📄 advancereservation.java
字号:
str = "AR_STATUS_ACTIVE"; break; case GridSimTags.AR_STATUS_COMPLETED: str = "AR_STATUS_COMPLETED"; break; case GridSimTags.AR_STATUS_CANCELED: str = "AR_STATUS_CANCELED"; break; case GridSimTags.AR_STATUS_ERROR_INVALID_BOOKING_ID: str = "AR_STATUS_ERROR_INVALID_BOOKING_ID"; break; case GridSimTags.AR_STATUS_EXPIRED: str = "AR_STATUS_EXPIRED"; break; case GridSimTags.AR_STATUS_NOT_COMMITTED: str = "AR_STATUS_NOT_COMMITTED"; break; case GridSimTags.AR_STATUS_RESERVATION_DOESNT_EXIST: str = "AR_STATUS_RESERVATION_DOESNT_EXIST"; break; case GridSimTags.AR_STATUS_TERMINATED: str = "AR_STATUS_TERMINATED"; break; case GridSimTags.AR_STATUS_ERROR: str = "AR_STATUS_ERROR"; break; default: break; } return str; } /** * Converts a reservation result from integer into a String. * The result is one of GridSimTags.AR_COMMIT_XXXX tags, * where XXXX = specific tag name. * @param result a result for commit a reservation * @return a String representation of the reservation result * or <tt>null</tt> if invalid result. * @pre $none * @post $none * @see gridsim.GridSimTags */ public static String getCommitResult(int result) { String str = null; switch (result) { case GridSimTags.AR_COMMIT_SUCCESS: str = "AR_COMMIT_SUCCESS"; break; case GridSimTags.AR_COMMIT_FAIL: str = "AR_COMMIT_FAIL"; break; case GridSimTags.AR_COMMIT_FAIL_EXPIRED: str = "AR_COMMIT_FAIL_EXPIRED"; break; case GridSimTags.AR_COMMIT_FAIL_INVALID_BOOKING_ID: str = "AR_COMMIT_FAIL_INVALID_BOOKING_ID"; break; case GridSimTags.AR_COMMIT_ERROR_RESOURCE_CANT_SUPPORT: str = "AR_COMMIT_ERROR_RESOURCE_CANT_SUPPORT"; break; case GridSimTags.AR_COMMIT_ERROR: str = "AR_COMMIT_ERROR"; break; default: break; } return str; } /** * Converts a reservation result from integer into a String. * The result is one of GridSimTags.AR_MODIFY_XXXX tags, * where XXXX = specific tag name. * @param result a result for modify a reservation * @return a String representation of the reservation result * or <tt>null</tt> if invalid result. * @pre $none * @post $none * @see gridsim.GridSimTags */ public static String getModifyResult(int result) { String str = null; switch (result) { case GridSimTags.AR_MODIFY_ERROR: str = "AR_MODIFY_ERROR"; break; case GridSimTags.AR_MODIFY_SUCCESS: str = "AR_MODIFY_SUCCESS"; break; case GridSimTags.AR_MODIFY_FAIL_INVALID_END_TIME: str = "AR_MODIFY_FAIL_INVALID_END_TIME"; break; case GridSimTags.AR_MODIFY_FAIL_INVALID_START_TIME: str = "AR_MODIFY_FAIL_INVALID_START_TIME"; break; case GridSimTags.AR_MODIFY_FAIL_INVALID_NUM_PE: str = "AR_MODIFY_FAIL_INVALID_NUM_PE"; break; case GridSimTags.AR_MODIFY_FAIL_INVALID_BOOKING_ID: str = "AR_MODIFY_FAIL_INVALID_BOOKING_ID"; break; case GridSimTags.AR_MODIFY_FAIL_RESERVATION_ACTIVE: str = "AR_MODIFY_FAIL_RESERVATION_ACTIVE"; break; case GridSimTags.AR_MODIFY_FAIL_RESOURCE_CANT_SUPPORT: str = "AR_MODIFY_FAIL_RESOURCE_CANT_SUPPORT"; break; default: break; } return str; } ////////////////// PUBLIC METHODS ///////////////////////////////// /** * Allocates a new AdvanceReservation object. Time zone of this object * will be a default <tt>Calendar</tt> object given during * <tt>GridSim.init()</tt> method. If <tt>Calendar</tt> object is * <tt>null</tt>, then time zone is GMT+0 * * @param name this entity name * @param baudRate the bandwidth of this entity * @throws Exception This happens when one of the following scenarios occur: * <ul> * <li> creating this entity before initializing GridSim package * <li> this entity name is <tt>null</tt> or empty * </ul> * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], * String) * @see gridsim.GridSim#init(int, Calendar, boolean) * @pre name != null * @pre baudRate > 0 * @post $none */ public AdvanceReservation(String name, double baudRate) throws Exception { super(name, baudRate); // default current time and its time zone Calendar cal = GridSim.getSimulationCalendar(); if (cal == null) { timeZone_ = 0.0; } else { timeZone_ = cal.getTimeZone().getRawOffset() / HOUR; } init(); } /** * Allocates a new AdvanceReservation object with a given time zone * @param name this entity name * @param baudRate the bandwidth of this entity * @param timeZone the time zone of this entity * @throws Exception This happens when one of the following scenarios occur: * <ul> * <li> creating this entity before initializing GridSim package * <li> this entity name is <tt>null</tt> or empty * <li> invalid time zone * </ul> * @pre name != null * @pre baudRate > 0 * @post $none */ public AdvanceReservation(String name, double baudRate, double timeZone) throws Exception { super(name, baudRate); if (AdvanceReservation.validateTimeZone(timeZone) == true) { timeZone_ = timeZone; } else { throw new Exception(name + ": Error - invalid time zone"); } init(); } /** * Allocates a new AdvanceReservation object. Time zone of this object * will be a default <tt>Calendar</tt> object given during * <tt>GridSim.init()</tt> method. If <tt>Calendar</tt> object is * <tt>null</tt>, then time zone is GMT+0 * * @param name this entity name * @param link the link that this GridSim entity will use to communicate * with other GridSim or Network entities. * @throws Exception This happens when one of the following scenarios occur: * <ul> * <li> creating this entity before initializing GridSim package * <li> this entity name is <tt>null</tt> or empty * </ul> * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], * String) * @see gridsim.GridSim#init(int, Calendar, boolean) * @pre name != null * @pre link != null * @post $none */ public AdvanceReservation(String name, Link link) throws Exception { super(name, link); // default current time and its time zone Calendar cal = GridSim.getSimulationCalendar(); if (cal == null) { timeZone_ = 0.0; } else { timeZone_ = cal.getTimeZone().getRawOffset() / HOUR; } init(); } /** * Allocates a new AdvanceReservation object with a given time zone * @param name this entity name * @param link the link that this GridSim entity will use to communicate * with other GridSim or Network entities. * @param timeZone the time zone of this entity * @throws Exception This happens when one of the following scenarios occur: * <ul> * <li> creating this entity before initializing GridSim package * <li> this entity name is <tt>null</tt> or empty * <li> invalid time zone * </ul> * @pre name != null * @pre link != null * @post $none */ public AdvanceReservation(String name, Link link, double timeZone) throws Exception { super(name, link); if (AdvanceReservation.validateTimeZone(timeZone) == true) { timeZone_ = timeZone; } else { throw new Exception(name + ": Error - invalid time zone"); } init(); } /** * Gets an expiry time of a reservation * @param bookingID a reservation booking ID * @return an expiry time or -1 if not found * @pre bookingID != null * @post $result > 0 */ public long getExpiryTime(String bookingID) { int[] id = parseBookingID(bookingID); if (id == null) { return -1; } ARObject obj = searchBooking(id[0], id[1]); if (obj == null) { return -1; } return obj.getExpiryTime(); } /** * 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> endTime = null, meaning do not have a specific requirement about * completion time. * </ul> * * @param startTime reservation start time * @param endTime reservation end time * @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 numPE > 0 * @pre resID > 0 * @post $result != null * @see gridsim.GridSimTags */ public String createReservation(Calendar startTime, Calendar endTime, int numPE, int resID) { 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, 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> endTime = null, meaning do not have a specific requirement about * completion time. * </ul> * * @param startTime reservation start time * @param endTime reservation end time * @param numPE number of PEs required for this reservation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -