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

📄 resfailureex03.java

📁 中間件開發详细说明:清华大学J2EE教程讲义(ppt)-Tsinghua University J2EE tutorial lectures (ppt) [上载源码成为会员下载此源码] [成为VIP会
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        " and registered to " + gis.get_name() );            }            //////////////////////////////////////////            // Fifth step: Creates one or more GridUserFailure entities,            // linked to a router of the topology            int totalGridlet = 5;    // total jobs            double pollTime = 100;   // time between polls            int glSize = 100000;     // the size of gridlets (input/output)            int glLength = 42000000; // the length (MI) of gridlets            trace_flag = true;            for (int i = 0; i < num_user; i++)            {                String userName = NAME + "User_" + i;                // a network link attached to this entity                Link link2 = new SimpleLink(userName + "_link", baud_rate,                                            propDelay, mtu);                // only keeps track activities from User_0                if (i != 0) {                    trace_flag = false;                }                GridUserFailureEx03 user = new GridUserFailureEx03(userName, link2,                        pollTime, glLength, glSize, glSize, trace_flag);                user.setGridletNumber(totalGridlet);                // link this user to a router                String routerName = null;                if (random.nextBoolean() == true)                {                    linkNetwork(router0, user);                    routerName = router0.get_name();                }                else                {                    linkNetwork(router1, user);                    routerName = router1.get_name();                }                // randomly select which GIS to choose                int index = random.nextInt( gisList.size() );                RegionalGISWithFailure gis = (RegionalGISWithFailure) gisList.get(index);                user.setRegionalGIS(gis); // set the regional GIS entity                System.out.println("Created " + userName +                        " with id = " + user.get_id() + ", linked to " +                        routerName + ", and with " + totalGridlet +                        " gridlets. Registered to " + gis.get_name() );            }            System.out.println();            //////////////////////////////////////////            // Sixth step: Starts the simulation            GridSim.startGridSimulation();            System.out.println("\nFinish failure example 3... \n");        }        catch (Exception e)        {            e.printStackTrace();            System.out.println("Unwanted errors happen");        }    }    /**     * Links a particular entity with a given Router.     *     * @param router    a Router object     * @param obj       a GridSim entity to be attached to the Router     */    private static void linkNetwork(Router router, GridSimCore obj) throws Exception    {        if (router == null) {            System.out.println("Error - router is NULL.");            return;        }        // get the baud rate of a link        double baud_rate = obj.getLink().getBaudRate();        // create the packet scheduler for this link        PacketScheduler pktObj = new FIFOScheduler(router.get_name() +                                                   "_to_" + obj.get_name() );        // attach this GridSim entity to a Router        router.attachHost(obj, pktObj);    }    /**     * Creates one Grid resource. A Grid resource contains one or more     * Machines. Similarly, a Machine contains one or more PEs (Processing     * Elements or CPUs).     * <p>     * In this simple example, we are simulating one Grid resource with three     * Machines that contains one or more PEs.     *     * @param name          a Grid Resource name     * @param baud_rate     the bandwidth of this entity     * @param delay         the propagation delay     * @param MTU           Maximum Transmission Unit     * @param totalPE       number of PE per machine     * @param totalMachine  number of machines in this resources     * @param rating        rating of mahcines in this resource     * @param sched_alg     the scheduling algorithm of this resource     * @return a GridResource object     */    private static GridResourceWithFailure createGridResource(String name,                        double baud_rate, double delay, int MTU, int totalPE,                        int totalMachine, int rating, String sched_alg)    {        // Here are the steps needed to create a Grid resource:        // 1. We need to create an object of MachineList to store one or more        //    Machines        MachineList mList = new MachineList();        for (int i = 0; i < totalMachine; i++)        {            // 2. A Machine contains one or more PEs or CPUs. Therefore, should            //    create an object of PEList to store these PEs before creating            //    a Machine.            PEList peList = new PEList();            // 3. Create PEs and add these into an object of PEList.            for (int k = 0; k < totalPE; k++)            {                // need to store PE id and MIPS Rating                peList.add( new PE(k, rating) );            }            // 4. Create one Machine with its id and list of PEs or CPUs            mList.add( new Machine(i, peList) );        }        // 5. Create a ResourceCharacteristics object that stores the        //    properties of a Grid resource: architecture, OS, list of        //    Machines, allocation policy: time- or space-shared, time zone        //    and its price (G$/PE time unit).        String arch = "Sun Ultra";      // system architecture        String os = "Solaris";          // operating system        double time_zone = 9.0;         // time zone this resource located        double cost = 3.0;              // the cost of using this resource        // we create Space_Shared_failure or Time_Shared_failure schedulers        int scheduling_alg = 0;         // space_shared or time_shared        if (sched_alg.equals("SPACE") == true) {            scheduling_alg = ResourceCharacteristics.SPACE_SHARED;        }        else if (sched_alg.equals("TIME") == true) {            scheduling_alg = ResourceCharacteristics.TIME_SHARED;        }        ResourceCharacteristics resConfig = new ResourceCharacteristics(                arch, os, mList, scheduling_alg, time_zone, cost);        // 6. Finally, we need to create a GridResource object.        long seed = 11L*13*17*19*23+1;        double peakLoad = 0.0;        // the resource load during peak hour        double offPeakLoad = 0.0;     // the resource load during off-peak hr        double holidayLoad = 0.0;     // the resource load during holiday        // incorporates weekends so the grid resource is on 7 days a week        LinkedList Weekends = new LinkedList();        Weekends.add(new Integer(Calendar.SATURDAY));        Weekends.add(new Integer(Calendar.SUNDAY));        // incorporates holidays. However, no holidays are set in this example        LinkedList Holidays = new LinkedList();        GridResourceWithFailure gridRes = null;        try        {            // creates a GridResource with a link            gridRes = new GridResourceWithFailure(name,                new SimpleLink(name + "_link", baud_rate, delay, MTU),                seed, resConfig, peakLoad, offPeakLoad, holidayLoad,                Weekends, Holidays);        }        catch (Exception e) {            e.printStackTrace();        }        return gridRes;    }} // end class

⌨️ 快捷键说明

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