⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 argridresource.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                       new IO_data(array, super.SIZE, src));        }    }    /**     * Handles a cancel reservation request.     * @param ev  Sim_event object     * @pre ev != null     * @post $none     */    private void handleCancelReservation(Sim_event ev)    {        int src = -1;   // sender id        boolean success = false;        int tag = -1;        try        {            // id[0] = gridletID, [1] = reservID, [2] = transID, [3] = sender ID            int[] obj = ( int[] ) ev.get_data();            // get the data inside an array            int reservationID = obj[1];            int transactionID = obj[2];            src = obj[3];            // gridletID can be -1 if want to cancel ALL Gridlets in 1 reserv            int gridletID = obj[0];            int returnTag = GridSimTags.RETURN_AR_CANCEL;            tag = returnTag + transactionID;            // check whether this resource can support AR or not            success = checkResourceType(src, returnTag, transactionID,                            GridSimTags.AR_CANCEL_ERROR_RESOURCE_CANT_SUPPORT,                            "can't cancel a reservation");            if (success == false) {                return;            }            // cancels a gridlet of a specific reservation            else if (success == true && gridletID != -1)            {                ( (ARPolicy) policy_).handleCancelReservation(reservationID,                                            src, gridletID, tag);            }            // cancels ALL gridlets of a specific reservation            else if (success == true && gridletID == -1)            {                ( (ARPolicy) policy_).handleCancelReservation(reservationID,                                            src, tag);            }        }        catch (ClassCastException c)        {            // cancel a list of Gridlets            handleCancelList(ev);            return;        }        catch (Exception e) {            success = false;        }        // if there is an exception, then send back an error msg        if (success == false && tag != -1)        {            System.out.println(super.get_name() + " : Error - can't cancel a "+                "new reservation.");            super.send(src, 0.0, GridSimTags.RETURN_AR_CANCEL,                new IO_data(new Integer(GridSimTags.AR_CANCEL_ERROR),SIZE,src));        }    }    /**     * Handles a cancel reservation request with a list of Gridlet IDs.     * @param ev   a Sim_event object     * @pre ev != null     * @post $none     */    private void handleCancelList(Sim_event ev)    {        boolean success = false;        int tag = -1;        int src = 0;        try        {            // [0]=reservID, [1]=list of Gridlet IDs, [2]=transID, [3]=senderID            Object[] obj = ( Object[] ) ev.get_data();            // get the data inside an array            int reservationID = ( (Integer) obj[0] ).intValue();            ArrayList list = (ArrayList) obj[1];            int transactionID = ( (Integer) obj[2] ).intValue();            src = ( (Integer) obj[3] ).intValue();            // tag = return tag + transaction id            int returnTag = GridSimTags.RETURN_AR_CANCEL;            tag = returnTag + transactionID;            // check whether this resource can support AR or not            success = checkResourceType(src, returnTag, transactionID,                            GridSimTags.AR_CANCEL_ERROR_RESOURCE_CANT_SUPPORT,                            "can't cancel a reservation");            // if list is empty            if (list == null) {                success = false;            }            // if successful            if (success == true) {                ( (ARPolicy) policy_).handleCancelReservation(reservationID,                                      src, list, tag);            }        }        catch (ClassCastException c) {            success = false;        }        catch (Exception e) {            success = false;        }        // if there is an exception, then send back an error msg        if (success == false && tag != -1)        {            System.out.println(super.get_name() + " : Error - can't cancel a "+                               "new reservation.");            super.send(src, 0.0, GridSimTags.RETURN_AR_CANCEL,                new IO_data(new Integer(GridSimTags.AR_CANCEL_ERROR),SIZE,src));        }    }    /**     * Handles a commit reservation request with no Gridlets.     * @param ev  Sim_event object     * @pre ev != null     * @post $none     */    private void handleCommitOnly(Sim_event ev)    {        int src = -1;   // the sender id        boolean success = false;        int tag = -1;        try        {            // id[0] = resID, [1] = reservID, [2] = trans ID, [3] = sender ID            int[] obj = ( int[] ) ev.get_data();            // get the data inside the array            int returnTag = GridSimTags.RETURN_AR_COMMIT;            tag = returnTag + obj[2];            src = obj[3];            // check whether this resource can support AR or not            success = checkResourceType(src, returnTag, obj[2],                            GridSimTags.AR_COMMIT_ERROR_RESOURCE_CANT_SUPPORT,                            "can't commit a reservation");            // if this resource is not supported AR, then exit            if (success == false) {                return;            }            else {                ( (ARPolicy) policy_).handleCommitOnly(obj[1], src, tag);            }        }        catch (ClassCastException c) {            success = false;        }        catch (Exception e) {            success = false;        }        // if there is an exception, then send back an error msg        if (success == false && tag != -1)        {            System.out.println(super.get_name() + " : Error - can't commit a "+                "reservation.");            super.send(src, 0.0, GridSimTags.RETURN_AR_COMMIT,                new IO_data(new Integer(GridSimTags.AR_COMMIT_ERROR),SIZE,src));        }    }    /**     * Handles a commit reservation request with one or more Gridlets.     * @param ev  Sim_event object     * @pre ev != null     * @post $none     */    private void handleCommitReservation(Sim_event ev)    {        int src = -1;   // the sender id        boolean success = false;        int tag = -1;        try        {            // [0]=reservID, [1]=gridlet(s), [2]=transID, [3]=senderID            Object[] obj = ( Object[] ) ev.get_data();            // get the data inside an array            int reservationID = ( (Integer) obj[0] ).intValue();            int transactionID = ( (Integer) obj[2] ).intValue();            src = ( (Integer) obj[3] ).intValue();            int returnTag = GridSimTags.RETURN_AR_COMMIT;            tag = returnTag + transactionID;            // check whether this resource can support AR or not            success = checkResourceType(src, returnTag, transactionID,                            GridSimTags.AR_COMMIT_ERROR_RESOURCE_CANT_SUPPORT,                            "can't commit a reservation");            // if a resource doesn't support AR then exit straightaway            if (success == false) {                return;            }            // check again whether obj[1] contains either Gridlet or GridletList            success = selectCommitMethod(obj[1], reservationID, src, tag);        }        catch (ClassCastException c) {            success = false;            c.printStackTrace();        }        catch (Exception e) {            success = false;        }        // if there is an exception or other errors, then send back an error msg        if (success == false && tag != -1)        {            System.out.println(super.get_name() + " : Error - can't commit a"+                " reservation.");            super.send(src, 0.0, GridSimTags.RETURN_AR_COMMIT,                new IO_data(new Integer(GridSimTags.AR_COMMIT_ERROR),SIZE,src));        }    }    /**     * Chooses whether to commit for one or a list of Gridlets.     * @param obj    an object containing one Gridlet or a GridletList     * @param reservID   reservation ID     * @param src    sender ID     * @param tag    tag ID     * @return <tt>true</tt> if this method is successful, <tt>false</tt>     *         otherwise     */    private boolean selectCommitMethod(Object obj,int reservID,int src,int tag)    {        boolean flag = true;        try        {            // A case where a reservation only has 1 Gridlet            Gridlet gridlet = (Gridlet) obj;            if (checkGridlet(gridlet) == true)            {                ( (ARPolicy) policy_).handleCommitReservation(reservID, src,                        tag, gridlet);            }            else {                flag = false;            }        }        catch (ClassCastException c)        {            try            {                // A case where a reservation contains 1 or more Gridlets                GridletList list = (GridletList) obj;                Gridlet gl = null;                // For each Gridlet in the list, check whether it has finished                // before or not                for (int i = 0; i < list.size(); i++)                {                    gl = (Gridlet) list.get(i);                    if (checkGridlet(gl) == false)                    {                        flag = false;                        break;                    }                }                if (flag == true)                {                    ( (ARPolicy) policy_).handleCommitReservation(reservID, src,                        tag, list);                }            }            catch (ClassCastException again) {                flag = false;            }        }        catch (Exception e) {            flag = false;        }        return flag;    }    /**     * Checks whether a Gridlet has finished previously or not     * @param gl   a Gridlet object     * @return <tt>true</tt> if a Gridlet has finished execution beforehand,     *         <tt>false</tt> otherwise     */    private boolean checkGridlet(Gridlet gl)    {        // checks whether this Gridlet has finished or not        if (gl.isFinished() == true)        {            System.out.println(super.get_name() + ": Error - Gridlet #" +                               gl.getGridletID() + " for User #" +                               gl.getUserID() + " is already finished.");            return false;        }        // process this Gridlet to this GridResource        gl.setResourceParameter(super.get_id(),                                super.resource_.getCostPerSec());        return true;    }    /**     * Handles a create reservation request.     * @param ev  Sim_event object     * @pre ev != null     * @post $none     */    private void handleCreateReservation(Sim_event ev)    {        int src = -1;   // the sender id        boolean success = false;        int tag = -1;        try        {            // get the data            ARObject obj = (ARObject) ev.get_data();            src = obj.getUserID();            // get the unique tag to send back to recepient            int returnTag = GridSimTags.RETURN_AR_CREATE;            tag = returnTag + obj.getTransactionID();            // check whether this resource can support AR or not            success = checkResourceType(src, returnTag, obj.getTransactionID(),                            GridSimTags.AR_CREATE_FAIL_RESOURCE_CANT_SUPPORT,                            "can't create a new reservation");            // if this resource can't support AR then exit            if (success == false) {                return;            }            // if it is AR            if (ev.get_tag() == GridSimTags.SEND_AR_CREATE) {                ( (ARPolicy) policy_).handleCreateReservation(obj, src, tag);            }            else {   // if it is an immediate reservation                ( (ARPolicy) policy_).handleImmediateReservation(obj, src, tag);            }        }        catch (ClassCastException c) {            success = false;        }        catch (Exception e) {            success = false;        }        // if there is an exception, then send back an error msg        if (success == false && tag != -1)        {            System.out.println(super.get_name() + " : Error - can't create a"+                " new reservation.");            super.send(src, 0.0, GridSimTags.RETURN_AR_CREATE,                new IO_data(new Integer(GridSimTags.AR_CREATE_ERROR),SIZE,src));        }    }} // end class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -