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

📄 allocpolicy.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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: AllocPolicy.java,v 1.44 2006/03/09 05:56:31 anthony Exp $ */package gridsim;import java.util.Calendar;import java.util.Iterator;import java.util.Collection;import gridsim.*;import eduni.simjava.Sim_port;import eduni.simjava.Sim_entity;import eduni.simjava.Sim_event;/** * AllocPolicy is an abstract class that handles the internal * {@link gridsim.GridResource} * allocation policy. New scheduling algorithms can be added into a GridResource * entity by extending this class and implement the required abstract methods. * <p> * All the implementation details and the data structures chosen are up to * the child class. All the protected methods and attributes are available * to code things easier. * <p> * Since GridSim 3.0, scheduling algorithm or allocation policy that requires * Advanced Reservation functionalities need to extend from * {@link gridsim.ARPolicy} class instead. * * @author       Manzur Murshed and Rajkumar Buyya * @author       Anthony Sulistio (re-written this class) * @since        GridSim Toolkit 2.2 * @see gridsim.ARPolicy * @see gridsim.GridSim * @see gridsim.ResourceCharacteristics * @invariant $none */public abstract class AllocPolicy extends Sim_entity{    /** The GridResource characteristics object, same as the one in     * GridResource class     */    protected ResourceCharacteristics resource_;    /** The GridResource Calendar, same as the one in     * GridResource class     */    protected ResourceCalendar resCalendar_;    /** The GridResource output port. This port is mainly used to send     * Gridlets or any other messages by this Allocation Policy class.     * This is because an Allocation Policy class doesn't have networked     * entities (Input and Output).     */    protected Sim_port outputPort_;    /** The total number of PEs that this resource has. */    protected int totalPE_;    /** This GridResource ID */    protected int resId_;    /** This class entity ID */    protected final int myId_;    /** This GridResource name */    protected final String resName_;    /** Initial simulation time as given in <tt>GridSim.init().     * @see gridsim.GridSim#init(int, Calendar, boolean)     * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[],     *      String)     */    protected long initTime_;    // for statistical purposes to determine the load of this scheduler    private Accumulator accTotalLoad_;    private boolean endSimulation_;  // denotes the end of simulation    private final int ARRAY_SIZE = 2;  // [0] = gridlet id and [1] = result    ///////////////////// ABSTRACT METHODS /////////////////////////////    /**     * An <tt>abstract</tt> method that schedules a new Gridlet     * received by a GridResource entity.     * <p>     * For a Gridlet that requires many Processing Elements (PEs) or CPUs,     * the gridlet length is calculated only for 1 PE. <br>     * For example, a Gridlet has a length of 500 MI and requires 2 PEs.     * This means each PE will execute 500 MI of this job.     * If this scheduler can only execute 1 Gridlet per PE, then it is up     * to the scheduler to either double the gridlet length up to 1,000 MI     * or to leave the length as it is.     * <p>     * In the beginning of this code, a <tt>ResGridlet</tt> object should be     * created. The <tt>ResGridlet</tt> object is very useful since it keeps     * track of related time information during execution of this Gridlet.     * <p>     * If an acknowledgement is required, then at the end of this method,     * should include the following code:     * <code>     * <br><br>     * ... // other code <br> <br>     * // sends back an ack if required <br>     * boolean success = true; // If this method success, false otherwise <br>     * if (ack == true) { <br>     * &nbsp;&nbsp;&nbsp;&nbsp;sendAck(GridSimTags.GRIDLET_SUBMIT_ACK,     *        success, gl.getGridletID(), gl.getUserID() ); <br>     * } <br>     * <br>     * </code>     * @param   gl    a Gridlet object that is going to be executed     * @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)     * @see gridsim.ResGridlet     * @see gridsim.ResGridletList     * @pre gl != null     * @post $none     */    public abstract void gridletSubmit(Gridlet gl, boolean ack);    /**     * An <tt>abstract</tt> method that cancels a Gridlet in an execution list.     * When writing this code, there are few things to consider:     * <ul>     *     <li> if a Gridlet can't be found in any data structures     *     <li> if a Gridlet has finished executing upon canceling     *     <li> if a Gridlet can be canceled     * </ul>     * <p>     * This method is always required to send back the Gridlet to sender.     * If the Gridlet is not found, then send back a <tt>null</tt> Gridlet.     * Therefore, at the end of this method, should include the following     * code:     * <code>     * <br><br>     * ... // other code <br> <br>     * // A ResGridlet object stored in a container or other data structure<br>     * // before exit, finalize all the Gridlet's relevant time information<br>     * resGridlet.finalizeGridlet(); <br>     * <br>     * // sends the Gridlet back to sender <br>     * // Here, <tt>gridlet</tt> can be <tt>null</tt> if not found <br>     * Gridlet gridlet = resGridlet.getGridlet(); <br>     * sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, gridlet,     *                          gridletId, userId);     *     * <br>     * </code>     * @param gridletId    a Gridlet ID     * @param userId       the user or owner's ID of this Gridlet     * @pre gridletId > 0     * @pre userId > 0     * @post $none     */    public abstract void gridletCancel(int gridletId, int userId);    /**     * An <tt>abstract</tt> method that pauses a Gridlet during an execution.     * <p>     * If an acknowledgement is required, then at the end of this method,     * should include the following code:     * <code>     * <br><br>     * ... // other code <br> <br>     * // sends back an ack if required <br>     * boolean success = true; // If this method success, false otherwise <br>     * if (ack == true) { <br>     * &nbsp;&nbsp;&nbsp;&nbsp;sendAck(GridSimTags.GRIDLET_PAUSE_ACK,     *        success, gl.getGridletID(), gl.getUserID() ); <br>     * } <br>     * <br>     * </code>     *     * @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 abstract void gridletPause(int gridletId, int userId, boolean ack);    /**     * An <tt>abstract</tt> method that resumes a previously paused Gridlet.     * <p>     * If an acknowledgement is required, then at the end of this method,     * should include the following code:     * <code>     * <br><br>     * ... // other code <br> <br>     * // sends back an ack if required <br>     * boolean success = true; // If this method success, false otherwise <br>     * if (ack == true) { <br>     * &nbsp;&nbsp;&nbsp;&nbsp;sendAck(GridSimTags.GRIDLET_RESUME_ACK,     *        success, gl.getGridletID(), gl.getUserID() ); <br>     * } <br>     * <br>     * </code>     *     * @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 abstract void gridletResume(int gridletId, int userId, boolean ack);    /**     * An <tt>abstract</tt> method that finds the status of a Gridlet.     * This method doesn't need to send back anything since it will     * automatically handle by GridResource class once the status is found.     * @param gridletId    a Gridlet ID     * @param userId       the user or owner's ID of this Gridlet     * @return the Gridlet status or <tt>-1</tt> if not found     * @see gridsim.Gridlet     * @pre gridletId > 0     * @pre userId > 0     * @post $none     */    public abstract int gridletStatus(int gridletId, int userId);    /**     * An <tt>abstract</tt> method that moves a Gridlet to another     * GridResource entity.     * When writing this code, there are few things to consider:     * <ul>     *     <li> if a Gridlet can't be found in any data structures. <br>     *          Hence, only need to send an ack with a <tt>false</tt>     *          boolean value by using     *          {@link #sendAck(int, boolean, int, int)}.<br><br>     *     *     <li> if a Gridlet has finished executing upon moving. <br>     *          Then need to send an ack with a <tt>false</tt>     *          boolean value by using     *          {@link #sendAck(int, boolean, int, int)}. <br>     *          Moreover, need to send the completed Gridlet by using     *          {@link #sendFinishGridlet(Gridlet)}.<br><br>     *     *     <li> if a Gridlet can be moved, then need to use     *          {@link #gridletMigrate(Gridlet, int, boolean)}.     * </ul>     *     *     * @param gridletId    a Gridlet ID     * @param userId       the user or owner's ID of this Gridlet     * @param destId       a new destination GridResource ID for 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     * @pre destId > 0     * @post $none     */    public abstract void gridletMove(int gridletId, int userId, int destId,                                     boolean ack);    ///////////////////// End of Abstract methods ///////////////////////////    /**     * Overrides this method when executing or scheduling newly-defined tags.     * This method is called by     * {@link gridsim.GridResource#processOtherEvent(Sim_event)}     * for an event with an unknown tag.     * This approach is desirable if you do not want to create a new type of     * grid resource.     *     * @param ev    a Sim_event object     * @pre ev != null     * @post $none     */    public void processOtherEvent(Sim_event ev)    {        if (ev == null)        {            System.out.println(resName_ + ".processOtherEvent(): " +                    "Error - an event is null.");            return;        }        System.out.println(resName_ + ".processOtherEvent(): Unable to " +                "handle request from an event with a tag number " +                ev.get_tag() );    }    /**     * Gets the total load for this GridResource     * @return an Accumulator object     * @pre $none     * @post $result != null     */    public Accumulator getTotalLoad() {        return accTotalLoad_;    }    /**     * Sets the end of simulation for this entity. Normally, the GridResource     * entity will set this flag.     * @pre $none     * @post $none     */    public void setEndSimulation() {        endSimulation_ = true;    }    /**     * Checks whether it is the end of a simulation or not     * @return <tt>true</tt> if it is the end of a simulation, <tt>false</tt>     *         otherwise     * @pre $none     * @post $none     */    protected boolean isEndSimulation() {        return endSimulation_;    }    /**     * Initializes all important attributes.  Normally, the GridResource     * entity will call this method upon its constructor.     * @param res   a ResourceCharacteristics object     * @param cal   a ResourceCalendar object     * @param port  a Sim_port object     * @pre res != null     * @pre cal != null     * @pre port != null     * @post $none     */    public void init(ResourceCharacteristics res, ResourceCalendar cal,                     Sim_port port)    {        // default values        resource_ = res;        resCalendar_ = cal;        outputPort_ = port;        totalPE_ = resource_.getNumPE();        resId_ = resource_.getResourceID();        double load = calculateTotalLoad(0);        accTotalLoad_.add(load);        // looking at the init simulation time        Calendar calendar = GridSim.getSimulationCalendar();        long simTime = calendar.getTimeInMillis();

⌨️ 快捷键说明

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