📄 gridlet.java
字号:
* @post $none */ public String GetStatusString() { return this.getGridletStatusString(); } /** * Gets the string representation of the current Gridlet status code * @return the Gridlet status code as a string or <tt>null</tt> if the * status code is unknown * @pre $none * @post $none */ public String getGridletStatusString() { return Gridlet.getStatusString(status_); } /** * Gets the string representation of the given Gridlet status code * @param status the Gridlet status code * @return the Gridlet status code as a string or <tt>null</tt> if the * status code is unknown * @pre $none * @post $none */ public static String getStatusString(int status) { String statusString = null; switch (status) { case Gridlet.CREATED: statusString = "Created"; break; case Gridlet.READY: statusString = "Ready"; break; case Gridlet.INEXEC: statusString = "InExec"; break; case Gridlet.SUCCESS: statusString = "Success"; break; case Gridlet.QUEUED: statusString = "Queued"; break; case Gridlet.FAILED: statusString = "Failed"; break; case Gridlet.CANCELED: statusString = "Canceled"; break; case Gridlet.PAUSED: statusString = "Paused"; break; case Gridlet.RESUMED: statusString = "Resumed"; break; default: break; } return statusString; } /** * Gets the length of this Gridlet * @return the length of this Gridlet * @deprecated As of GridSim 2.1, replaced by {@link #getGridletLength()} * @pre $none * @post $result >= 0.0 */ public double GetGridletLength() { return this.getGridletLength(); } /** * Gets the length of this Gridlet * @return the length of this Gridlet * @pre $none * @post $result >= 0.0 */ public double getGridletLength() { return gridletLength_; } /** * Gets the total execution time of this Gridlet from the latest * GridResource * @return the the total execution time of this Gridlet in a GridResource * @deprecated As of GridSim 2.1, replaced by {@link #getActualCPUTime()} * @pre $none * @post $result >= 0.0 */ public double GetActualCPUTime() { return this.getActualCPUTime(); } /** * Gets the total execution time of this Gridlet from the latest * GridResource * @return the total execution time of this Gridlet in a GridResource * @pre $none * @post $result >= 0.0 */ public double getActualCPUTime() { if (index_ == -1) { return 0.0; } return ( (Resource) resList_.get(index_) ).actualCPUTime; } /** * Gets the cost running this Gridlet in the latest GridResource * @return the cost associated with running this Gridlet * or <tt>0.0</tt> if none * @deprecated As of GridSim 2.1, replaced by {@link #getCostPerSec()} * @pre $none * @post $result >= 0.0 */ public double GetCostPerSec() { return this.getCostPerSec(); } /** * Gets the cost running this Gridlet in the latest GridResource * @return the cost associated with running this Gridlet * or <tt>0.0</tt> if none * @pre $none * @post $result >= 0.0 */ public double getCostPerSec() { if (index_ == -1) { return 0.0; } return ( (Resource) resList_.get(index_) ).costPerSec; } /** * Gets the total cost of processing or executing this Gridlet. * <tt>Processing Cost = actual CPU Time * cost per sec</tt> * @return the total cost of processing Gridlet * @deprecated As of GridSim 2.1, replaced by {@link #getProcessingCost()} * @see gridsim.Gridlet#getActualCPUTime() * @see gridsim.Gridlet#getCostPerSec() * @pre $none * @post $result >= 0.0 */ public double GetProcessingCost() { return this.getProcessingCost(); } /** * Gets the total cost of processing or executing this Gridlet * <tt>Processing Cost = actual CPU Time * cost per sec</tt> * @return the total cost of processing Gridlet * @see gridsim.Gridlet#getActualCPUTime() * @see gridsim.Gridlet#getCostPerSec() * @pre $none * @post $result >= 0.0 */ public double getProcessingCost() { if (index_ == -1) { return 0.0; } Resource res = null; double cost = 0.0; for (int i = 0; i <= index_; i++) { res = (Resource) resList_.get(i); cost += (res.actualCPUTime * res.costPerSec); } return cost; } /** * Gets the time of this Gridlet resides in the latest GridResource * (from arrival time until departure time). * @return the time of this Gridlet resides in a GridResource * @deprecated As of GridSim 2.1, replaced by {@link #getWallClockTime()} * @pre $none * @post $result >= 0.0 */ public double GetWallClockTime() { return this.getWallClockTime(); } /** * Gets the time of this Gridlet resides in the latest GridResource * (from arrival time until departure time). * @return the time of this Gridlet resides in a GridResource * @pre $none * @post $result >= 0.0 */ public double getWallClockTime() { if (index_ == -1) { return 0.0; } return ( (Resource) resList_.get(index_) ).wallClockTime; } /** * Gets all the GridResource names that executed this Gridlet * @return an array of GridResource names or <tt>null</tt> if it has none * @pre $none * @post $none */ public String[] getAllResourceName() { int size = resList_.size(); String[] data = null; if (size > 0) { data = new String[size]; for (int i = 0; i < size; i++) { data[i] = ( (Resource) resList_.get(i)).resourceName; } } return data; } /** * Gets all the GridResource IDs that executed this Gridlet * @return an array of GridResource IDs or <tt>null</tt> if it has none * @pre $none * @post $none */ public int[] getAllResourceID() { int size = resList_.size(); int[] data = null; if (size > 0) { data = new int[size]; for (int i = 0; i < size; i++) { data[i] = ( (Resource) resList_.get(i)).resourceId; } } return data; } /** * Gets the total execution time of this Gridlet in a given GridResource ID * @param resId a GridResource entity ID * @return the total execution time of this Gridlet in a GridResource * or <tt>0.0</tt> if not found * @pre resId >= 0 * @post $result >= 0.0 */ public double getActualCPUTime(int resId) { Resource res = null; int size = resList_.size(); for (int i = 0; i < size; i++) { res = (Resource) resList_.get(i); if (resId == res.resourceId) { return res.actualCPUTime; } } return 0.0; } /** * Gets the cost running this Gridlet in a given GridResource ID * @param resId a GridResource entity ID * @return the cost associated with running this Gridlet * or <tt>0.0</tt> if not found * @pre resId >= 0 * @post $result >= 0.0 */ public double getCostPerSec(int resId) { Resource res = null; int size = resList_.size(); for (int i = 0; i < size; i++) { res = (Resource) resList_.get(i); if (resId == res.resourceId) { return res.costPerSec; } } return 0.0; } /** * Gets the length of this Gridlet that has been executed so far in a given * GridResource ID. This method is useful when trying to move this Gridlet * into different GridResources or to cancel it. * @param resId a GridResource entity ID * @return the length of a partially executed Gridlet or the full Gridlet * length if it is completed or <tt>0.0</tt> if not found * @pre resId >= 0 * @post $result >= 0.0 */ public double getGridletFinishedSoFar(int resId) { Resource res = null; int size = resList_.size(); for (int i = 0; i < size; i++) { res = (Resource) resList_.get(i); if (resId == res.resourceId) { return res.finishedSoFar; } } return 0.0; } /** * Gets the submission or arrival time of this Gridlet in the * given GridResource ID * @param resId a GridResource entity ID * @return the submission time or <tt>0.0</tt> if not found * @pre resId >= 0 * @post $result >= 0.0 */ public double getSubmissionTime(int resId) { Resource res = null; int size = resList_.size(); for (int i = 0; i < size; i++) { res = (Resource) resList_.get(i); if (resId == res.resourceId) { return res.submissionTime; } } return 0.0; } /** * Gets the time of this Gridlet resides in a given GridResource ID * (from arrival time until departure time). * @param resId a GridResource entity ID * @return the time of this Gridlet resides in the GridResource * or <tt>0.0</tt> if not found * @pre resId >= 0 * @post $result >= 0.0 */ public double getWallClockTime(int resId) { Resource res = null; int size = resList_.size(); for (int i = 0; i < size; i++) { res = (Resource) resList_.get(i); if (resId == res.resourceId) { return res.wallClockTime; } } return 0.0; } /** * Gets the GridResource name based on its ID * @param resId a GridResource entity ID * @return the GridResource name or <tt>null</tt> if not found * @pre resId >= 0 * @post $none */ public String getResourceName(int resId) { Resource res = null; int size = resList_.size(); for (int i = 0; i < size; i++) { res = (Resource) resList_.get(i); if (resId == res.resourceId) { return res.resourceName; } } return null; } /** * Gets the finish time of this Gridlet in a GridResource * @return the finish or completion time of this Gridlet or <tt>-1</tt> if * not finished yet. * @deprecated As of GridSim 2.1, replaced by {@link #getFinishTime()} * @pre $none * @post $result >= -1 */ public double GetFinishTime() { return this.getFinishTime(); } /** * Gets the finish time of this Gridlet in a GridResource * @return the finish or completion time of this Gridlet or <tt>-1</tt> if * not finished yet. * @pre $none * @post $result >= -1 */ public double getFinishTime() { return finishTime_; } ////////////////////////// PROTECTED METHODS ////////////////////////////// /** * Writes this particular history transaction of this Gridlet into a log * @param str a history transaction of this Gridlet * @pre str != null * @post $none */ protected void write(String str) { if (record_ == false) { return; } if (num_ == null || history_ == null) { // Creates the history or transactions of this Gridlet newline_ = System.getProperty("line.separator"); num_ = new DecimalFormat("#0.00#"); // with 3 decimal spaces history_ = new StringBuffer(1000); history_.append("Time below denotes the simulation time."); history_.append( System.getProperty("line.separator") ); history_.append("Time (sec) Description Gridlet #"+gridletID_); history_.append( System.getProperty("line.separator") ); history_.append("------------------------------------------"); history_.append( System.getProperty("line.separator") ); history_.append( num_.format(GridSim.clock()) ); history_.append(" Creates Gridlet ID #" + gridletID_); history_.append( System.getProperty("line.separator") ); } history_.append( num_.format(GridSim.clock()) ); history_.append( " " + str + newline_); }} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -