arpolicy.java

来自「一个非常著名的网格模拟器,能够运行网格调度算法!」· Java 代码 · 共 603 行 · 第 1/2 页

JAVA
603
字号
/* * 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: ARPolicy.java,v 1.18 2005/10/21 12:29:09 anthony Exp $ */package gridsim;import java.util.Calendar;import java.util.ArrayList;import java.util.TimeZone;import java.util.Iterator;import java.util.Collection;/** * ARPolicy is an abstract class that handles the internal * {@link gridsim.GridResource} * allocation policy related to Advanced Reservation functionalities. * New scheduling algorithms can be added into a GridResource * entity by extending this class and implement the required abstract methods. * {@link gridsim.AllocPolicy} abstract methods are also need to be * implemented. * <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. Child classes should use * <tt>replyXXXReservation()</tt> methods * where <i>XXX = Cancel / Commit / Query / Time / Create</i>. This is because * these methods send a correct format or message to * {@link gridsim.AdvanceReservation} * class. Sending an incorrect message will caused an exception on the * receiver's side. * * @author       Anthony Sulistio * @since        GridSim Toolkit 3.0 * @see gridsim.GridSim * @see gridsim.ResourceCharacteristics * @see gridsim.AdvanceReservation * @see gridsim.AllocPolicy * @invariant $none */public abstract class ARPolicy extends AllocPolicy{    /** A constant variable that represents 1 second in 1,000 milliseconds. */    protected final int MILLI_SEC = 1000;      // 1 sec = 1,000 milli seconds    private final int MAX = 2;   // max. array size    private final int SIZE = 12;  // int = 4 bytes + overhead = 8 bytes    private final int TAG_SIZE = 6;    private final int[] timeArray_ = {1, 5, 10, 15, 30, 45};  // time interval    private int[] tagArray_;    ///////////////////// ABSTRACT METHODS ////////////////////////////////    /**     * An abstract method that handles a new immediate reservation request.     * {@link #replyCreateReservation(int, int, long, int)} method should be     * used to send a result back to sender or user.     * <p>     * An immediate reservation requests a reservation immediately, i.e.     * the current time is used as the start time with/without specifying     * duration or end time. <br>     * Immediate reservation can be done by one of the following ways:     * <ol>     * <li> <tt>start time = 0 (in long)</tt> and <tt>duration > 0</tt>.<br>     *      If successful, expiry time should be set like this:     *      <tt>expiry time = current time + duration.</tt>     *      <br><br>     * <li> <tt>start time = 0 (in long)</tt> and <tt>duration = 0</tt>.<br>     *      This means a reservation is running as long as there are empty     *      PEs available. <br> <b>NOTE:</b> using this approach, a reservation     *      is having a risk of being pre-empted or terminated by a     *      resource scheduler when new AR requests come. In addition,     *      due to complexity, a resource's scheduler might not support     *      this method. Finally, <tt>expiry time = 0</tt> since a scheduler     *      can not determine it. <br>     * </ol>     * @param obj   a reservation object     * @param senderID  a sender or user ID     * @param sendTag   a tag to send to the user     * @pre obj != null     * @pre senderID > 0     * @post $none     */    public abstract void handleImmediateReservation(ARObject obj,                                                 int senderID, int sendTag);    /**     * An abstract method that handles a new advanced reservation request.     * {@link #replyCreateReservation(int, int, long, int)} method should be     * used to send a result back to sender or user.     * @param obj   a reservation object     * @param senderID  a sender or user ID     * @param sendTag   a tag to send to the user     * @pre obj != null     * @pre senderID > 0     * @post $none     */    public abstract void handleCreateReservation(ARObject obj,                                                 int senderID, int sendTag);    /**     * An abstract method that handles a modify reservation request.     * {@link #replyModifyReservation(int, int, int)} method should be used     * to send a result back to sender or user.     * @param obj  a reservation object     * @param senderID   a sender or user ID     * @param sendTag    a tag to send to the user     * @pre obj != null     * @pre senderID > 0     * @post $none     */    public abstract void handleModifyReservation(ARObject obj,                                                 int senderID, int sendTag);    /**     * An abstract method that handles a cancel reservation request.     * This method cancels only for a particular Gridlet.     * {@link #replyCancelReservation(int, int, int)} method should be used     * to send a result back to sender or user.     * @param reservationID   a reservation ID     * @param senderID        a sender or user ID     * @param gridletID       a gridlet ID     * @param sendTag         a tag to send to the user     * @pre reservationID > 0     * @pre senderID > 0     * @post $none     */    public abstract void handleCancelReservation(int reservationID,                                 int senderID, int gridletID, int sendTag);    /**     * An abstract method that handles a cancel reservation request.     * This method cancels a list of Gridlet IDs.     * {@link #replyCancelReservation(int, int, int)} method should be used     * to send a result back to sender or user.     * @param reservationID   a reservation ID     * @param senderID        a sender or user ID     * @param list            a list of Gridlet IDs (each ID is represented as     *                        an Integer object)     * @param sendTag         a tag to send to the user     * @pre reservationID > 0     * @pre senderID > 0     * @pre list != null     * @post $none     */    public abstract void handleCancelReservation(int reservationID,                                 int senderID, ArrayList list, int sendTag);    /**     * An abstract method that handles a cancel reservation request.     * This method cancels all Gridlets for a given reservation ID.     * {@link #replyCancelReservation(int, int, int)} method should be used     * to send a result back to sender or user.     * @param reservationID   a reservation ID     * @param senderID        a sender or user ID     * @param sendTag         a tag to send to the user     * @pre reservationID > 0     * @pre senderID > 0     * @post $none     */    public abstract void handleCancelReservation(int reservationID,                                 int senderID, int sendTag);    /**     * An abstract method that handles a commit reservation request.     * This method commits a reservation only. Gridlets are submitted using     * {@link #handleCommitReservation(int, int, int, Gridlet)} or     * {@link #handleCommitReservation(int, int, int, GridletList)} method.<br>     * {@link #replyCommitReservation(int, int, int)} method should be used     * to send a result back to sender or user.     * @param reservationID  a reservation ID     * @param senderID       a sender or user ID     * @param sendTag        a tag to send to the user     * @pre reservationID > 0     * @pre senderID > 0     * @post $none     */    public abstract void handleCommitOnly(int reservationID,                                 int senderID, int sendTag);    /**     * An abstract method that handles a commit reservation request.     * This method commits a reservation and submits a Gridlet to be processed     * as well.     * {@link #replyCommitReservation(int, int, int)} method should be     * used to send a result back to sender or user.     * @param reservationID  a reservation ID     * @param senderID       a sender or user ID     * @param sendTag        a tag to send to the user     * @param gridlet        a Gridlet object     * @pre reservationID > 0     * @pre senderID > 0     * @pre gridlet != null     * @post $none     */    public abstract void handleCommitReservation(int reservationID,                                 int senderID, int sendTag, Gridlet gridlet);    /**     * An abstract method that handles a commit reservation request.     * This method commits a reservation and submits a list of  Gridlets     * to be processed as well.     * {@link #replyCommitReservation(int, int, int)} method should be     * used to send a result back to sender or user.     * @param reservationID  a reservation ID     * @param senderID       a sender or user ID     * @param sendTag        a tag to send to the user     * @param list           a list of Gridlet objects     * @pre reservationID > 0     * @pre senderID > 0     * @pre list != null     * @post $none     */    public abstract void handleCommitReservation(int reservationID,                                 int senderID, int sendTag, GridletList list);    /**     * An abstract method that handles a query reservation request.     * {@link #replyQueryReservation(int, int, int)} method should be     * used to send a result back to sender or user.     * @param reservationID  a reservation ID     * @param senderID       a sender or user ID     * @param sendTag        a tag to send to the user     * @pre reservationID > 0     * @pre senderID > 0     * @post $none     */    public abstract void handleQueryReservation(int reservationID,                                 int senderID, int sendTag);    /**     * An abstract method that handles a query busy time request.     * {@link #replyTimeReservation(int, int, ArrayList, double)} method should     * be used to send a result back to sender or user.     * @param from    starting period time (local resource time)     * @param to      ending period time (local resource time)     * @param senderID       a sender or user ID     * @param sendTag        a tag to send to the user     * @pre from > 0     * @pre to > 0     * @pre senderID > 0     * @post $none     */    public abstract void handleQueryBusyTime(long from, long to, int senderID,                                 int sendTag, double userTimeZone);    /**     * An abstract method that handles a query free time request.     * {@link #replyTimeReservation(int, int, ArrayList, double)} method should     * be used to send a result back to sender or user.     * @param from    starting period time (local resource time)     * @param to      ending period time (local resource time)     * @param senderID       a sender or user ID     * @param sendTag        a tag to send to the user     * @pre from > 0     * @pre to > 0     * @pre senderID > 0     * @post $none     */    public abstract void handleQueryFreeTime(long from, long to, int senderID,                                 int sendTag, double userTimeZone);    ///////////////////// END OF ABSTRACT METHODS ////////////////////////////    /**     * Allocates a new ARPolicy object. A child class should call this method     * during its constructor. The name of this entity (or the child class that     * inherits this class) will be <tt>"resName_entityName"</tt>.     *     * @param resourceName    the GridResource entity name that will contain     *                        this allocation policy     * @param entityName      this object entity name     * @throws Exception This happens when one of the following scenarios occur:     *      <ul>     *          <li> creating this entity before initializing GridSim package     *          <li> this entity name is <tt>null</tt> or empty     *          <li> this entity has <tt>zero</tt> number of PEs (Processing     *              Elements). <br>     *              No PEs mean the Gridlets can't be processed.     *              A GridResource must contain one or more Machines.     *              A Machine must contain one or more PEs.     *      </ul>     *     * @see gridsim.GridSim#init(int, Calendar, boolean)     * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[],     *          String)     * @pre resourceName != null     * @pre entityName != null     * @post $none     */    protected ARPolicy(String resourceName, String entityName) throws Exception    {        super(resourceName, entityName);        // size = 3 * Time interval to store tags for sec, min and hour        tagArray_ = new int[TAG_SIZE + TAG_SIZE + TAG_SIZE];        // populating the data. Just make sure the tag numbers are decremented        // by 1

⌨️ 快捷键说明

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