?? gridsim.java
字號:
System.out.println( e.getMessage() ); } catch (Exception e) { gl = null; System.out.println(errorMsg + "Error occurs."); System.out.println( e.getMessage() ); } return gl; } /** * Pauses a Gridlet that is currently executing in a given GridResource * ID <tt>with</tt> a delay. * @param gl a Gridlet object to be sent * @param resId an unique resource ID * @param delay delay time or <tt>0.0</tt> if want to execute NOW * @return <tt>true</tt> if this Gridlet has been paused successfully in the * destination GridResource, <tt>false</tt> otherwise. * Pausing a Gridlet can be failed for the one or more * following reasons: * <ul> * <li> if a GridResource ID doesn't exist * <li> if a Gridlet ID doesn't exist * <li> if a Gridlet's user ID doesn't exist * <li> if the delay time is negative * <li> if a Gridlet object is <tt>null</tt> or empty; * <li> if a Gridlet object has <tt>finished</tt> executing * beforehand. The Gridlet needs to be retrieved by * using {@link #gridletReceive()} * </ul> * @pre gl != null * @pre resId >= 0 * @pre delay >= 0.0 * @post $none */ protected boolean gridletPause(Gridlet gl, int resId, double delay) { if (gl == null || delay < 0.0) { return false; } return gridletPause(gl.getGridletID(),gl.getUserID(),resId,delay,true); } /** * Pauses a Gridlet that is currently executing in a given GridResource * ID <tt>with</tt> a delay. * @param gridletId a Gridlet ID * @param userId the user or owner ID of this Gridlet * @param resourceId an unique resource ID * @param delay delay time or <tt>0.0</tt> if want to execute NOW * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know * whether this operation is success or not, <tt>false</tt> * otherwise (don't care) * @return <tt>true</tt> if this Gridlet has been paused successfully in the * destination GridResource, <tt>false</tt> otherwise. * Pausing a Gridlet can be failed for the one or more * following reasons: * <ul> * <li> if a GridResource ID doesn't exist * <li> if a Gridlet ID doesn't exist * <li> if a Gridlet's user ID doesn't exist * <li> if the delay time is negative * <li> if a Gridlet object has <tt>finished</tt> executing * beforehand. The Gridlet needs to be retrieved by using * {@link #gridletReceive()} * </ul> * @pre gridletId >= 0 * @pre userId >= 0 * @pre resourceId >= 0 * @pre delay >= 0.0 * @post $none */ protected boolean gridletPause(int gridletId, int userId, int resourceId, double delay, boolean ack) { boolean valid = false; String errorMsg = super.get_name() + ".gridletPause(): "; try { valid = sendGridlet(errorMsg, gridletId, userId, resourceId, delay, GridSimTags.GRIDLET_PAUSE, ack); if (valid == true && ack == true) { valid = getBooleanResult(gridletId, GridSimTags.GRIDLET_PAUSE_ACK); } } catch (Sim_exception e) { valid = false; System.out.println(errorMsg + "Error occurs."); System.out.println( e.getMessage() ); } catch (Exception e) { valid = false; System.out.println(errorMsg + "Error occurs."); System.out.println( e.getMessage() ); } return valid; } /** * Gets the current status of this Gridlet in a given GridResource ID * @param gl a Gridlet object * @param resourceId a GridResource ID that executes this Gridlet object * @return the current Gridlet status or <tt>-1</tt> if not found. * The various Gridlet status can be found in Gridlet class. * @see gridsim.Gridlet * @pre gl != null * @pre resourceId > 0 * @post $none */ protected int gridletStatus(Gridlet gl, int resourceId) { if (gl == null) { return NOT_FOUND; } return gridletStatus(gl.getGridletID(), gl.getUserID(), resourceId); } /** * Gets the current status of this Gridlet in a given GridResource ID * @param gridletId a Gridlet ID * @param userId the user or owner of this Gridlet object * @param resourceId a GridResource ID that executes this Gridlet object * @return the current Gridlet status or <tt>-1</tt> if not found. * The various Gridlet status can be found in Gridlet class. * @see gridsim.Gridlet * @pre gridletId > 0 * @pre userId > 0 * @pre resourceId > 0 * @post $none */ protected int gridletStatus(int gridletId, int userId, int resourceId) { int status = NOT_FOUND; String errorMsg = super.get_name() + "gridletStatus(): "; try { boolean valid = sendGridlet(errorMsg, gridletId, userId, resourceId, 0.0, GridSimTags.GRIDLET_STATUS, false); if (valid == false) { return status; } // waiting for a response from the GridResource status = getIntResult(gridletId, GridSimTags.GRIDLET_STATUS); } catch (Sim_exception e) { status = NOT_FOUND; System.out.println(errorMsg + "Error occurs."); System.out.println( e.getMessage() ); } catch (Exception e) { status = NOT_FOUND; System.out.println(errorMsg + "Error occurs."); System.out.println( e.getMessage() ); } return status; } /** * Resumes a Gridlet that is currently pausing in a given GridResource * ID <tt>with</tt> a delay.<br> * <b>NOTE:</b> Resuming a Gridlet only works if it is currently on paused. * @param gl a Gridlet object to be sent * @param resId an unique resource ID * @param delay delay time or <tt>0.0</tt> if want to execute NOW * @return <tt>true</tt> if this Gridlet has been resumed successfully in * the destination GridResource, <tt>false</tt> otherwise. * Resuming a Gridlet can be failed for the one or more * following reasons: * <ul> * <li> if a GridResource ID doesn't exist * <li> if a Gridlet ID doesn't exist * <li> if a Gridlet's user ID doesn't exist * <li> if the delay time is negative * <li> if a Gridlet object is <tt>null</tt> or empty * <li> if a Gridlet is not currently on paused * </ul> * @pre gl != null * @pre resId >= 0 * @pre delay >= 0.0 * @post $none */ protected boolean gridletResume(Gridlet gl, int resId, double delay) { if (gl == null || delay < 0.0) { return false; } return gridletResume(gl.getGridletID(),gl.getUserID(),resId,delay,true); } /** * Resumes a Gridlet that is currently pausing in a given GridResource * ID <tt>with</tt> a delay. <br> * <b>NOTE:</b> Resuming a Gridlet only works if it is currently on paused. * @param gridletId a Gridlet ID * @param userId the user or owner ID of this Gridlet * @param resourceId an unique resource ID * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know * whether this operation is success or not, <tt>false</tt> * otherwise (don't care) * @return <tt>true</tt> if this Gridlet has been resumed successfully in * the destination GridResource, <tt>false</tt> otherwise. * Resuming a Gridlet can be failed for the one or more * following reasons: * <ul> * <li> if a GridResource ID doesn't exist * <li> if a Gridlet ID doesn't exist * <li> if a Gridlet's user ID doesn't exist * <li> if the delay time is negative * <li> if a Gridlet is not currently on paused * </ul> * @pre gridletId >= 0 * @pre userId >= 0 * @pre resourceId >= 0 * @pre delay >= 0.0 * @post $none */ protected boolean gridletResume(int gridletId, int userId, int resourceId, double delay, boolean ack) { boolean valid = false; String errorMsg = super.get_name() + ".gridletResume(): "; try { valid = sendGridlet(errorMsg, gridletId, userId, resourceId, delay, GridSimTags.GRIDLET_RESUME, ack); if (valid == true && ack == true) { // waiting for a response from the GridResource valid = getBooleanResult(gridletId, GridSimTags.GRIDLET_RESUME_ACK); } } catch (Sim_exception e) { valid = false; System.out.println(errorMsg + "Error occurs."); System.out.println( e.getMessage() ); } catch (Exception e) { valid = false; System.out.println(errorMsg + "Error occurs."); System.out.println( e.getMessage() ); } return valid; } /** * Moves a Gridlet to the destination GridResource ID * @param gl a Gridlet object * @param srcId the GridResource ID that is currently executing this Gridlet * @param destId the new GridResource ID * @param delay simulation delay * @return <tt>true</tt> if this Gridlet has moved successfully, * <tt>false</tt> otherwise. Moving a Gridlet can be failed, due * to one or more following reasons: * <ul> * <li> if a Gridlet object is null * <li> if one or both GridResource ID don't exist * <li> if the delay is negative * <li> if a Gridlet in the GridResource has completed beforehand. * The Gridlet can be retrieved by using * {@link #gridletReceive()} * </ul> * @pre gl != null * @pre srcId > 0 * @pre destId > 0 * @pre delay >= 0.0 * @post $result = true || false */ protected boolean gridletMove(Gridlet gl,int srcId,int destId,double delay) { if (gl == null || delay < 0.0) { return false; } boolean success = gridletMove(gl.getGridletID(), gl.getUserID(), srcId, destId, delay, true); return success; } /** * Moves a Gridlet to the destination GridResource ID * @param gridletId a Gridlet ID * @param userId the owner or user ID of this Gridlet * @param srcId the GridResource ID that is currently executing this * Gridlet * @param destId the new GridResource ID * @param delay simulation delay * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know * whether this operation is success or not, <tt>false</tt> * otherwise (don't care) * @return <tt>true</tt> if this Gridlet has moved successfully, * <tt>false</tt> otherwise. Moving a Gridlet can be failed, due * to one or more following reasons: * <ul> * <li> if a Gridlet ID doesn't exist * <li> if the owner of user ID of this Gridlet doesn't exist * <li> if one or both GridResource ID don't exist * <li> if the delay is negative * <li> if a Gridlet in the GridResource has completed beforehand. * The Gridlet can be retrieved by using * {@link #gridletReceive()} * </ul> * @pre gridletId > 0 * @pre userId > 0 * @pre srcId > 0 * @pre destId > 0 * @pre delay >= 0.0 * @post $result = true || false */ protected boolean gridletMove(int gridletId, int userId, int srcId, int destId, double delay, boolean ack) { String errorMsg = super.get_name() + ".gridletMove(): "; // check whether the source Id is the same as destination Id if (srcId == destId) { System.out.println(errorMsg + "Error - Can't move a
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -