📄 arsimplespaceshared.java
字号:
result = obj.getStatus(); } // sends the result back to user super.replyQueryReservation(senderID, sendTag, result); } /** * Handles internal events that are coming to this entity. * @pre $none * @post $none */ public void body() { // Gets the PE's rating for each Machine in the list. // Assumed one Machine has same PE rating. MachineList list = super.resource_.getMachineList(); int size = list.size(); machineRating_ = new int[size]; for (int i = 0; i < size; i++) { machineRating_[i] = super.resource_.getMIPSRatingOfOnePE(i, 0); } // a loop that is looking for internal events only Sim_event ev = new Sim_event(); while ( Sim_system.running() ) { super.sim_get_next(ev); // if the simulation finishes then exit the loop if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || super.isEndSimulation() == true) { gridletInExecList_.clear(); gridletQueueList_.clear(); gridletWaitingList_.clear(); reservList_.clear(); break; } // checks the expiry time for all reservations if (ev.get_src() == super.myId_ && ev.get_tag() == EXPIRY_TIME) { checkExpiryTime(); continue; } // time to execute reservations' Gridlets. if (ev.get_src() == super.myId_ && ev.get_tag() == PERFORM_RESERVATION) { performReservation(); continue; } // Internal Event if the event source is this entity if (ev.get_src() == super.myId_ && gridletInExecList_.size() > 0) { updateGridletProcessing(); // update Gridlets checkGridletCompletion(); // check for finished Gridlets // periodically need to check reservations performReservation(); } } // CHECK for ANY INTERNAL EVENTS WAITING TO BE PROCESSED while (super.sim_waiting() > 0) { // wait for event and ignore since it is likely to be related to // internal event scheduled to update Gridlets processing super.sim_get_next(ev); System.out.println(super.get_name() + ".body(): ignore internal events"); } } /** * Schedules a new Gridlet that has been received by the GridResource * entity. * @param gl a Gridlet object that is going to be executed * @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) * @pre gl != null * @post $none */ public void gridletSubmit(Gridlet gl, boolean ack) { // update the current Gridlets in exec list up to this point in time updateGridletProcessing(); // reset number of PE since at the moment, it is not supported if (gl.getNumPE() > 1) { String userName = GridSim.getEntityName( gl.getUserID() ); System.out.println(); System.out.println(super.get_name() + ".gridletSubmit(): " + " Gridlet #" + gl.getGridletID() + " from " + userName + " user requires " + gl.getNumPE() + " PEs."); System.out.println("--> Process this Gridlet to 1 PE only."); System.out.println(); // also adjusted the length because the number of PEs are reduced int numPE = gl.getNumPE(); double len = gl.getGridletLength(); gl.setGridletLength(len*numPE); gl.setNumPE(1); } ResGridlet rgl = new ResGridlet(gl); boolean success = false; // if there is an available PE slot, then allocate immediately if (gridletInExecList_.size() < super.totalPE_) { success = allocatePEtoGridlet(rgl); } // if no available PE then put the ResGridlet into a Queue list if (success == false) { rgl.setGridletStatus(Gridlet.QUEUED); gridletQueueList_.add(rgl); } // sends back an ack if required if (ack == true) { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, true, gl.getGridletID(), gl.getUserID() ); } } /** * Finds the status of a specified Gridlet ID. * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet * @return the Gridlet status or <tt>-1</tt> if not found * @see gridsim.Gridlet * @pre gridletId > 0 * @pre userId > 0 * @post $none */ public int gridletStatus(int gridletId, int userId) { ResGridlet rgl = null; // Find in EXEC List first int found = super.findGridlet(gridletInExecList_, gridletId, userId); if (found >= 0) { // Get the Gridlet from the execution list rgl = (ResGridlet) gridletInExecList_.get(found); return rgl.getGridletStatus(); } // Find in Paused List found = super.findGridlet(gridletPausedList_, gridletId, userId); if (found >= 0) { // Get the Gridlet from the execution list rgl = (ResGridlet) gridletPausedList_.get(found); return rgl.getGridletStatus(); } // Find in Queue List found = super.findGridlet(gridletQueueList_, gridletId, userId); if (found >= 0) { // Get the Gridlet from the execution list rgl = (ResGridlet) gridletQueueList_.get(found); return rgl.getGridletStatus(); } // Find in the AR Waiting List found = super.findGridlet(gridletWaitingList_, gridletId, userId); if (found >= 0) { // Get the Gridlet from the execution list rgl = (ResGridlet) gridletWaitingList_.get(found); return rgl.getGridletStatus(); } // if not found in all lists then no found return -1; } /** * Cancels a Gridlet running in this entity. * The User ID is * important as many users might have the same Gridlet ID in the lists.<br> * <b>NOTE:</b> * <ul> * <li> Before canceling a Gridlet, this method updates all the * Gridlets in the execution list. If the Gridlet has no more MIs * to be executed, then it is considered to be <tt>finished</tt>. * Hence, the Gridlet can't be canceled. * * <li> Once a Gridlet has been canceled, it can't be resumed to * execute again since this method will pass the Gridlet back to * sender, i.e. the <tt>userId</tt>. * * <li> If a Gridlet can't be found in both execution and paused list, * then a <tt>null</tt> Gridlet will be send back to sender, * i.e. the <tt>userId</tt>. * </ul> * * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet * @pre gridletId > 0 * @pre userId > 0 * @post $none */ public void gridletCancel(int gridletId, int userId) { // cancels a Gridlet ResGridlet rgl = cancel(gridletId, userId); // if the Gridlet is not found if (rgl == null) { System.out.println(super.get_name() + ".gridletCancel(): Cannot " + "find Gridlet #" + gridletId + " for User #" + userId); super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, null, gridletId, userId); return; } // if the Gridlet has finished beforehand then prints an error msg if (rgl.getGridletStatus() == Gridlet.SUCCESS) { System.out.println(super.get_name() + ".gridletCancel(): Cannot " + "cancel Gridlet #" + gridletId + " for User #" + userId + " since it has FINISHED."); } // sends the Gridlet back to sender rgl.finalizeGridlet(); super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, rgl.getGridlet(), gridletId, userId); } /** * Pauses a Gridlet only if it is currently executing. * This method will search in the execution list, as well as in the queue * list. The User ID is * important as many users might have the same Gridlet ID in the lists. * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet * @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) * @pre gridletId > 0 * @pre userId > 0 * @post $none */ public void gridletPause(int gridletId, int userId, boolean ack) { boolean status = false; // Find in EXEC List first int found = super.findGridlet(gridletInExecList_, gridletId, userId); if (found >= 0) { // updates all the Gridlets first before pausing updateGridletProcessing(); // Removes the Gridlet from the execution list ResGridlet rgl = (ResGridlet) gridletInExecList_.remove(found); // if a Gridlet is finished upon cancelling, then set it to success // instead. if (rgl.getRemainingGridletLength() == 0.0) { found = -1; // meaning not found in Queue List gridletFinish(rgl, Gridlet.SUCCESS); System.out.println(super.get_name() + ".gridletPause(): Cannot pause" + " Gridlet #" + gridletId + " for User #" + userId + " since it has FINISHED."); } else { status = true; rgl.setGridletStatus(Gridlet.PAUSED); // change the status gridletPausedList_.add(rgl); // add into the paused list // Set the PE on which Gridlet finished to FREE super.resource_.setStatusPE( PE.FREE, rgl.getMachineID(), rgl.getPEID() ); // empty slot is available, hence process a new Gridlet allocateQueueGridlet(); } } else { // Find in QUEUE list found = super.findGridlet(gridletQueueList_, gridletId, userId); } // if found in the Queue List if (status == false && found >= 0) { status = true; // removes the Gridlet from the Queue list ResGridlet rgl = (ResGridlet) gridletQueueList_.remove(found); rgl.setGridletStatus(Gridlet.PAUSED); // change the status gridletPausedList_.add(rgl); // add into the paused list } else { // Find in the AR Waiting List found = super.findGridlet(gridletWaitingList_, gridletId, userId); } // if found in the AR waiting list if (status == false && found >= 0) { status = true; // removes the Gridlet from the waiting list ResGridlet rgl = (ResGridlet) gridletWaitingList_.remove(found); rgl.setGridletStatus(Gridlet.PAUSED); // change the status gridletPausedList_.add(rgl); // add into the paused list } // if not found anywhere in both exec and paused lists else if (found == -1) { System.out.println(super.get_name() + ".gridletPause(): Error - cannot " + "find Gridlet #" + gridletId + " for User #" + userId); } // sends back an ack if required if (ack == true) { super.sendAck(GridSimTags.GRIDLET_PAUSE_ACK, status, gridletId, userId); } } /** * Moves a Gridlet from this GridResource entity to a different one. * This method will search in both the execution and paused list. * The User ID is important as many Users might have the same Gridlet ID * in the lists. * <p> * If a Gridlet has finished beforehand, then this method will send back * the Gridlet to sender, i.e. the <tt>userId</tt> and sets the * acknowledgment to false (if required). * * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet * @param destId a new destination GridResource ID for this Gridlet * @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) * @pre gridletId > 0 * @pre userId > 0 * @pre destId > 0 * @post $none */ public void gridletMove(int gridletId, int userId, int destId, boolean ack) { // cancels the Gridlet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -