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

📄 advancereservation.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        }        // then search for the existing reservation        ARObject old = searchBooking(id[0], id[1]);        if (old == null) {            return GridSimTags.AR_MODIFY_FAIL_INVALID_BOOKING_ID;        }        // get the transaction ID for this query        int tagID = incrementID();        obj.setTransactionID(tagID);        // then send it to a grid resource        super.send(super.output, 0.0, GridSimTags.SEND_AR_MODIFY,                   new IO_data(obj, obj.getByteSize(), id[0]) );        // wait for feedback whether the reservation has been accepted or not        // waiting for a response from the GridResource        FilterResult tag = new FilterResult(tagID,GridSimTags.RETURN_AR_MODIFY);        // only look for this type of ack for same reservation ID        Sim_event ev = new Sim_event();        super.sim_get_next(tag, ev);        int result = GridSimTags.AR_MODIFY_ERROR;        try        {            int[] array = (int[]) ev.get_data(); // [0] = trans ID, [1] = result            result = array[1];            if (result == GridSimTags.AR_MODIFY_SUCCESS)            {                // replace the old values with new ones                obj.setStatus(GridSimTags.AR_STATUS_NOT_STARTED);                old.copy(obj);            }        }        catch (Exception e) {            result = GridSimTags.AR_MODIFY_ERROR;        }        return result;    }    /**     * Cancels a given reservation. All Gridlets associated with this     * reservation will automatically be cancelled. Users need to retrieve     * the Gridlets manually, by using GridSim.gridletReceive().     * A return value for this method uses one of     * of GridSimTags.AR_CANCEL_XXXX tags, where XXXX = specific tag name.     *     * @param bookingID   this reservation booking ID     * @return an integer tag that denotes success or failure.     * @see gridsim.GridSimTags     * @see gridsim.GridSim#gridletReceive()     * @see gridsim.GridSim#gridletReceive(int, int, int)     * @pre bookingID != null     * @post $none     */    public int cancelReservation(String bookingID) {        return cancelReservation(bookingID, -1);    }    /**     * Cancels a list of Gridlets for a given reservation.     * Users need to retrieve     * the Gridlets manually, by using GridSim.gridletReceive().     * If cancellation of a Gridlet fails, then it will ignore the rest of the     * list.     * A return value for this method uses one of     * of GridSimTags.AR_CANCEL_XXXX tags, where XXXX = specific tag name.     * <br>     * <b>NOTE:</b> This method is similar to GridSim.gridletCancel()     *     * @param bookingID   this reservation booking ID     * @param list        a list of Gridlet IDs (each ID is an Integer object).     *                    Each Gridlet ID should be unique and no duplicate.     * @return an integer tag that denotes success or failure.     * @see gridsim.GridSimTags     * @see gridsim.GridSim#gridletReceive()     * @see gridsim.GridSim#gridletReceive(int, int, int)     * @see gridsim.GridSim#gridletCancel(int, int, int, double)     * @see gridsim.GridSim#gridletCancel(Gridlet, int, double)     * @pre bookingID != null     * @pre list != null     * @post $none     */    public int cancelReservation(String bookingID, ArrayList list)    {        if (bookingID == null) {            return GridSimTags.AR_CANCEL_FAIL_INVALID_BOOKING_ID;        }        // check the list        if (list == null) {            return GridSimTags.AR_CANCEL_FAIL;        }        // id[0] = resID, [1] = reservID, [2] = trans ID        int[] id = parseBookingID(bookingID);        if (id == null) {            return GridSimTags.AR_CANCEL_FAIL_INVALID_BOOKING_ID;        }        // [0] = reservID, [1] = list, [2] = transID, [3] = sender ID        Object[] commitObj = new Object[MAX_ID];        commitObj[0] = new Integer(id[1]);        commitObj[1] = list;        int tagID = incrementID();        commitObj[2] = new Integer(tagID);   // transaction id        commitObj[3] = new Integer( super.get_id() );  // sender ID        // Integer object size = 12 (incl. overheads)        int size = list.size() * 12;        // sends to a destinated grid resource        super.send(super.output, 0.0, GridSimTags.SEND_AR_CANCEL,                   new IO_data(commitObj, size, id[0]) );        // waiting for a response from the GridResource with an unique tag        // of transaction id        FilterResult tag = new FilterResult(tagID,GridSimTags.RETURN_AR_CANCEL);        // only look for this type of ack for same reservation ID        Sim_event ev = new Sim_event();        super.sim_get_next(tag, ev);        // get the result back, sent by GridResource or AllocPolicy object        int result = 0;        try        {            int[] array = (int[]) ev.get_data(); // [0] = trans ID, [1] = result            result = array[1];        }        catch (Exception e) {            result = GridSimTags.AR_CANCEL_ERROR;        }        return result;    }    /**     * Cancels a Gridlet for a given reservation.     * Users need to retrieve     * the Gridlet manually, by using GridSim.gridletReceive().     * A return value for this method uses one of     * of GridSimTags.AR_CANCEL_XXXX tags, where XXXX = specific tag name.     * <br>     * <b>NOTE:</b> This method is similar to GridSim.gridletCancel()     *     * @param bookingID   this reservation booking ID     * @param gl          a Gridlet object     * @return an integer tag that denotes success or failure.     * @see gridsim.GridSimTags     * @see gridsim.GridSim#gridletReceive()     * @see gridsim.GridSim#gridletReceive(int, int, int)     * @see gridsim.GridSim#gridletCancel(int, int, int, double)     * @see gridsim.GridSim#gridletCancel(Gridlet, int, double)     * @pre bookingID != null     * @pre gl != null     * @post $none     */    public int cancelReservation(String bookingID, Gridlet gl)    {        if (gl == null) {            return GridSimTags.AR_CANCEL_ERROR;        }        return cancelReservation(bookingID, gl.getGridletID());    }    /**     * Cancels a Gridlet for a given reservation.     * Users need to retrieve     * the Gridlet manually, by using GridSim.gridletReceive().     * A return value for this method uses one of     * of GridSimTags.AR_CANCEL_XXXX tags, where XXXX = specific tag name.     * <br>     * <b>NOTE:</b> This method is similar to GridSim.gridletCancel()     *     * @param bookingID   this reservation booking ID     * @param gridletID   a Gridlet ID     * @return an integer tag that denotes success or failure.     * @see gridsim.GridSimTags     * @see gridsim.GridSim#gridletReceive()     * @see gridsim.GridSim#gridletReceive(int, int, int)     * @see gridsim.GridSim#gridletCancel(int, int, int, double)     * @see gridsim.GridSim#gridletCancel(Gridlet, int, double)     * @pre bookingID != null     * @pre gridletID >= 0     * @post $none     */    public int cancelReservation(String bookingID, int gridletID)    {        if (bookingID == null) {            return GridSimTags.AR_CANCEL_FAIL_INVALID_BOOKING_ID;        }        // id[0] = resID, [1] = reservID, [2] = trans ID, [3] = sender ID        int[] id = parseBookingID(bookingID);        if (id == null) {            return GridSimTags.AR_CANCEL_FAIL_INVALID_BOOKING_ID;        }        int resourceID = id[0];    // get the resource ID        id[0] = gridletID;         // overrides resource ID with a gridlet id        id[2] = incrementID();     // transaction id        id[3] = super.get_id();    // this entity or sender ID        // send to grid resource to cancel a reservation        super.send(super.output, 0.0, GridSimTags.SEND_AR_CANCEL,                   new IO_data(id, SIZE_ARRAY, resourceID) );        // waiting for a response from the GridResource with an unique tag        // of transaction id        FilterResult tag = new FilterResult(id[2],GridSimTags.RETURN_AR_CANCEL);        // only look for this type of ack for same reservation ID        Sim_event ev = new Sim_event();        super.sim_get_next(tag, ev);        // get the result back, sent by GridResource or AllocPolicy object        int result = 0;        try        {            int[] array = (int[]) ev.get_data();  // [0] = tag ID, [1] = result            result = array[1];        }        catch (Exception e) {            result = GridSimTags.AR_CANCEL_ERROR;        }        return result;    }    /**     * Querys to a resource regarding to list of free time during a period of     * time. Each object inside ArrayList is <tt>long array[3]</tt>, with:     * <ul>     *    <li> array[0] = start time     *    <li> array[1] = duration time     *    <li> array[2] = number of PEs     * </ul>     *     * @param resourceID   a resource ID     * @param from         starting time in milliseconds     * @param to           ending time in milliseconds     * @return ArrayList object or <tt>null</tt> if error occurs     * @pre resourceID != null     * @pre from > 0     * @pre to > 0     * @post $none     */    public ArrayList queryFreeTime(Integer resourceID, long from, long to)    {        if (resourceID == null) {            return null;        }        return queryFreeTime(resourceID.intValue(), from, to);    }    /**     * Querys to a resource regarding to list of free time during a period of     * time. Each object inside ArrayList is <tt>long array[3]</tt>, with:     * <ul>     *    <li> array[0] = start time     *    <li> array[1] = duration time     *    <li> array[2] = number of PEs     * </ul>     *     * @param resourceID   a resource ID     * @param from         starting time in milliseconds     * @param to           ending time in milliseconds     * @return ArrayList object or <tt>null</tt> if error occurs     * @pre resourceID > 0     * @pre from > 0     * @pre to > 0     * @post $none     */    public ArrayList queryFreeTime(int resourceID, long from, long to)    {        int tag = GridSimTags.SEND_AR_LIST_FREE_TIME;        return queryTime(resourceID, from, to, tag);    }    /**     * Querys to a resource regarding to list of busy time during a period of     * time. Each object inside ArrayList is <tt>long array[3]</tt>, with:     * <ul>     *    <li> array[0] = start time     *    <li> array[1] = duration time     *    <li> array[2] = number of PEs     * </ul>     *     * @param resourceID   a resource ID     * @param from         starting time in milliseconds     * @param to           ending time in milliseconds     * @return ArrayList object or <tt>null</tt> if error occurs     * @pre resourceID > 0     * @pre from > 0     * @pre to > 0     * @post $none     */    public ArrayList queryBusyTime(int resourceID, long from, long to)    {        int tag = GridSimTags.SEND_AR_LIST_BUSY_TIME;        return queryTime(resourceID, from, to, tag);    }    /**     * Sends a request to a resource regarding to either free or busy time.     * @param resourceID   a resource ID     * @param from         starting time     * @param to           ending time     * @param tag          a tag for either free or busy time     * @return ArrayList object or <tt>null</tt> if error occurs     * @pre resourceID > 0     * @pre from > 0     * @pre to > 0     * @post $none     */    private ArrayList queryTime(int resourceID, long from, long to, int tag)    {        int DEFAULT = 1;   // don't care about num PE        String str = validateValue(from, to, DEFAULT, resourceID, true);        // if there is an error msg, then return null        if (str != null) {            return null;        }        int id = incrementID();              // transaction ID        int size = ARObject.getByteSize();   // object size to be sent        // create a new object        ARObject data = new ARObject(super.get_id(), timeZone_);        int duration = (int) (to - from);        data.setStartTime(from);             // from start time        data.setDurationTime(duration);      // duration time        data.setTransactionID(id);           // transaction ID        data.setResourceID(resourceID);      // resource ID        // send to a resource ID        super.send(super.output, 0, tag, new IO_data(data, size, resourceID));        // wait for feedback whether the reservation has been accepted or not        // waiting for a response from the GridResource        tag = GridSimTags.RETURN_AR_QUERY_TIME;        FilterQueryTimeAR simTag = new FilterQueryTimeAR(id, tag);        // only look for this type of ack for same reservation ID        Sim_event ev = new Sim_event();        super.sim_get_next(simTag, ev);        ArrayList obj = null;        try        {            Object[] array = (Object[]) ev.get_data();  // [0] = trans ID            obj = (ArrayList) array[1];   // [1] = result        }        catch (Exception e) {            obj = null;        }        return obj;

⌨️ 快捷键说明

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