private void processGridletReturn(Sim_event ev)
    {
        if (trace_flag)
        {
            System.out.println(super.get_name() +
                ": received an GRIDLET_RETURN event. Clock: " + GridSim.clock());
        }

        Object obj = (Object) ev.get_data();
        Gridlet gl = null;
        Random random = new Random(5);   // a random generator with a random seed

        if (obj instanceof Gridlet)
        {
            gl = (Gridlet) obj;
            gridletLatencyTime[gl.getGridletID()] = GridSim.clock();

            // Write into a results file
            if (trace_flag)
            {
                write(super.get_name(), "Receiving", gl.getGridletID(),
                      GridSim.getEntityName(gl.getResourceID()),
                      gl.getGridletStatusString(), GridSim.clock());
            }

            ///////////////////////// Gridlet Success
            if (gl.getGridletStatusString().compareTo("Success") == 0)
            {
                System.out.println(super.get_name() + ": Receiving Gridlet #" +
                       gl.getGridletID() + " with status Success at time = " +
                       GridSim.clock() + " from resource " +
                       GridSim.getEntityName(gl.getResourceID()));

                this.GridletReceiveList_.add(gl); // add into the received list
                gridletLatencyTime[gl.getGridletID()] =
                        gridletLatencyTime[gl.getGridletID()] -
                        gridletSubmissionTime[gl.getGridletID()];

                // We have received all the gridlets. So, finish the simulation.
                if (GridletReceiveList_.size() == GridletSubmittedList_.size())
                {
                    super.finishSimulation();
                }

            } // if (gl.getGridletStatusString() == "Success")

            //////////////////////// Gridlet Failed
            else if (gl.getGridletStatusString().compareTo("Failed") == 0)
            {
                System.out.println(super.get_name() + ": Receiving Gridlet #" +
                       gl.getGridletID() + " with status Failed at time = " +
                       GridSim.clock() + " from resource " +
                       GridSim.getEntityName(gl.getResourceID()));

                // Send the gridlet as soon as we have resources available.
                // This gridlet will be resend as soon as possible,
                // in the first loop.
                int pos = findGridletInGridletSubmittedList(gl);
                if (pos == -1) {
                    System.out.println(super.get_name() +
                        ". Gridlet not found in GridletSubmittedList.");
                }
                else
                {
                    // set this gridlet as submitted, because otherwise
                    // this gridlet may be submitted several times.
                    // A gridlet will only be submitted when the event carrying
                    // its id reaches the user
                    ((GridletSubmission) GridletSubmittedList_.get(pos)).setSubmitted(true);

                    // Now, schedule an event to itself to submit the gridlet
                    // The gridlet will be sent as soon as possible
                    Integer glID_Int = new Integer(gl.getGridletID());

                    // This event includes the gridletID, so that the user
                    // will try to submit only this gridlet
                    super.send(super.get_id(), GridSimTags.SCHEDULE_NOW,
                               GridUserFailureEx03.SUBMIT_GRIDLET, glID_Int);
                }
            } // if (gl.getGridletStatusString() == "Failed")

            ////////////////////////////// Gridlet Failed_resource
            else if (gl.getGridletStatusString().compareTo("Failed_resource_unavailable") == 0)
            {
                int pos = findGridletInGridletSubmittedList(gl);
                if (pos == -1) {
                    System.out.println(super.get_name() +
                        ". Gridlet not found in GridletSubmittedList.");
                }
                else
                {
                    // Now, set its submission time for a random time between
                    // 1 and the polling time
                    double resubmissionTime = random.nextDouble() * pollingTime_;

                    // this is to prevent the gridlet from being submitted
                    // before its resubmission time.
                    // This is different from the FAILED case, because
                    // in that case, the gridlet should be resubmited as soon
                    // as possible. As oppossed to that, this gridlet should
                    // not be resubmited before its resubmission time.
                    ((GridletSubmission) GridletSubmittedList_.get(pos)).setSubmitted(true);


                    System.out.println(super.get_name() + ": Receiving Gridlet #" +
                           gl.getGridletID() +
                           " with status Failed_resource_unavailable at time = " +
                           GridSim.clock() + " from resource " +
                           GridSim.getEntityName(gl.getResourceID()) +
                           "(resID: " + gl.getResourceID() +
                           "). Resubmission time will be: " +
                           resubmissionTime + GridSim.clock());

                    // Now, we have to inform the GIS  about this failure, so it
                    // can keep the list of resources up-to-date.
                    informGIS(gl.getResourceID());

                    // Now, schedule an event to itself to submit the gridlet
                    Integer glID_Int = new Integer(gl.getGridletID());

                    // This event includes the gridletID, so that the user
                    // will try to submit only this gridlet
                    super.send(super.get_id(), resubmissionTime,
                               GridUserFailureEx03.SUBMIT_GRIDLET, glID_Int);
                }
            } // else if
            else
            {
                System.out.println(super.get_name() + ": Receiving Gridlet #" +
                       gl.getGridletID() + " with status " +
                       gl.getGridletStatusString() + " at time = " +
                       GridSim.clock() + " from resource " +
                       GridSim.getEntityName(gl.getResourceID()) +
                       " resID: " + gl.getResourceID());
            }

        } // if (obj instanceof Gridlet)
    }