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

📄 .#gridlet.java.1.31

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 31
📖 第 1 页 / 共 3 页
字号:
/* * 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: Gridlet.java,v 1.31 2005/06/21 09:10:23 anthony Exp $ */package gridsim;import java.util.*;import java.text.DecimalFormat;/** * A Gridlet is a package that contains all the information related to the job * and its execution management details such as job length expressed in MI * (Millions Instruction), the size of input and output * files, and the job owner id. * Individual users model their application by creating Gridlets for * processing them on Grid resources. * <p> * These basic parameters help in determining * execution time, the time required to transport input and output files between * users and remote resources, and returning the processed Gridlets back to the * originator along with the results. * <p> * For a Gridlet that requires many Processing Elements (PEs) or CPUs, * the gridlet length is calculated only for 1 PE for simplicity.<br> * For example, this Gridlet has a length of 500 MI and requires 2 PEs. * This means each PE will execute 500 MI of this Gridlet. * <p> * From GridSim 3.1, we have also added a classType attribute which can be * used to provide differentiated service to scheduling gridlets on a resource. * The higher the classType means the higher the priority of scheduling this * Gridlet on the resource. * However, it is up to the resource's allocation policy to schedule gridlets * based on their priority or not. * * @author       Manzur Murshed and Rajkumar Buyya * @since        GridSim Toolkit 1.0 * @invariant $none */public class Gridlet{    // the User or Broker ID. It is advisable that broker set this ID    // with its own ID, so that GridResource returns to it after the execution    private int userID_;    // the size of this Gridlet to be executed in a GridResource (unit: in MI)    private double gridletLength_;    // the input file size of this Gridlet before execution (unit: in byte)    private long gridletFileSize_;   // in byte = program + input data size    // the output file size of this Gridlet after execution (unit: in byte)    private long gridletOutputSize_;    private int numPE_;              // num of PE required to execute this job    private int gridletID_;          // this Gridlet ID    private int status_;             // status of this Gridlet    private DecimalFormat num_;      // to format the decimal number    private double finishTime_;      // the time where this Gridlet completes    // start time of executing this Gridlet.    // With new functionalities, such as CANCEL, PAUSED and RESUMED, this    // attribute only stores the latest execution time. Previous execution time    // are ignored.    private double execStartTime_;   // in simulation time    // records the transaction history for this Gridlet    private boolean record_;         // record a history or not    private String newline_;    private StringBuffer history_;    private ArrayList resList_;    private int index_;    // differentiated service    private int classType_;    // class type of Gridlet for resource scheduling    private int netToS_;       // ToS for sending Gridlet over the network    ////////////////////////////////////////////    // Below are CONSTANTS attributes    /** The Gridlet has been created and added to the GridletList object */    public static final int CREATED = 0;    /** The Gridlet has been assigned to a GridResource object as planned */    public static final int READY = 1;    /** The Gridlet has moved to a Grid node */    public static final int QUEUED = 2;    /** The Gridlet is in execution in a Grid node */    public static final int INEXEC = 3;    /** The Gridlet has been executed successfully */    public static final int SUCCESS = 4;    /** The Gridlet is failed */    public static final int FAILED = 5;    /** The Gridlet has been canceled.  */    public static final int CANCELED = 6;    /** The Gridlet has been paused. It can be resumed by changing the status     * into <tt>RESUMED</tt>.     */    public static final int PAUSED = 7;    /** The Gridlet has been resumed from <tt>PAUSED</tt> state. */    public static final int RESUMED = 8;    /////////////////////////////////////////////////////////////    /**     * Allocates a new Gridlet object. The Gridlet length, input and output     * file sizes should be greater than or equal to 1.     * By default, this constructor records the history of this object.     *     * @param gridletID            the unique ID of this Gridlet     * @param gridletLength        the length or size (in MI) of this Gridlet     *                             to be executed in a GridResource     * @param gridletFileSize      the file size (in byte) of this Gridlet     *                             <tt>BEFORE</tt> submitting to a GridResource     * @param gridletOutputSize    the file size (in byte) of this Gridlet     *                             <tt>AFTER</tt> finish executing by     *                             a GridResource     * @param classType            Sets the class type or priority of this     *                             gridlet for scheduling on a resource.     * @pre gridletID >= 0     * @pre gridletLength >= 0.0     * @pre gridletFileSize >= 1     * @pre gridletOutputSize >= 1     * @post $none     */    public Gridlet(int gridletID, double gridletLength,                long gridletFileSize, long gridletOutputSize, int classType)    {        this(gridletID,gridletLength,gridletFileSize,gridletOutputSize,true);        this.classType_ = classType;    }    /**     * Allocates a new Gridlet object. The Gridlet length, input and output     * file sizes should be greater than or equal to 1.     *     * @param gridletID            the unique ID of this Gridlet     * @param gridletLength        the length or size (in MI) of this Gridlet     *                             to be executed in a GridResource     * @param gridletFileSize      the file size (in byte) of this Gridlet     *                             <tt>BEFORE</tt> submitting to a GridResource     * @param gridletOutputSize    the file size (in byte) of this Gridlet     *                             <tt>AFTER</tt> finish executing by     *                             a GridResource     * @param record               record the history of this object or not     * @pre gridletID >= 0     * @pre gridletLength >= 0.0     * @pre gridletFileSize >= 1     * @pre gridletOutputSize >= 1     * @post $none     */    public Gridlet(int gridletID, double gridletLength,                long gridletFileSize, long gridletOutputSize, boolean record)    {        this.userID_ = -1;          // to be set by a Broker or user        this.status_ = CREATED;        this.gridletID_ = gridletID;        this.numPE_ = 1;        this.execStartTime_ = 0.0;        this.finishTime_ = -1.0;    // meaning this Gridlet hasn't finished yet        this.classType_ = 0;        this.netToS_ = 0;        // Gridlet length, Input and Output size should be at least 1 byte.        this.gridletLength_ = Math.max(1, gridletLength);        this.gridletFileSize_ = Math.max(1, gridletFileSize);        this.gridletOutputSize_ = Math.max(1, gridletOutputSize);        // Normally, a Gridlet is only executed on a resource without being        // migrated to others. Hence, to reduce memory consumption, set the        // size of this ArrayList to be less than the default one.        this.resList_ = new ArrayList(2);        this.index_ = -1;        this.record_ = record;        // history will be created later        this.num_ = null;        this.history_ = null;        this.newline_ = null;    }    /**     * Allocates a new Gridlet object. The Gridlet length, input and output     * file sizes should be greater than or equal to 1.     * By default this constructor sets the history of this object.     *     * @param gridletID            the unique ID of this Gridlet     * @param gridletLength        the length or size (in MI) of this Gridlet     *                             to be executed in a GridResource     * @param gridletFileSize      the file size (in byte) of this Gridlet     *                             <tt>BEFORE</tt> submitting to a GridResource     * @param gridletOutputSize    the file size (in byte) of this Gridlet     *                             <tt>AFTER</tt> finish executing by     *                             a GridResource     * @pre gridletID >= 0     * @pre gridletLength >= 0.0     * @pre gridletFileSize >= 1     * @pre gridletOutputSize >= 1     * @post $none     */    public Gridlet(int gridletID, double gridletLength,                long gridletFileSize, long gridletOutputSize)    {        this(gridletID, gridletLength, gridletFileSize, gridletOutputSize, 0);        this.record_ = true;    }    //////////////////////// INTERNAL CLASS ///////////////////////////////////    /**     * Internal class that keeps track Gridlet's movement in different     * GridResources     */    private class Resource    {        /** Gridlet's submission time to a GridResource */        public double submissionTime;        /** The time of this Gridlet resides in a GridResource         * (from arrival time until departure time).         */        public double wallClockTime;        /** The total execution time of this Gridlet in a GridResource. */        public double actualCPUTime;        /** Cost per second a GridResource charge to execute this Gridlet */        public double costPerSec;        /** Gridlet's length finished so far */        public double finishedSoFar;        /** a GridResource id */        public int resourceId;        /** a GridResource name */        public String resourceName;        /**         * Empty Constructor with default attributes' value         * @pre $none         * @post $none         */        public Resource()        {            submissionTime = 0.0;            wallClockTime = 0.0;            actualCPUTime = 0.0;            costPerSec = 0.0;            finishedSoFar = 0.0;            resourceId = -1;            resourceName = null;        }    } // end of internal class    //////////////////////// End of Internal Class //////////////////////////    /**     * Sets the length or size (in MI) of this Gridlet     * to be executed in a GridResource.     * This Gridlet length is calculated for 1 PE only <tt>not</tt> the total     * length.     *     * @param gridletLength     the length or size (in MI) of this Gridlet     *                          to be executed in a GridResource     * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise     * @pre gridletLength > 0     * @post $none     */    public boolean setGridletLength(double gridletLength)    {        if (gridletLength <= 0) {            return false;        }        gridletLength_ = gridletLength;        return true;    }    /**     * Sets the network service level for sending this gridlet over a network     * @param netServiceLevel   determines the kind of service this gridlet     *                          receives in the network (applicable to     *                          selected PacketScheduler class only)     * @pre netServiceLevel >= 0     * @post $none     */    public boolean setNetServiceLevel(int netServiceLevel)    {        boolean success = false;        if (netServiceLevel > 0)        {            netToS_ = netServiceLevel;            success = true;        }        return success;    }    /**     * Gets the network service level for sending this gridlet over a network     * @return the network service level     * @pre $none     * @post $none     */    public int getNetServiceLevel() {        return netToS_;    }    /**     * Gets the waiting time of this gridlet executed on a resource     * @return the waiting time     * @pre $none     * @post $none     */    public double getWaitingTime()    {        if (index_ == -1) {            return 0;        }        // use the latest resource submission time        double subTime = ((Resource) resList_.get(index_)).submissionTime;        return execStartTime_ - subTime;    }    /**     * Sets the classType or priority of this Gridlet for scheduling on a     * resource.     * @param classType classType of this Gridlet     * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise     * @pre classType > 0     * @post $none     */    public boolean setClassType(int classType)    {        boolean success = false;        if (classType > 0)        {            this.classType_ = classType;            success = true;        }        return success;    }    /**     * Gets the classtype or priority of this Gridlet for scheduling on a     * resource.     * @return classtype of this gridlet     * @pre $none     * @post $none     */    public int getClassType() {        return classType_;    }    /**     * Sets the number of PEs required to run this Gridlet. <br>     * NOTE: The Gridlet length is computed for 1 PE only for simplicity.     * For example, this Gridlet has a length of 500 MI and requires 2 PEs.     * This means each PE will execute 500 MI of this Gridlet.     *     * @param numPE     number of PE     * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise     * @pre numPE > 0     * @post $none     */    public boolean setNumPE(int numPE)    {        boolean success = false;        if (numPE > 0)        {            numPE_ = numPE;            success = true;        }        return success;    }    /**     * Gets the number of PEs required to run this Gridlet     * @return number of PEs     * @pre $none     * @post $none     */    public int getNumPE() {        return numPE_;    }    /**     * Gets the history of this Gridlet. The layout of this history is in a     * readable table column with <tt>time</tt> and <tt>description</tt>     * as headers.     * @return a String containing the history of this Gridlet object.     * @pre $none     * @post $result != null     */    public String getGridletHistory()    {        String msg = null;        if (history_ == null) {            msg = "No history is recorded for Gridlet #" + gridletID_;        }        else {            msg = history_.toString();        }        return msg;    }    /**     * Gets the length of this Gridlet that has been executed so far     * from the latest GridResource. This     * method is useful when trying to move this Gridlet into different     * GridResources or to cancel it.     * @return the length of a partially executed Gridlet or the full Gridlet     *         length if it is completed     * @pre $none     * @post $result >= 0.0     */    public double getGridletFinishedSoFar()    {        if (index_ == -1) {            return gridletLength_;        }        double finish = ( (Resource) resList_.get(index_) ).finishedSoFar;        if (finish > gridletLength_) {            return gridletLength_;        }        return finish;    }    /**     * Checks whether this Gridlet has finished execution or not     * @return <tt>true</tt> if this Gridlet has finished execution,     *         <tt>false</tt> otherwise     * @pre $none     * @post $none     */    public boolean isFinished()    {        if (index_ == -1) {            return false;

⌨️ 快捷键说明

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