📄 arsimplespaceshared.java
字号:
ResGridlet rgl = cancel(gridletId, userId); // if the Gridlet is not found if (rgl == null) { System.out.println(super.get_name() + ".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.get_name() + ".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.get_name() + ".gridletResume():" + " Gridlet #" + gridletId + " with User ID #" + userId + " has been sucessfully RESUMED."); } else { System.out.println(super.get_name() + ".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); } } /** * Initialises all private attributes * @pre $none * @post $none */ private void init() { reservID_ = 1; reservList_ = new ArrayList(); expiryList_ = new ArrayList(); // initialises local data structure this.gridletInExecList_ = new ResGridletList(); this.gridletPausedList_ = new ResGridletList(); this.gridletQueueList_ = new ResGridletList(); this.gridletWaitingList_ = new ResGridletList(); this.lastUpdateTime_ = 0.0; this.machineRating_ = null; } /** * Checks for expiry time of all reservation in the list. Also checks * whether a reservation has been completed or not. * @pre $none * @post $none */ private void checkExpiryTime() { long currentTime = super.getCurrentTime(); // get current time ARObject obj = null; try { long endTime = 0; // a loop that checks a reservation has been committed before the // expiry time or not for (int i = 0; i < reservList_.size(); i++) { if (reservList_.size() == 0) { break; } obj = (ARObject) reservList_.get(i); // check for expiry time if (obj.hasCommitted() == false && obj.getExpiryTime() <= currentTime) { obj.setStatus(GridSimTags.AR_STATUS_EXPIRED); expiryList_.add(obj); reservList_.remove(obj); continue; } // if no Gridlets executed or time has already gone // then remove it from the list endTime = obj.getStartTime()+(obj.getDurationTime()*MILLI_SEC); if (obj.getTotalGridlet() == 0 && endTime <= currentTime) { obj.setStatus(GridSimTags.AR_STATUS_COMPLETED); expiryList_.add(obj); reservList_.remove(obj); continue; } } } catch (Exception e) { // .... } } /** * Accepts a given reservation and sends a result back to user * @param obj a reservation object to be stored * @param pos an index or position number in the reservation list * @param senderID a user or sender ID * @param sendTag a tag to send to the user * @param expTime reservation expiry time * @param ar true if it is AR, false if it is immediate reservation * @pre obj != null * @pre senderID > 0 * @pre expTime > 0 * @post $none */ private void acceptReservation(ARObject obj, int pos, int senderID, int sendTag, long expTime, boolean ar) { // Create a copy of this object. ARObject arObj = new ARObject(obj); // if expiry time is more or greater than start time, then need to // set it into start time instead. if (ar == true && expTime > obj.getStartTime()) { expTime = obj.getStartTime(); } arObj.setReservation(reservID_, expTime); // set the id + expiry time reservList_.add(pos, arObj); // add the object into the list // convert the expiry time from local time into user's time expTime = AdvanceReservation.convertTimeZone(expTime, resource_.getResourceTimeZone(), obj.getTimeZone() ); // send back to sender super.replyCreateReservation(senderID, sendTag, expTime, reservID_); // then send this into itself to check for expiry time int start = (int) (expTime - super.getCurrentTime()) / super.MILLI_SEC; super.sendInternalEvent(start, EXPIRY_TIME); reservID_++; // increment reservation ID } /** * Finds an empty slot for a particular reservation. * @param startTime reservation start time * @param endTime reservation end time * @param numPE number of PEs required by this reservation * @return the position number in the reservation list or a busy time tag. * @pre startTime > 0 * @pre endTime > 0 * @pre numPE > 0 * @post $none */ private int findEmptySlot(long startTime, long endTime, int numPE) { long finishTime = 0; int pos = NOT_FOUND; // the exact position for a new obj to be put int begin = NOT_FOUND; // start interval for checking PE availability int end = NOT_FOUND; // end interval for checking PE availability // forward increments that looking for position or index for the new // reservation. Also, look for the start interval ARObject obj = null; Iterator iter = reservList_.iterator(); int i = 0; while ( iter.hasNext() ) { obj = (ARObject) iter.next(); // calculates the finish time of each reservation in the list finishTime = obj.getStartTime()+(obj.getDurationTime()*MILLI_SEC); // find exact location to store a new obj // also find the start internal if ( startTime <= obj.getStartTime() ) { // set the correct position or index in the array if (pos == NOT_FOUND) { pos = i; } // if start time is before both begin and finish time if (begin == NOT_FOUND && startTime <= finishTime) { begin = i; } } // if start time is in between begin and finish time else if (begin == NOT_FOUND && startTime <= finishTime) { begin = i; } // then find the end interval if (obj.getStartTime() <= endTime) { end = i; } else { end = i - 1; break; } i++; } // if only 1 job found during the time interval, then make sure the end // doesn't overlap with begin time if (end == NOT_FOUND || end < begin) { end = begin; } // if no position, then it will be appended at the end of the list if (pos == NOT_FOUND) { pos = reservList_.size(); } // once a position in the list is determined, then check availability int result = isAvailable(begin, end, numPE, startTime, endTime); if (result < 0) { pos = result; } return pos; } /** * Finds how many PEs are used within the time interval as indicated by * begin and end position of a list * @param begin a begin index or position in a reservation list * @param end an end index or position in a reservation list * @param numPE number of PEs required by this reservation * @param startTime reservation start time * @param endTime reservation end time * @return the position number in the reservation list or a busy time tag. * @pre $none * @post $none */ private int isAvailable(int begin, int end, int numPE, long startTime, long endTime) { // if the required slot is empty or not occupied if (begin == NOT_FOUND) { return SUCCESS; } ARObject obj = null; long time = 0; // a temp time int result = 0; // if the required slot only has 1 occupants or empty if (begin == end) { obj = (ARObject) reservList_.get(begin); // if the slot is empty if ( endTime < obj.getStartTime() ) { result = SUCCESS; } // determines the total PE of existing reservation + new one else if (obj.getNumPE() + numPE <= totalPE_) { result = SUCCESS; } else { // if no enough PE then approximates the busy time time = obj.getStartTime() + (obj.getDurationTime()*MILLI_SEC) - startTime; result = approxBusyTime(time); } } // if the required slot involves more than 1 occupants else { result = calculateEmptySlot(begin, end, numPE, startTime); } return result; } /** * Finds how many PEs are used within the time interval as indicated by * begin and end position of a list. This involves for more than 1 occupants * in a slot. * @param begin a begin index or position in a reservation list * @param end an end index or position in a reservation list * @param numPE number of PEs required by this reservation * @param startTime reservation start time * @param endTime reservation end time * @return the position number in the reservation list or
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -