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

        // Check whether the Gridlet is in execution list or not
        int found = gridletInExecList_.indexOf(gridletId, userId);

        // if a Gridlet is in execution list
        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
            if (rgl.getRemainingGridletLength() == 0.0) {
                rgl.setGridletStatus(Gridlet.SUCCESS);
            }
            else {
                rgl.setGridletStatus(Gridlet.CANCELED);
            }

            // then forecast the next Gridlet to complete
            forecastGridlet();
        }

        // if a Gridlet is not in exec list, then find it in the paused list
        else
        {
            found = gridletPausedList_.indexOf(gridletId, userId);

            // if a Gridlet is found in the paused list then remove it
            if (found >= 0)
            {
                rgl = (ResGridlet) gridletPausedList_.remove(found);
                rgl.setGridletStatus(Gridlet.CANCELED);
            }
        }

        return rgl;
    }