📄 resgridlet.java
字号:
/* * Title: GridSim Toolkit * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * * $Id: ResGridlet.java,v 1.27 2005/07/19 07:36:41 anthony Exp $ */package gridsim;import java.util.Calendar;/** * GridSim ResGridlet represents a Gridlet submitted to GridResource for * processing. This class keeps track the time for all activities in the * GridResource for a specific Gridlet. Before a Gridlet exits the * GridResource, it is RECOMMENDED to call this method * {@link #finalizeGridlet()}. * <p> * It contains a Gridlet object along with its arrival time and * the ID of the machine and the PE (Processing Element) allocated to it. * It acts as a placeholder for maintaining the amount of resource share * allocated at various times for simulating any * scheduling using internal events. * * @author Manzur Murshed and Rajkumar Buyya * @since GridSim Toolkit 1.0 * @invariant $none */public class ResGridlet{ private Gridlet gridlet_; // a Gridlet object private double arrivalTime_; // Gridlet arrival time for the first time private double finishedTime_; // estimation of Gridlet finished time private double gridletFinishedSoFar_; // length of Gridlet finished so far // Gridlet execution start time. This attribute will only hold the latest // time since a Gridlet can be cancel, paused or resumed. private double startExecTime_; private double totalCompletionTime_; // total time to complete this Gridlet // The below attributes are only be used by the SpaceShared policy private int machineID_; // machine id this Gridlet is assigned to private int peID_; // PE id this Gridlet is assigned to private int[] machineArrayID_ = null; // an array of machine IDs private int[] peArrayID_ = null; // an array of PE IDs private int index_; // index of machine and PE arrays // NOTE: Below attributes are related to AR stuff private final int NOT_FOUND = -1; private long startTime_; // reservation start time private int duration_; // reservation duration time private int reservID_; // reservation id private int numPE_; // num PE needed to execute this Gridlet /** * Allocates a new ResGridlet object upon the arrival of a Gridlet object. * The arriving time is determined by {@link gridsim.GridSim#clock()}. * @param gridlet a gridlet object * @see gridsim.GridSim#clock() * @pre gridlet != null * @post $none */ public ResGridlet(Gridlet gridlet) { // when a new ResGridlet is created, then it will automatically set // the submission time and other properties, such as remaining length this.gridlet_ = gridlet; this.startTime_ = 0; this.reservID_ = NOT_FOUND; this.duration_ = 0; init(); } /** * Allocates a new ResGridlet object upon the arrival of a Gridlet object. * Use this constructor to store reserved Gridlets, i.e. Gridlets that * done reservation before. * The arriving time is determined by {@link gridsim.GridSim#clock()}. * @param gridlet a gridlet object * @param startTime a reservation start time. Can also be interpreted * as starting time to execute this Gridlet. * @param duration a reservation duration time. Can also be interpreted * as how long to execute this Gridlet. * @param reservID a reservation ID that owns this Gridlet * @see gridsim.GridSim#clock() * @pre gridlet != null * @pre startTime > 0 * @pre duration > 0 * @pre reservID > 0 * @post $none */ public ResGridlet(Gridlet gridlet,long startTime,int duration,int reservID) { this.gridlet_ = gridlet; this.startTime_ = startTime; this.reservID_ = reservID; this.duration_ = duration; init(); } /** * Gets the Gridlet or reservation start time. * @return Gridlet's starting time * @pre $none * @post $none */ public long getStartTime() { return startTime_; } /** * Gets the reservation duration time. * @return reservation duration time * @pre $none * @post $none */ public int getDurationTime() { return duration_; } /** * Gets the number of PEs required to execute this Gridlet. * @return number of PE * @pre $none * @post $none */ public int getNumPE() { return numPE_; } /** * Gets the reservation ID that owns this Gridlet * @return a reservation ID * @pre $none * @post $none */ public int getReservationID() { return reservID_; } /** * Checks whether this Gridlet is submitted by reserving or not. * @return <tt>true</tt> if this Gridlet has reserved before, * <tt>false</tt> otherwise * @pre $none * @post $none */ public boolean hasReserved() { if (reservID_ == NOT_FOUND) { return false; } return true; } /** * Initialises all local attributes * @pre $none * @post $none */ private void init() { // get number of PEs required to run this Gridlet this.numPE_ = gridlet_.getNumPE(); // if more than 1 PE, then create an array if (numPE_ > 1) { this.machineArrayID_ = new int[numPE_]; this.peArrayID_ = new int[numPE_]; } this.arrivalTime_ = GridSim.clock(); this.gridlet_.setSubmissionTime(arrivalTime_); // default values this.finishedTime_ = NOT_FOUND; // Cannot finish in this hourly slot. this.machineID_ = NOT_FOUND; this.peID_ = NOT_FOUND; this.index_ = 0; this.totalCompletionTime_ = 0.0; this.startExecTime_ = 0.0; // In case a Gridlet has been executed partially by some other grid // resources. this.gridletFinishedSoFar_ = gridlet_.getGridletFinishedSoFar(); } /** * Gets this Gridlet entity Id * @return the Gridlet entity Id * @pre $none * @post $none */ public int getGridletID() { return gridlet_.getGridletID(); } /** * Gets the user or owner of this Gridlet * @return the Gridlet's user Id * @pre $none * @post $none */ public int getUserID() { return gridlet_.getUserID(); } /** * Gets the Gridlet's length * @return Gridlet's length * @pre $none * @post $none */ public double getGridletLength() { return gridlet_.getGridletLength(); } /** * Gets the Gridlet's class type * @return class type of the Gridlet * @pre $none * @post $none */ public int getGridletClassType() { return gridlet_.getClassType() ; } /** * Sets the Gridlet status. * @param status the Gridlet status * @return <tt>true</tt> if the new status has been set, <tt>false</tt> * otherwise * @pre status >= 0 * @post $none */ public boolean setGridletStatus(int status) { // gets Gridlet's previous status int prevStatus = gridlet_.getGridletStatus(); // if the status of a Gridlet is the same as last time, then ignore if (prevStatus == status) { return false; } boolean success = true; try { double clock = GridSim.clock(); // gets the current clock // sets Gridlet's current status gridlet_.setGridletStatus(status); // if a previous Gridlet status is INEXEC if (prevStatus == Gridlet.INEXEC) { // and current status is either CANCELED, PAUSED or SUCCESS if (status == Gridlet.CANCELED || status == Gridlet.PAUSED || status == Gridlet.SUCCESS) { // then update the Gridlet completion time totalCompletionTime_ += (clock - startExecTime_); index_ = 0; return true; } } if (prevStatus == Gridlet.RESUMED && status == Gridlet.SUCCESS) { // then update the Gridlet completion time totalCompletionTime_ += (clock - startExecTime_); return true; } // if a Gridlet is now in execution if (status == Gridlet.INEXEC || (prevStatus == Gridlet.PAUSED && status == Gridlet.RESUMED) ) { startExecTime_ = clock; gridlet_.setExecStartTime(startExecTime_); } } catch(Exception e) { success = false; } return success; } /** * Gets the Gridlet's execution start time * @return Gridlet's execution start time * @pre $none * @post $none */ public double getExecStartTime() { return gridlet_.getExecStartTime(); } /** * Sets this Gridlet's execution parameters. These parameters are set by * the GridResource before departure or sending back to the original * Gridlet's owner. * * @param wallClockTime the time of this Gridlet resides in * a GridResource (from arrival time until * departure time). * @param actualCPUTime the total execution time of this Gridlet in a * GridResource. * @pre wallClockTime >= 0.0 * @pre actualCPUTime >= 0.0 * @post $none */ public void setExecParam(double wallClockTime, double actualCPUTime) { gridlet_.setExecParam(wallClockTime, actualCPUTime); } /** * Sets the machine and PE (Processing Element) ID * @param machineID machine ID * @param peID PE ID * @deprecated As of GridSim 2.1, replaced by * {@link #setMachineAndPEID(int, int)} * @pre machineID >= 0 * @pre peID >= 0 * @post $none */ public void SetIDs(int machineID, int peID) { this.setMachineAndPEID(machineID, peID); } /** * Sets the machine and PE (Processing Element) ID * @param machineID machine ID * @param peID PE ID * @pre machineID >= 0 * @pre peID >= 0 * @post $none */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -