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

📄 regionalgiswithfailure.java

📁 中間件開發详细说明:清华大学J2EE教程讲义(ppt)-Tsinghua University J2EE tutorial lectures (ppt) [上载源码成为会员下载此源码] [成为VIP会
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * 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 * * Author: Agustin Caminero and Anthony Sulistio * Organization: Universidad de Castilla La Mancha (UCLM), Spain. * Created on: Nov 2006. */package gridsim.resFailure;import gridsim.index.*;import java.util.*;import eduni.simjava.*;import gridsim.*;import gridsim.net.Link;import eduni.simjava.distributions.Sim_uniform_obj;import gridsim.resFailure.FailureMsg;import eduni.simjava.distributions.DiscreteGenerator;import eduni.simjava.distributions.ContinuousGenerator;import gridsim.util.Variate;import java.io.FileWriter;/** * RegionalGISWithFailure is based on {@link gridsim.index.RegionalGIS}, but * with added failure functionalities. * RegionalGISWithFailure is a simple regional GridInformationService (GIS) * entity that * performs basic functionalities, such as storing a list of local resources, * and asking other regional GIS entities for resources. * <p> * If you want to implement other complex functionalities, you need to extend * this class and to override {@link #processOtherEvent(Sim_event)} * and/or {@link #registerOtherEntity()} method. * * @author  Agustin Caminero and Anthony Sulistio * @since   GridSim Toolkit 4.1 * @see     gridsim.index.RegionalGIS */public class RegionalGISWithFailure extends AbstractGIS{    /** This entity ID in <tt>Integer</tt> object. */    protected Integer myID_;    private ArrayList resList_;         // all resources within this region    private ArrayList arList_;          // AR resources only within this region    private ArrayList globalResList_;   // all resources outside this region    private ArrayList globalResARList_; // AR resources only outside this region    private LinkedList regionalList_;   // list of regional GIS, incl. myself    private ArrayList userList_;    // list of users querying for global res    private ArrayList userARList_;  // list of users querying for global AR res    private int numRes_;  // counting for num of GIS entities for res request    private int numAR_;   // counting for num of GIS entities for res AR request    // defines how GIS should decide how many resource fails    private DiscreteGenerator failureNumResPatternDiscrete_;    // defines how GIS should decide when the resource will fail    private DiscreteGenerator failureTimePatternDiscrete_;    // defines how GIS should decide how long the resource will be out of order    private DiscreteGenerator failureLengthPatternDiscrete_;    // defines how GIS should decide how many resource fails    private ContinuousGenerator failureNumResPatternCont_;    // defines how GIS should decide when the resource will fail    private ContinuousGenerator failureTimePatternCont_;    // defines how GIS should decide how long the resource will be out of order    private ContinuousGenerator failureLengthPatternCont_;    // New, as some distibutions coming with SimJava2 does not work    // defines how GIS should decide how many resource fails    private Variate failureNumResPatternVariate_;    // defines how GIS should decide when the resource will fail    private Variate failureTimePatternVariate_;    // defines how GIS should decide how long the resource will be out of order    private Variate failureLengthPatternVariate_;    // a flag to denote whether to record events into a file or not    private boolean record_ = false;    // denotes whether sim has just began or it has been running for some time    private boolean begining;    /**     * Creates a new regional GIS entity     * @param name  this regional GIS name     * @param link  a network link to this entity     * @param failureLengthPattern      defines on how long     *                                  each resource will be out of order     * @param failureNumResPattern      defines on how many resource fails     * @param failureTimePattern        defines on when each resource will fail     * @throws Exception This happens when creating this entity before     *                   initializing GridSim package or this entity name is     *                   <tt>null</tt> or empty     * @pre name != null     * @pre link != null     * @post $none     */    public RegionalGISWithFailure(String name, Link link,                           DiscreteGenerator failureNumResPattern,                           DiscreteGenerator failureTimePattern,                           DiscreteGenerator failureLengthPattern)                           throws Exception    {        super(name, link);        if (setFailureGenerator(failureNumResPattern, failureTimePattern,                                failureLengthPattern))            init();        else            throw new Exception(super.get_name() +                    " : Problem when setting the failure patterns for the " +                    super.get_name() + " entity");    }    /**     * Creates a new regional GIS entity     * @param name  this regional GIS name     * @param link  a network link to this entity     * @param failureLengthPattern      defines on how long     *                                  each resource will be out of order     * @param failureNumResPattern      defines on how many resource fails     * @param failureTimePattern        defines on when each resource will fail     * @throws Exception This happens when creating this entity before     *                   initializing GridSim package or this entity name is     *                   <tt>null</tt> or empty     * @pre name != null     * @pre link != null     * @post $none     */    public RegionalGISWithFailure(String name, Link link,                      ContinuousGenerator failureNumResPattern,                      ContinuousGenerator failureTimePattern,                      ContinuousGenerator failureLengthPattern)                      throws Exception    {       super(name, link);       if (setFailureGenerator(failureNumResPattern, failureTimePattern,                               failureLengthPattern))           init();       else           throw new Exception(super.get_name() +                   " : Problem when setting the failure patterns for the " +                   super.get_name() + " entity");    }   /**    * Creates a new regional GIS entity    * @param name  this regional GIS name    * @param link  a network link to this entity    * @param failureLengthPattern      defines on how long    *                                  each resource will be out of order    * @param failureNumResPattern      defines on how many resource fails    * @param failureTimePattern        defines on when each resource will fail    * @throws Exception This happens when creating this entity before    *                   initializing GridSim package or this entity name is    *                   <tt>null</tt> or empty    * @pre name != null    * @pre link != null    * @post $none    */   public RegionalGISWithFailure(String name, Link link,                     Variate failureNumResPattern, Variate failureTimePattern,                     Variate failureLengthPattern) throws Exception   {       super(name, link);       if (setFailureGenerator(failureNumResPattern, failureTimePattern,                               failureLengthPattern))           init();       else           throw new Exception(super.get_name() +                   " : Problem when setting the failure patterns for the " +                   super.get_name() + " entity");   }    /**     * Asks this resource to record its activities. <br>     * NOTE: this method should be called <b>BEFORE</b> the simulation starts.     * If an existing file exists, the new activities will be appended at the     * end. The file name is this entity name.     *     * @param trace     <tt>true</tt> if you want to record this resource's     *                  activities, <tt>false</tt> otherwise     */    public void setTrace(boolean trace)    {        record_ = trace;        initializeReportFile();    }    /**     * Initialises all attributes     * @pre $none     * @post $none     */    private void init()    {        myID_ = new Integer( super.get_id() );        resList_ = new ArrayList();        arList_ = new ArrayList();        regionalList_ = null;        globalResList_ = null;        globalResARList_ = null;        userList_ = null;        userARList_ = null;        numAR_ = -1;        numRes_ = -1;        begining = true;    }    /**     * Stores the incoming registration ID into the given list. <br>     * NOTE: <tt>ev.get_data()</tt> should contain an <tt>Integer</tt> object.     *     * @param ev      a new Sim_event object or incoming registration request     * @param list    a list storing the registration IDs     * @return <tt>true</tt> if successful, <tt>false</tt> otherwise     * @pre ev != null     * @pre list != null     * @post $none     */    protected boolean storeRegistrationID(Sim_event ev, List list)    {        boolean result = false;        if (ev == null || list == null) {            return result;        }        Object obj = ev.get_data();        if (obj instanceof Integer)        {            Integer id = (Integer) obj;            list.add(id);            result = true;            if (record_ == true) {                write("Registering", id.intValue(), GridSim.clock());                System.out.println();                System.out.println(super.get_name() + ": registering " +                    GridSim.getEntityName(id));                for (int i = 0; i < list.size() ; i++)                {                    System.out.println(super.get_name() + ": list["+ i +"] = " +                        GridSim.getEntityName((Integer) list.get(i)) );                }                System.out.println();            }        }        return result;    }    /**     * Process a registration request from a resource entity     * supporting Advanced Reservation to this regional     * GIS entity. <br>     * NOTE: <tt>ev.get_data()</tt> should contain an <tt>Integer</tt> object     * representing the resource ID.     *     * @param ev  a Sim_event object (or a registration request)     * @pre ev != null     * @post $none     */    protected void processRegisterResourceAR(Sim_event ev)    {        boolean result1 = storeRegistrationID(ev, arList_);        boolean result2 = storeRegistrationID(ev, resList_);        if (result1 == false || result2 == false)        {            System.out.println(super.get_name() +                ".processRegisterResourceAR(): Warning - can't register " +                "a resource ID.");        }    }    /**     * Process a registration request from a resource entity to this regional     * GIS entity. <br>     * NOTE: <tt>ev.get_data()</tt> should contain an <tt>Integer</tt> object     * representing the resource ID.     *     * @param ev  a Sim_event object (or a registration request)     * @pre ev != null     * @post $none     */    protected void processRegisterResource(Sim_event ev)    {        boolean result = storeRegistrationID(ev, resList_);        if (result == false)        {            System.out.println(super.get_name() +                ".processRegisterResource(): Warning - can't register " +                "a resource ID.");        }    }    /**     * This function processes an incoming event,     * whose tag is GRIDRESOURCE_FAILURE.     * @param ev  a Sim_event object (or an incoming event or request)     */    private void processGridResource_Failure(Sim_event ev)    {        Random random = new Random(); // a random generator        Integer res_id_Integer;        int res_id;        /*****        We have different cases:         - when there are no resources available at this moment, just schedule           this event for another time in the future         - if we are the beginning of the simulation, then we have to decide           how many res will fail, when and for how long.         - if we are not at the beginning of the sim, we have to choose           a resource and send the GRIDRESOURCE_FAILURE event.        *****/        // If there are no available resources, then we have to        // schedule ths event for another time in the future        if (resList_.size() == 0)        {            System.out.println(                "------- GRIDRESOURCE_FAILURE received at the " +                super.get_name() +                ", but there is no resources available." +                " So, scheduling a new GRIDRESOURCE_FAILURE to GIS in 2 mins.");            super.send(super.get_id(), 120, GridSimTags.GRIDRESOURCE_FAILURE);        }        // if the sim has just began, then we have to decide how many res        // will fail, when and for how long        else if (begining)        {            begining = false; // the sim is already running            // how many resources will fail            int numResFail = (int) getNextFailureNumResSample();            // in case we have chosen too many res to fail            if (numResFail > resList_.size())                numResFail = resList_.size();            /****************/            if (record_ == true) {                System.out.println(super.get_name() + ": " + numResFail +                   " resources will fail in this simulation. " +                   "Num of failed machines on each resource will be decided later");            }            /****************/            for (int i = 0; i < numResFail; i++)            {                // when a resource will fail                double resTimeFail = getNextFailureTimeSample();                // Now, schedule an event to this entity, so that when that                // event happens, RegionalGISWithFailure will                // choose the resource which will fail and how long the failure                // will last. Then, it will send the failure signal to the resource.                super.send(super.get_id(), resTimeFail,                           GridSimTags.GRIDRESOURCE_FAILURE);                /*********/                if (record_ == true) {                    System.out.println(super.get_name() +                       ": sends an autogenerated GRIDRESOURCE_FAILURE to itself." +                       " Clock: " + GridSim.clock() + ", resTimeFail: " +                       resTimeFail + " seconds");                }                /*********/            }        } // if (begining)        else        {            // Send the GRIDRESOURCE_FAILURE event to the resources.            // First, choose how long the failure will be, and the number            // of machines affected. Convert hours into seconds            double failureLength = getNextFailureLengthSample() * 3600;            int numMachFailed = (int) getNextNumMachinesFailedSample();            // Only do anything if the number of machines and the length of            // the failure are > 0            if ((numMachFailed > 0) && (failureLength > 0) )            {                ResourceCharacteristics resChar;                // Second, choose a resource to send the failure event.                // Only choose a resource whose machines are all of them                // working properly.                int res_num;                boolean isWorking;

⌨️ 快捷键说明

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