📄 spacesharedwithfailure.java
字号:
// 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.resName_ + ".SpaceSharedWithFailure.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 } // if not found anywhere in both exec and paused lists else if (found == -1) { System.out.println(super.resName_ + ".SpaceSharedWithFailure.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 ResGridlet rgl = cancel(gridletId, userId); // if the Gridlet is not found if (rgl == null) { System.out.println(super.resName_ + ".SpaceSharedWithFailure.gridletMove(): Cannot find " + "Gridlet #" + gridletId + " for User #" + userId); if (ack == true) // sends back an ack if required { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); } return; } // if the Gridlet has finished beforehand if (rgl.getGridletStatus() == Gridlet.SUCCESS) { System.out.println(super.resName_ + ".SpaceSharedWithFailure.gridletMove(): Cannot move Gridlet #" + gridletId + " for User #"+ userId+ " since it has FINISHED."); if (ack == true) // sends back an ack if required { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); } gridletFinish(rgl, Gridlet.SUCCESS); } else // otherwise moves this Gridlet to a different GridResource { rgl.finalizeGridlet(); // Set PE on which Gridlet finished to FREE super.resource_.setStatusPE( PE.FREE, rgl.getMachineID(), rgl.getPEID() ); super.gridletMigrate(rgl.getGridlet(), destId, ack); allocateQueueGridlet(); } } /** * Resumes a Gridlet only in the paused 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 gridletResume(int gridletId, int userId, boolean ack) { boolean status = false; // finds the Gridlet in the execution list first int found = super.findGridlet(gridletPausedList_, gridletId, userId); if (found >= 0) { // removes the Gridlet ResGridlet rgl = (ResGridlet) gridletPausedList_.remove(found); rgl.setGridletStatus(Gridlet.RESUMED); // update the Gridlets up to this point in time updateGridletProcessing(); status = true; // if there is an available PE slot, then allocate immediately boolean success = false; if ( gridletInExecList_.size() < super.totalPE_ ) { success = allocatePEtoGridlet(rgl); } // otherwise put into Queue list if (success == false) { rgl.setGridletStatus(Gridlet.QUEUED); gridletQueueList_.add(rgl); } System.out.println(super.resName_ + "TimeShared.gridletResume():" + " Gridlet #" + gridletId + " with User ID #" + userId + " has been sucessfully RESUMED."); } else { System.out.println(super.resName_ + "TimeShared.gridletResume(): Cannot find " + "Gridlet #" + gridletId + " for User #" + userId); } // sends back an ack if required if (ack == true) { super.sendAck(GridSimTags.GRIDLET_RESUME_ACK, status, gridletId, userId); } } ///////////////////////////// PRIVATE METHODS ///////////////////// /** * Allocates the first Gridlet in the Queue list (if any) to execution list * @pre $none * @post $none */ private void allocateQueueGridlet() { // if there are many Gridlets in the QUEUE, then allocate a // PE to the first Gridlet in the list since it follows FCFS // (First Come First Serve) approach. Then removes the Gridlet from // the Queue list if (gridletQueueList_.size() > 0 && gridletInExecList_.size() < super.totalPE_) { ResGridlet obj = (ResGridlet) gridletQueueList_.get(0); // allocate the Gridlet into an empty PE slot and remove it from // the queue list boolean success = allocatePEtoGridlet(obj); if (success == true) { gridletQueueList_.remove(obj); } } } /** * Updates the execution of all Gridlets for a period of time. * The time period is determined from the last update time up to the * current time. Once this operation is successfull, then the last update * time refers to the current time. * @pre $none * @post $none */ private void updateGridletProcessing() { // Identify MI share for the duration (from last event time) double time = GridSim.clock(); double timeSpan = time - lastUpdateTime_; // if current time is the same or less than the last update time, // then ignore if (timeSpan <= 0.0) { return; } // Update Current Time as Last Update lastUpdateTime_ = time; // update the GridResource load int size = gridletInExecList_.size(); double load = super.calculateTotalLoad(size); super.addTotalLoad(load); // if no Gridlets in execution then ignore the rest if (size == 0) { return; } ResGridlet obj = null; // a loop that allocates MI share for each Gridlet accordingly Iterator iter = gridletInExecList_.iterator(); while ( iter.hasNext() ) { obj = (ResGridlet) iter.next(); // Updates the Gridlet length that is currently being executed load = getMIShare( timeSpan, obj.getMachineID() ); obj.updateGridletFinishedSoFar(load); } } /** * Identifies MI share (max and min) each Gridlet gets for * a given timeSpan * @param timeSpan duration * @param machineId machine ID that executes this Gridlet * @return the total MI share that a Gridlet gets for a given * <tt>timeSpan</tt> * @pre timeSpan >= 0.0 * @pre machineId > 0 * @post $result >= 0.0 */ private double getMIShare(double timeSpan, int machineId) { // 1 - localLoad_ = available MI share percentage double localLoad = super.resCalendar_.getCurrentLoad(); // each Machine might have different PE Rating compare to another // so much look at which Machine this PE belongs to double totalMI = machineRating_[machineId] * timeSpan * (1 - localLoad); return totalMI; } /** * Allocates a Gridlet into a free PE and sets the Gridlet status into * INEXEC and PE status into busy afterwards * @param rgl a ResGridlet object * @return <tt>true</tt> if there is an empty PE to process this Gridlet, * <tt>false</tt> otherwise * @pre rgl != null * @post $none */ private boolean allocatePEtoGridlet(ResGridlet rgl) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -