📄 advancereservation.java
字号:
* @param resName a resource name * @return an unique booking id if successful, otherwise an error message * @pre numPE > 0 * @pre resName != null * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(Calendar startTime, Calendar endTime, int numPE, String resName) { long start = 0; // start time long end = 0; // end time // if start time is not empty if (startTime != null) { start = startTime.getTimeInMillis(); } // if end time is not empty if (endTime != null) { end = endTime.getTimeInMillis(); } return createReservation(start, end, numPE, resName); } /** * Creates a new reservation and sends the request to a resource. * If the new reservation has been accepted by a resource, an unique booking * ID is generated in the format of <tt>"resourceID_reservationID"</tt>. * Otherwise, an error message or an approximate busy time is returned * by using GridSimTags.AR_CREATE_XXXX tags, where XXXX = specific tag name. * <p> * Immediate reservation can be used by this method by specifying one or * both properties: * <ul> * <li> startTime = null, meaning do not care about start time or use * current time as a reservation's start time. * <li> duration = 0, meaning do not have a specific requirement about * duration or completion time. * </ul> * * @param startTime reservation start time * @param duration reservation duration time in seconds * @param numPE number of PEs required for this reservation * @param resID a resource ID * @return an unique booking id if successful, otherwise an error message * @pre duration >= 0 * @pre numPE > 0 * @pre resID > 0 * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(Calendar startTime, int duration, int numPE, int resID) { long start = 0; // start time // check the start time if (startTime != null) { start = startTime.getTimeInMillis(); } return createReservation(start, duration, numPE, resID); } /** * Creates a new reservation and sends the request to a resource. * If the new reservation has been accepted by a resource, an unique booking * ID is generated in the format of <tt>"resourceID_reservationID"</tt>. * Otherwise, an error message or an approximate busy time is returned * by using GridSimTags.AR_CREATE_XXXX tags, where XXXX = specific tag name. * <p> * Immediate reservation can be used by this method by specifying one or * both properties: * <ul> * <li> startTime = null, meaning do not care about start time or use * current time as a reservation's start time. * <li> duration = 0, meaning do not have a specific requirement about * duration or completion time. * </ul> * * @param startTime reservation start time * @param duration reservation duration time in seconds * @param numPE number of PEs required for this reservation * @param resName a resource name * @return an unique booking id if successful, otherwise an error message * @pre duration >= 0 * @pre numPE > 0 * @pre resName != null * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(Calendar startTime, int duration, int numPE, String resName) { long start = 0; // start time // check the start time if (startTime != null) { start = startTime.getTimeInMillis(); } return createReservation(start, duration, numPE, resName); } /** * Creates a new reservation and sends the request to a resource. * If the new reservation has been accepted by a resource, an unique booking * ID is generated in the format of <tt>"resourceID_reservationID"</tt>. * Otherwise, an error message or an approximate busy time is returned * by using GridSimTags.AR_CREATE_XXXX tags, where XXXX = specific tag name. * <p> * Immediate reservation can be used by this method by specifying one or * both properties: * <ul> * <li> startTime = 0, meaning do not care about start time or use * current time as a reservation's start time. * <li> endTime = 0, meaning do not have a specific requirement about * completion time. * </ul> * * @param startTime reservation start time in milliseconds * @param endTime reservation end time in milliseconds * @param numPE number of PEs required for this reservation * @param resID a resource ID * @return an unique booking id if successful, otherwise an error message * @pre startTime >= 0 * @pre endTime >= 0 * @pre numPE > 0 * @pre resID > 0 * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(long startTime, long endTime, int numPE, int resID) { // sends an immediate reservation int tag = 0; boolean ar = true; if (startTime == 0 || endTime == 0) { ar = false; tag = GridSimTags.SEND_AR_CREATE_IMMEDIATE; } else { // sends AR tag = GridSimTags.SEND_AR_CREATE; } // check all the values first String errorMsg = validateValue(startTime, endTime, numPE, resID, ar); if (errorMsg != null) { return errorMsg; } // otherwise create a new reservation ARObject createObj = new ARObject(super.get_id(), timeZone_); createObj.setStartTime(startTime); // duration = end time - start time int duration = (int) (endTime - startTime) / MILLI_SEC; createObj.setDurationTime(duration); createObj.setNumPE(numPE); createObj.setResourceID(resID); return sendReservation(resID, createObj, tag); } /** * Creates a new reservation and sends the request to a resource. * If the new reservation has been accepted by a resource, an unique booking * ID is generated in the format of <tt>"resourceID_reservationID"</tt>. * Otherwise, an error message or an approximate busy time is returned * by using GridSimTags.AR_CREATE_XXXX tags, where XXXX = specific tag name. * <p> * Immediate reservation can be used by this method by specifying one or * both properties: * <ul> * <li> startTime = 0, meaning do not care about start time or use * current time as a reservation's start time. * <li> endTime = 0, meaning do not have a specific requirement about * completion time. * </ul> * * @param startTime reservation start time in milliseconds * @param endTime reservation end time in milliseconds * @param numPE number of PEs required for this reservation * @param resName a resource name * @return an unique booking id if successful, otherwise an error message * @pre startTime > 0 * @pre endTime > 0 * @pre numPE > 0 * @pre resName != null * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(long startTime, long endTime, int numPE, String resName) { int result = 0; boolean error = false; // check the resource name int resID = 0; if (resName == null) { result = GridSimTags.AR_CREATE_ERROR_INVALID_RESOURCE_NAME; error = true; } else { resID = GridSim.getEntityId(resName); if (resID == -1) { result = GridSimTags.AR_CREATE_ERROR_INVALID_RESOURCE_NAME; error = true; } } if (error == true) { return AdvanceReservation.getCreateResult(result); } return createReservation(startTime, endTime, numPE, resID); } /** * Creates a new reservation and sends the request to a resource. * If the new reservation has been accepted by a resource, an unique booking * ID is generated in the format of <tt>"resourceID_reservationID"</tt>. * Otherwise, an error message or an approximate busy time is returned * by using GridSimTags.AR_CREATE_XXXX tags, where XXXX = specific tag name. * <p> * Immediate reservation can be used by this method by specifying one or * both properties: * <ul> * <li> startTime = 0, meaning do not care about start time or use * current time as a reservation's start time. * <li> duration = 0, meaning do not have a specific requirement about * duration or completion time. * </ul> * * @param startTime reservation start time in milliseconds * @param duration reservation end time in seconds * @param numPE number of PEs required for this reservation * @param resID a resource ID * @return an unique booking id if successful, otherwise an error message * @pre startTime > 0 * @pre duration > 0 * @pre numPE > 0 * @pre resID > 0 * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(long startTime, int duration, int numPE, int resID) { // sends an immediate reservation int tag = 0; boolean ar = true; // a flag to denote whether it is AR or Immediate if (startTime == 0 || duration == 0) { ar = false; tag = GridSimTags.SEND_AR_CREATE_IMMEDIATE; } else { // sends AR tag = GridSimTags.SEND_AR_CREATE; } // check all the values first String errorMsg = validateValue(startTime, duration, numPE, resID, ar); if (errorMsg != null) { return errorMsg; } // otherwise create a new reservation ARObject createObj = new ARObject(super.get_id(), timeZone_); createObj.setStartTime(startTime); createObj.setDurationTime(duration); createObj.setNumPE(numPE); createObj.setResourceID(resID); return sendReservation(resID, createObj, tag); } /** * Creates a new reservation and sends the request to a resource. * If the new reservation has been accepted by a resource, an unique booking * ID is generated in the format of <tt>"resourceID_reservationID"</tt>. * Otherwise, an error message or an approximate busy time is returned * by using GridSimTags.AR_CREATE_XXXX tags, where XXXX = specific tag name. * <p> * Immediate reservation can be used by this method by specifying one or * both properties: * <ul> * <li> startTime = 0, meaning do not care about start time or use * current time as a reservation's start time. * <li> duration = 0, meaning do not have a specific requirement about * duration or completion time. * </ul> * * @param startTime reservation start time in milliseconds * @param duration reservation end time in seconds * @param numPE number of PEs required for this reservation * @param resName a resource name * @return an unique booking id if successful, otherwise an error message * @pre startTime > 0 * @pre duration > 0 * @pre numPE > 0 * @pre resName != null * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(long startTime, int duration, int numPE, String resName) { int result = 0; boolean error = false; // check the resource name int resID = 0; if (resName == null) { result = GridSimTags.AR_CREATE_ERROR_INVALID_RESOURCE_NAME; error = true; } else { // then check the resource ID as well resID = GridSim.getEntityId(resName); if (resID == -1) { result = GridSimTags.AR_CREATE_ERROR_INVALID_RESOURCE_NAME; error = true; } } // if invalid resource name or id, then exit if (error == true) { return AdvanceReservation.getCreateResult(result); } return createReservation(startTime, duration, numPE, resID); } /** * Modifies an existing reservation. Modification must be done before * reservation's start time. * A return value of this method uses one of * GridSimTags.AR_MODIFY_XXXX tags, where XXXX = specific tag name. * * @param bookingID reservation booking ID * @param obj reservation object that contains new modifications * @return an integer tag that denotes success or failure. * @pre bookingID != null * @pre obj != null * @post $none * @see gridsim.GridSimTags */ public int modifyReservation(String bookingID, ARObject obj) { // id[0] = resID, [1] = reservID, [2] = trans ID int[] id = parseBookingID(bookingID); if (id == null) { return GridSimTags.AR_MODIFY_FAIL_INVALID_BOOKING_ID;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -