private ResGridlet cancel(int gridletId, int userId)
    {
        ResGridlet rgl = null;

        // Find in EXEC List first
        int found = gridletInExecList_.indexOf(gridletId, userId);
        if (found >= 0)
        {
            // update the gridlets in execution list up to this point in time
            updateGridletProcessing();

            // Get the Gridlet from the execution list
            rgl = (ResGridlet) gridletInExecList_.remove(found);

            // if a Gridlet is finished upon cancelling, then set it to success
            // instead.
            if (rgl.getRemainingGridletLength() == 0.0) {
                rgl.setGridletStatus(Gridlet.SUCCESS);
            }
            else {
                rgl.setGridletStatus(Gridlet.CANCELED);
            }

            // Set PE on which Gridlet finished to FREE
            super.resource_.setStatusPE( PE.FREE, rgl.getMachineID(),
                                        rgl.getPEID() );
            allocateQueueGridlet();
            return rgl;
        }

        // Find in QUEUE list
        found = gridletQueueList_.indexOf(gridletId, userId);
        if (found >= 0)
        {
            rgl = (ResGridlet) gridletQueueList_.remove(found);
            rgl.setGridletStatus(Gridlet.CANCELED);
            return rgl;
        }

        // if not found, then find in the Paused list
        found = gridletPausedList_.indexOf(gridletId, userId);
        if (found >= 0)
        {
            rgl = (ResGridlet) gridletPausedList_.remove(found);
            rgl.setGridletStatus(Gridlet.CANCELED);
            return rgl;
        }

        // if not found, then find in AR waiting list
        found = gridletWaitingList_.indexOf(gridletId, userId);
        if (found >= 0)
        {
            rgl = (ResGridlet) gridletWaitingList_.remove(found);
            rgl.setGridletStatus(Gridlet.CANCELED);
            return rgl;
        }

        // if not found
        rgl = null;
        return rgl;
    }