gridresource.java
来自「一个非常著名的网格模拟器,能够运行网格调度算法!」· Java 代码 · 共 1,005 行 · 第 1/3 页
JAVA
1,005 行
/* * 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: GridResource.java,v 1.61 2006/03/09 05:56:31 anthony Exp $ */package gridsim;import gridsim.*;import gridsim.net.*;import gridsim.index.*;import java.util.LinkedList;import eduni.simjava.Sim_event;import eduni.simjava.Sim_system;/** * GridResource extends the {@link gridsim.GridSimCore} class for * gaining communication and concurrent entity capabilities. * An instance of this class stimulates a resource * with properties defined in an object of * {@link gridsim.ResourceCharacteristics} class. * <p> * The process of creating a Grid resource is as follows: * <ol> * <li> create PE (Processing Element) objects with a suitable MIPS (Million * Instructions Per Second) or SPEC (Standard Performance Evaluation * Corporation) rating; * <li> assemble them together to create a machine; * <li> group one or more objects of the machine to form a Grid resource * </ol> * <p> * A resource having a single machine with one or more PEs (Processing Elements) * is managed as a time-shared system using a round-robin scheduling algorithm. * A resource with multiple machines is treated as a distributed memory cluster * and is managed as a space-shared system using FCFS (First Come Firt Serve) * scheduling policy or its variants. * <p> * Since GridSim 2.2, other scheduling algorithm can be added externally * (without compiling or replacing the existing GridSim JAR file) into a * Grid resource. For more information, look on tutorial page or AllocPolicy * class. * <p> * Since GridSim 3.0, different types of resources can be created externally * without modifying this class. You need to do the following: * <ol> * <li> extends from this class * <li> uses only a constructor from * {@link #GridResource(String, double, ResourceCharacteristics, * ResourceCalendar, AllocPolicy)} * <li> overrides {@link #registerOtherEntity()} method to register a * different entity or tag to {@link gridsim.GridInformationService}. * However, you also need to create a new child class extending from * {@link gridsim.GridInformationService}. * <li> overrides {@link #processOtherEvent(Sim_event)} method to process * other incoming tags apart from the standard ones. * </ol> * <br> * <b>NOTE:</b> * <ul> * <li>You do not need to override {@link #body()} method if you do step 3. * <li>A resource name can be found using <tt>super.get_name()</tt> method * from {@link eduni.simjava.Sim_entity} class. * <li>A resource ID can be found using <tt>super.get_id()</tt> method * from {@link eduni.simjava.Sim_entity} class. * </ul> * <p> * Since GridSim 3.1, a network framework has been incorporated into this * simulation. To make use of this, you need to create a resource entity * only using the below constructors: * <ul> * <li> {@link #GridResource(String, Link, ResourceCharacteristics, * ResourceCalendar, AllocPolicy)} * <li> {@link #GridResource(String, Link, ResourceCharacteristics, * ResourceCalendar)} * <li> {@link #GridResource(String, Link, long, * ResourceCharacteristics, double, double, double, * LinkedList, LinkedList)} * </ul> * * Then you need to attach this entity into the overall network topology, i.e. * connecting this entity to a router, etc. See the examples for more details. * * @author Manzur Murshed and Rajkumar Buyya * @author Anthony Sulistio (re-written this class) * @since GridSim Toolkit 1.0 * @see gridsim.GridSimCore * @see gridsim.ResourceCharacteristics * @see gridsim.AllocPolicy * @invariant $none */public class GridResource extends GridSimCore{ /** Characteristics of this resource */ protected ResourceCharacteristics resource_; /** a ResourceCalendar object */ protected ResourceCalendar resCalendar_; /** A resource's scheduler. This object is reponsible in scheduling and * and executing submitted Gridlets. */ protected AllocPolicy policy_; /** A scheduler type of this resource, such as FCFS, Round Robin, etc */ protected int policyType_; /** Integer object size, including its overhead */ protected final int SIZE = 12; /** Regional GIS entity name */ protected String regionalGISName_; /** * Allocates a new GridResource object. When making a different type of * GridResource object, use * {@link #GridResource(String, double, ResourceCharacteristics, * ResourceCalendar, AllocPolicy)} * and then overrides {@link #processOtherEvent(Sim_event)}. * * @param name the name to be associated with this entity (as * required by Sim_entity class from simjava package) * @param baud_rate network communication or bandwidth speed * @param seed the initial seed * @param resource an object of ResourceCharacteristics * @param peakLoad the load during peak times * @param offPeakLoad the load during off peak times * @param relativeHolidayLoad the load during holiday times * @param weekends a linked-list contains the weekend days * @param holidays a linked-list contains the public holidays * @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, String[], String[], * String) * @see gridsim.GridSim#init(int, Calendar, boolean) * @see #GridResource(String, double, * ResourceCharacteristics, ResourceCalendar, AllocPolicy) * @pre name != null * @pre baud_rate > 0 * @pre resource != null * @post $none */ public GridResource(String name, double baud_rate, long seed, ResourceCharacteristics resource, double peakLoad, double offPeakLoad, double relativeHolidayLoad, LinkedList weekends, LinkedList holidays) throws Exception { super(name, baud_rate); resource_ = resource; resCalendar_ = new ResourceCalendar(resource_.getResourceTimeZone(), peakLoad, offPeakLoad, relativeHolidayLoad, weekends, holidays, seed); policy_ = null; init(); } /** * Allocates a new GridResource object. When making a different type of * GridResource object, use * {@link #GridResource(String, double, ResourceCharacteristics, * ResourceCalendar, AllocPolicy)} * and then overrides {@link #processOtherEvent(Sim_event)}. * * @param name the name to be associated with this entity (as * required by Sim_entity class from simjava package) * @param baud_rate network communication or bandwidth speed * @param resource an object of ResourceCharacteristics * @param calendar an object of ResourceCalendar * @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, String[], String[], * String) * @see gridsim.GridSim#init(int, Calendar, boolean) * @see #GridResource(String, double, * ResourceCharacteristics, ResourceCalendar, AllocPolicy) * @pre name != null * @pre baud_rate > 0 * @pre resource != null * @pre calendar != null * @post $none */ public GridResource(String name, double baud_rate, ResourceCharacteristics resource, ResourceCalendar calendar) throws Exception { super(name, baud_rate); resource_ = resource; resCalendar_ = calendar; policy_ = null; init(); } /** * Allocates a new GridResource object. When making a different type of * GridResource object, use this constructor and then overrides * {@link #processOtherEvent(Sim_event)}. * * @param name the name to be associated with this entity (as * required by Sim_entity class from simjava package) * @param baud_rate network communication or bandwidth speed * @param resource an object of ResourceCharacteristics * @param calendar an object of ResourceCalendar * @param policy a scheduling policy for this Grid resource. If no * scheduling policy is defined, the default one is * <tt>SpaceShared</tt> * @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, String[], String[], * String) * @see gridsim.GridSim#init(int, Calendar, boolean) * @see gridsim.AllocPolicy * @pre name != null * @pre baud_rate > 0 * @pre resource != null * @pre calendar != null * @pre policy != null * @post $none */ public GridResource(String name, double baud_rate, ResourceCharacteristics resource, ResourceCalendar calendar, AllocPolicy policy) throws Exception { super(name, baud_rate); resource_ = resource; resCalendar_ = calendar; policy_ = policy; // the order between policy and init() is important init(); } //////////////////////////////////////////// /** * Allocates a new GridResource object. When making a different type of * GridResource object, use * {@link #GridResource(String, Link, ResourceCharacteristics, * ResourceCalendar, AllocPolicy)} * and then overrides {@link #processOtherEvent(Sim_event)}. * * @param name the name to be associated with this entity (as * required by Sim_entity class from simjava package) * @param link the link that will be used to connect this * GridResource to another Entity or Router. * @param seed the initial seed * @param resource an object of ResourceCharacteristics * @param peakLoad the load during peak times * @param offPeakLoad the load during off peak times * @param relativeHolidayLoad the load during holiday times * @param weekends a linked-list contains the weekend days * @param holidays a linked-list contains the public holidays * @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, String[], String[], * String) * @pre name != null * @pre link != null * @pre resource != null * @post $none */ public GridResource(String name, Link link, long seed, ResourceCharacteristics resource, double peakLoad, double offPeakLoad, double relativeHolidayLoad, LinkedList weekends, LinkedList holidays) throws Exception { super(name, link); resource_ = resource; resCalendar_ = new ResourceCalendar(resource_.getResourceTimeZone(), peakLoad, offPeakLoad, relativeHolidayLoad, weekends, holidays, seed); policy_ = null; init(); } /** * Allocates a new GridResource object. When making a different type of * GridResource object, use * {@link #GridResource(String, Link, ResourceCharacteristics, * ResourceCalendar, AllocPolicy)} * and then overrides {@link #processOtherEvent(Sim_event)}. * * @param name the name to be associated with this entity (as * required by Sim_entity class from simjava package) * @param link the link that will be used to connect this * GridResource to another Entity or Router. * @param resource an object of ResourceCharacteristics * @param calendar an object of ResourceCalendar * @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.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?