⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridlet.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    public boolean isFinished()    {        if (index_ == -1) {            return false;        }        boolean completed = false;        // if result is 0 or -ve then this Gridlet has finished        double finish = ( (Resource) resList_.get(index_) ).finishedSoFar;        double result = gridletLength_ - finish;        if (result <= 0.0) {            completed = true;        }        return completed;    }    /**     * Sets the length of this Gridlet that has been executed so far.     * This method is used by ResGridlet class when an application     * is decided to cancel or to move this Gridlet into different     * GridResources.     * @param length    length of this Gridlet     * @see gridsim.AllocPolicy     * @see gridsim.ResGridlet     * @pre length >= 0.0     * @post $none     */    public void setGridletFinishedSoFar(double length)    {        // if length is -ve then ignore        if (length < 0.0 || index_ < 0) {            return;        }        Resource res = (Resource) resList_.get(index_);        res.finishedSoFar = length;        if (record_ == true) {            write("Sets the length's finished so far to " + length);        }    }    /**     * Gets the Gridlet ID     * @return the Gridlet ID     * @deprecated As of GridSim 2.1, replaced by {@link #getGridletID()}     * @pre $none     * @post $result >= 0     */    public int GetGridletID() {        return this.getGridletID();    }    /**     * Gets the Gridlet ID     * @return the Gridlet ID     * @pre $none     * @post $result >= 0     */    public int getGridletID() {        return gridletID_;    }    /**     * Sets the user or owner ID of this Gridlet. It is <tt>VERY</tt> important     * to set the user ID, otherwise this Gridlet will not be executed in a     * GridResource.     * @param id  the user ID     * @deprecated As of GridSim 2.1, replaced by {@link #setUserID(int)}     * @pre id >= 0     * @post $none     */    public void SetUserID(int id) {        this.setUserID(id);    }    /**     * Sets the user or owner ID of this Gridlet. It is <tt>VERY</tt> important     * to set the user ID, otherwise this Gridlet will not be executed in a     * GridResource.     * @param id  the user ID     * @pre id >= 0     * @post $none     */    public void setUserID(int id)    {        userID_ = id;        if (record_ == true)        {            write("Assigns the Gridlet to " + GridSim.getEntityName(id) +                  " (ID #" + id + ")");        }    }    /**     * Gets the user or owner ID of this Gridlet     * @return the user ID or <tt>-1</tt> if the user ID has not been set before     * @deprecated As of GridSim 2.1, replaced by {@link #getUserID()}     * @pre $none     * @post $result >= -1     */    public int GetUserID() {        return this.getUserID();    }    /**     * Gets the user or owner ID of this Gridlet     * @return the user ID or <tt>-1</tt> if the user ID has not been set before     * @pre $none     * @post $result >= -1     */    public int getUserID() {        return userID_;    }    /**     * Gets the latest resource ID that processes this Gridlet     * @return the resource ID or <tt>-1</tt> if none     * @deprecated As of GridSim 2.1, replaced by {@link #getResourceID()}     * @pre $none     * @post $result >= -1     */    public int GetResourceID() {        return this.getResourceID();    }    /**     * Gets the latest resource ID that processes this Gridlet     * @return the resource ID or <tt>-1</tt> if none     * @pre $none     * @post $result >= -1     */    public int getResourceID()    {        if (index_ == -1) {            return -1;        }        return ( (Resource) resList_.get(index_) ).resourceId;    }    /**     * Gets the input file size of this Gridlet <tt>BEFORE</tt>     * submitting to a GridResource     * @return the input file size of this Gridlet     * @deprecated As of GridSim 2.1, replaced by {@link #getGridletFileSize()}     * @pre $none     * @post $result >= 1     */    public long GetGridletFileSize() {        return this.getGridletFileSize();    }    /**     * Gets the input file size of this Gridlet <tt>BEFORE</tt>     * submitting to a GridResource     * @return the input file size of this Gridlet     * @pre $none     * @post $result >= 1     */    public long getGridletFileSize() {        return gridletFileSize_;    }    /**     * Gets the output size of this Gridlet <tt>AFTER</tt> submitting and     * executing to a GridResource     * @return the Gridlet output file size     * @deprecated As of GridSim 2.1, replaced by     *             {@link #getGridletOutputSize()}     * @pre $none     * @post $result >= 1     */    public long GetGridletOutputSize() {        return this.getGridletOutputSize();    }    /**     * Gets the output size of this Gridlet <tt>AFTER</tt> submitting and     * executing to a GridResource     * @return the Gridlet output file size     * @pre $none     * @post $result >= 1     */    public long getGridletOutputSize() {        return gridletOutputSize_;    }    /**     * Sets the resource parameters for which this Gridlet is going to be     * executed. <br>     * NOTE: This method <tt>should</tt> be called only by a resource entity,     * not the user or owner of this Gridlet.     * @param resourceID   the GridResource ID     * @param costPerSec   the cost running this GridResource per second     * @deprecated As of GridSim 2.1, replaced by     *             {@link #setResourceParameter(int, double)}     * @pre resourceID >= 0     * @pre costPerSec > 0.0     * @post $none     */    public void SetResParam(int resourceID, double costPerSec) {        this.setResourceParameter(resourceID, costPerSec);    }    /**     * Sets the resource parameters for which this Gridlet is going to be     * executed. <br>     * NOTE: This method <tt>should</tt> be called only by a resource entity,     * not the user or owner of this Gridlet.     * @param resourceID   the GridResource ID     * @param cost   the cost running this GridResource per second     * @pre resourceID >= 0     * @pre cost > 0.0     * @post $none     */    public void setResourceParameter(int resourceID, double cost)    {        Resource res = new Resource();        res.resourceId = resourceID;        res.costPerSec = cost;        res.resourceName = GridSim.getEntityName(resourceID);        // add into a list if moving to a new grid resource        resList_.add(res);        if (index_ == -1 && record_ == true)        {            write("Allocates this Gridlet to " + res.resourceName +                  " (ID #" + resourceID + ") with cost = $" + cost + "/sec");        }        else if (record_ == true)        {            int id = ( (Resource) resList_.get(index_) ).resourceId;            String name = ( (Resource) resList_.get(index_) ).resourceName;            write("Moves Gridlet from " + name + " (ID #" + id + ") to " +                  res.resourceName + " (ID #" + resourceID +                  ") with cost = $" + cost + "/sec");        }        index_++;  // initially, index_ = -1    }    /**     * Sets the submission or arrival time of this Gridlet into a GridResource     * @param clockTime     the submission time     * @deprecated As of GridSim 2.1, replaced by     *             {@link #setSubmissionTime(double)}     * @pre clockTime >= 0.0     * @post $none     */    public void SetSubmissionTime(double clockTime) {        this.setSubmissionTime(clockTime);    }    /**     * Sets the submission or arrival time of this Gridlet into a GridResource     * @param clockTime     the submission time     * @pre clockTime >= 0.0     * @post $none     */    public void setSubmissionTime(double clockTime)    {        if (clockTime < 0.0 || index_ < 0) {            return;        }        Resource res = (Resource) resList_.get(index_);        res.submissionTime = clockTime;        if (record_ == true) {            write( "Sets the submission time to " + num_.format(clockTime) );        }    }    /**     * Gets the submission or arrival time of this Gridlet from     * the latest GridResource     * @return the submission time or <tt>0.0</tt> if none     * @pre $none     * @post $result >= 0.0     */    public double getSubmissionTime()    {        if (index_ == -1) {            return 0.0;        }        return ( (Resource) resList_.get(index_) ).submissionTime;    }    /**     * Sets the execution start time of this Gridlet inside a GridResource.     * <b>NOTE:</b> With new functionalities, such as being able to cancel /     * to pause / to resume this Gridlet, the execution start time only holds     * the latest one. Meaning, all previous execution start time are ignored.     *     * @param clockTime     the latest execution start time     * @deprecated As of GridSim 2.1, replaced by     *             {@link #setExecStartTime(double)}     * @pre clockTime >= 0.0     * @post $none     */    public void SetExecStartTime(double clockTime) {        this.setExecStartTime(clockTime);    }    /**     * Sets the execution start time of this Gridlet inside a GridResource.     * <b>NOTE:</b> With new functionalities, such as being able to cancel /     * to pause / to resume this Gridlet, the execution start time only holds     * the latest one. Meaning, all previous execution start time are ignored.     *     * @param clockTime     the latest execution start time     * @pre clockTime >= 0.0     * @post $none     */    public void setExecStartTime(double clockTime)    {        execStartTime_ = clockTime;        if (record_ == true) {            write("Sets the execution start time to " + num_.format(clockTime));        }    }    /**     * Gets the latest execution start time     * @return the latest execution start time     * @pre $none     * @post $result >= 0.0     */    public double getExecStartTime() {        return execStartTime_;    }    /**     * 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.     *     * @deprecated As of GridSim 2.1, replaced by     *             {@link #setExecParam(double, double)}     * @pre wallClockTime >= 0.0     * @pre actualCPUTime >= 0.0     * @post $none     */    public void SetExecParam(double wallClockTime, double actualCPUTime) {        this.setExecParam(wallClockTime, actualCPUTime);    }    /**     * 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 wallTime    the time of this Gridlet resides in     *                         a GridResource (from arrival time until     *                         departure time).     * @param actualTime    the total execution time of this Gridlet in a     *                         GridResource.     *     * @pre wallTime >= 0.0     * @pre actualTime >= 0.0     * @post $none     */    public void setExecParam(double wallTime, double actualTime)    {        if (wallTime < 0.0 || actualTime < 0.0 || index_ < 0) {            return;        }        Resource res = (Resource) resList_.get(index_);        res.wallClockTime = wallTime;        res.actualCPUTime = actualTime;        if (record_ == true)        {            write("Sets the wall clock time to "+ num_.format(wallTime)+                  " and the actual CPU time to " + num_.format(actualTime));        }    }    /**     * Sets the status code of this Gridlet     * @param status    the status code of this Gridlet     * @deprecated As of GridSim 2.1, replaced by {@link #setGridletStatus(int)}     * @throws Exception Invalid Gridlet status     * @pre status >= 0 && status <= 5     * @post $none     */    public void SetStatus(int status) throws Exception {        this.setGridletStatus(status);    }    /**     * Sets the status code of this Gridlet     * @param newStatus    the status code of this Gridlet     * @throws Exception   Invalid range of Gridlet status     * @pre newStatus >= 0 && newStatus <= 8     * @post $none     */    public void setGridletStatus(int newStatus) throws Exception    {        // if the new status is same as current one, then ignore the rest        if (status_ == newStatus) {            return;        }        // throws an exception if the new status is outside the range        if (newStatus < Gridlet.CREATED || newStatus > Gridlet.RESUMED)        {            throw new Exception("Gridlet.setGridletStatus() : Error - " +                    "Invalid integer range for Gridlet status.");        }        if (newStatus == Gridlet.SUCCESS) {            finishTime_ = GridSim.clock();        }        if (record_ == true)        {            String obj = "Sets Gridlet status from " + getGridletStatusString();            write( obj + " to " + Gridlet.getStatusString(newStatus) );        }        this.status_ = newStatus;    }    /**     * Gets the status code of this Gridlet     * @return the status code of this Gridlet     * @deprecated As of GridSim 2.1, replaced by {@link #getGridletStatus()}     * @pre $none     * @post $result >= 0     */    public int GetStatus() {        return this.getGridletStatus();    }    /**     * Gets the status code of this Gridlet     * @return the status code of this Gridlet     * @pre $none     * @post $result >= 0     */    public int getGridletStatus() {        return status_;    }    /**     * 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     * @deprecated As of GridSim 2.1, replaced by     *             {@link #getGridletStatusString()}     * @pre $none

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -