📄 broker.java
字号:
/* * Title: Grid Broker * Description: A Grid Scheduler for Application Scheduling on Grid based on * Deadline and Budget Constrained Scheduling Algorithms * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * $Id: Broker.java,v 1.7 2003/06/30 05:10:55 anthony Exp $ */package gridbroker;import gridbroker.*;import java.util.*;import java.io.*;import gridsim.*;import eduni.simjava.Sim_event;/** * Broker class simulates the Grid resource broker. On receiving an experiment * from the user entity, it carries out resource discovery, and determines * deadline and budget values based on D- and B-factor, and then proceeds with * scheduling. * <p> * Broker class schedules Gridlets on resources depending on user constraints, * optimization strategy, and cost of resources and their availability. When it * receives the results of application processing, it records parameters of * interest with the <tt>gridsim.Statistics</tt> entity. When it has no more * processing requirements, it sends the <tt>END_OF_SIMULATION</tt> event to the * <tt>gridsim.GridSimShutdown</tt> entity. * * @author Manzur Murshed and Rajkumar Buyya * @version 2.1, June 2003 * @invariant $none */public class Broker extends GridSim{ private Experiment experiment_; private LinkedList resIDList_; // Resource Enity ID List private LinkedList brokerResourceList_; private GridletList glUnfinishedList_; private GridletList glFinishedList_; private int gridletDispatched_; private int gridletReturned_; private double expenses_; // the amount of budget spent so far private int maxGridletPerPE_; // Num Gridlets in Execution at any instance /** * Allocates a new Broker class * @param name the entity name * @param baudRate the communication speed * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], * String) * @pre name != null * @pre baudRate >= 0.0 * @post $none */ public Broker(String name, double baudRate) throws Exception { super(name, baudRate); gridletDispatched_ = 0; gridletReturned_ = 0; expenses_ = 0.0; maxGridletPerPE_ = 1; experiment_ = null; resIDList_ = null; brokerResourceList_ = null; glUnfinishedList_ = null; glFinishedList_ = null; } ////////////// Start INTERNAL CLASSES ///////////////////////////////// /** * This class can be used to sort the simulation cost * @invariant $none */ private class OrderCost implements Comparator { /** * Allocates a new OrderCost object * @pre $none * @post $none */ public OrderCost() { super(); } /** * Compare two objects * @param a the first Object to be compared * @param b the second Object to be compared * @return the value 0 if both Objects are equal; * a value less than 0 if the first Object is lexicographically * less than the second Object; * and a value greater than 0 if the first Object is * lexicographically greater than the second Object. * @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected * to be of type <tt>BrokerResource</tt> * @see BrokerResource * @pre a != null * @pre b != null * @post $none */ public int compare(Object a, Object b) throws ClassCastException { BrokerResource BRa = (BrokerResource) a; BrokerResource BRb = (BrokerResource) b; // Processing Cost of Resources Double d_c1 = new Double( BRa.resource.getCostPerMI() ); Double d_c2 = new Double( BRb.resource.getCostPerMI() ); return d_c1.compareTo(d_c2); } } // end internal class /** * This class can be used to sort the simulation cost and time * @invariant $none */ private class OrderCostTime implements Comparator { /** * Allocates a new OrderCostTime object * @pre $none * @post $none */ public OrderCostTime() { super(); } /** * Compare two objects * @param a the first Object to be compared * @param b the second Object to be compared * @return the value 0 if both Objects are equal; * a value less than 0 if the first Object is lexicographically * less than the second Object; * and a value greater than 0 if the first Object is * lexicographically greater than the second Object. * @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected * to be of type <tt>BrokerResource</tt> * @see BrokerResource * @pre a != null * @pre b != null * @post $none */ public int compare(Object a, Object b) throws ClassCastException { BrokerResource BRa = (BrokerResource) a; BrokerResource BRb = (BrokerResource) b; // Processing Cost of Resources Double d_c1 = new Double( BRa.resource.getCostPerMI() ); Double d_c2 = new Double( BRb.resource.getCostPerMI() ); // both resources cost the same price, them make powerful // resources as prefered first and put them to the begining // of the list. That is why // p2 and p1 are compared, instead of p1 and p2. if ( d_c1.equals(d_c2) ) { // Processing Capacity of Resources Double d_p1 = new Double( BRa.resource.getMIPSRating() * (1 - BRa.LatestLoad) ); Double d_p2 = new Double( BRb.resource.getMIPSRating() * (1 - BRb.LatestLoad) ); return d_p2.compareTo(d_p1); } else { return d_c1.compareTo(d_c2); } } } // end internal class /** * A class to store record of earlier processing time of a given Gridlet on * a given resource * @invariant $none */ private class BRGridletProcessingTime { /** A BrokerResource object */ public BrokerResource br; /** Denotes Gridlet processing time */ public double gridlet_processing_time; /** * Allocates a new BRGridletProcessingTime object * @param br a BrokerResource object * @param gl a Gridlet object * @see gridsim.Gridlet * @see gridbroker.BrokerResource * @pre br != null * @pre gl != null * @post $none */ public BRGridletProcessingTime(BrokerResource br, Gridlet gl) { this.br = br; this.gridlet_processing_time = br.getExpectedCompletionTime(gl); } } // end internal class /** * Comparator Interface for Sorting records of BRGridletProcessingTime * in asceneding order */ private class OrderBRGridletProcessingTime implements Comparator { /** * Allocates a new OrderBRGridletProcessingTime object * @pre $none * @post $none */ public OrderBRGridletProcessingTime() { super(); } /** * Compare two objects * @param a the first Object to be compared * @param b the second Object to be compared * @return the value 0 if both Objects are equal; * a value less than 0 if the first Object is lexicographically * less than the second Object; * and a value greater than 0 if the first Object is * lexicographically greater than the second Object. * @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected * to be of type <tt>BRGridletProcessingTime</tt> * @see gridbroker.Broker.BRGridletProcessingTime * @pre a != null * @pre b != null * @post $none */ public int compare(Object a, Object b) { BRGridletProcessingTime brGlT1 = (BRGridletProcessingTime) a; BRGridletProcessingTime brGlT2 = (BRGridletProcessingTime) b; // Processing Time on Resources Double d_t1 = new Double(brGlT1.gridlet_processing_time); Double d_t2 = new Double(brGlT2.gridlet_processing_time); return d_t1.compareTo(d_t2); } } // end internal class ///////////////////// End of INTERNAL CLASSES ////////////////////////// /** * Invokes a schedule report for every scheduling event. * <p> * In addition, * creates report files with <tt>".sched1"</tt>, <tt>".sched2"</tt>, * <tt>".sched3"</tt> and <tt>".sched31"</tt> extension. * @param expt an Experiment object * @param BRList a linked-list of broker resource * @param reportHeaderFlag a report header flag * @deprecated As of GridBroker 2.1, replaced by * {@link #scheduleReport(Experiment, LinkedList, boolean)} * @pre expt != null * @pre BRList != null * @post $none */ public void ScheduleReport(Experiment expt, LinkedList BRList, boolean reportHeaderFlag) { this.scheduleReport(expt, BRList, reportHeaderFlag); } /** * Invokes a schedule report for every scheduling event. * <p> * In addition, * creates report files with <tt>".sched1"</tt>, <tt>".sched2"</tt>, * <tt>".sched3"</tt> and <tt>".sched31"</tt> extension. * @param expt an Experiment object * @param BRList a linked-list of broker resource * @param reportHeaderFlag a report header flag * @pre expt != null * @pre BRList != null * @post $none */ public void scheduleReport(Experiment expt, LinkedList BRList, boolean reportHeaderFlag) { // PRINT report for the User with Experiment ID = 0 if (expt.getExperimentID() != 0) { return; } // print scheduling trace for experiment with ID 0 (i.e., // for the first user) String report1_filename = expt.getReportFileName() + ".sched1"; String report2_filename = expt.getReportFileName() + ".sched2"; String report3_filename = expt.getReportFileName() + ".sched3"; String report31_filename = expt.getReportFileName() + ".sched31"; writeScheduleReport("Gridlets Finished Report", report1_filename, BrokerResource.PARAM_GRIDLETS_FINISHED, expt, BRList, reportHeaderFlag); writeScheduleReport("Gridlets Processing Expenses Report", report2_filename, BrokerResource.PARAM_PROCESSING_EXPENSES, expt, BRList, reportHeaderFlag); writeScheduleReport("Gridlets on Resource Report", report3_filename, BrokerResource.PARAM_GRIDLETS_ON_RESOURCE, expt, BRList, reportHeaderFlag); writeScheduleReport("Gridlets Committed for Resource Report", report31_filename, BrokerResource.PARAM_GRIDLETS_COMMITTED_FOR_RESOURCE, expt, BRList, reportHeaderFlag); } /** * Writes a schedule report * @param reportTitle the title of a report * @param reportFileFullname the name of a report * @param parameter a resource paramter * @param expt an object of Experiment * @param BRList a linked-list of broker resource * @param reportHeaderFlag a report header flag * @see gridbroker.Experiment * @deprecated As of GridBroker 2.1, replaced by * {@link #writeScheduleReport(String, String, int, Experiment, * LinkedList, boolean)} * @pre reportTitle != null * @pre reportFileFullname != null * @pre parameter >= 0 * @pre expt != null * @pre BRList != null * @post $none */ public void WriteScheduleReport(String reportTitle, String reportFileFullname, int parameter, Experiment expt, LinkedList BRList, boolean reportHeaderFlag) { this.writeScheduleReport(reportTitle, reportFileFullname, parameter, expt, BRList, reportHeaderFlag); } /** * Writes a schedule report * @param reportTitle the title of a report * @param reportFileFullname the name of a report * @param parameter a resource paramter * @param expt an object of Experiment * @param BRList a linked-list of broker resource * @param reportHeaderFlag a report header flag * @see gridbroker.Experiment * @pre reportTitle != null * @pre reportFileFullname != null
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -