public static void main(String[] args)
    {
        System.out.println("Starting failure example 1...");

        try
        {
            if (args.length < 1)
            {
                System.out.println("Usage: java ResFailureEx01 network_ex01.txt");
                return;
            }


            //////////////////////////////////////////
            // First step: Initialize the GridSim package. It should be called
            // before creating any entities. We can't run this example without
            // initializing GridSim first. We will get a run-time exception
            // error.

            // a flag that denotes whether to trace GridSim events or not.
            boolean trace_flag = false;  // dont use SimJava trace
            int num_user = 1; //  number of grid users
            Calendar calendar = Calendar.getInstance();

            // Initialize the GridSim package
            System.out.println("Initializing GridSim package");
            GridSim.init(num_user, calendar, trace_flag);
            trace_flag = true;


            //////////////////////////////////////////
            // Second step: Builds the network topology among Routers.

            String filename = args[0];  // get the network topology
            System.out.println("Reading network from " + filename);
            LinkedList routerList = NetworkReader.createFIFO(filename);


            //////////////////////////////////////////
            // Third step: Creates one RegionalGISWithFailure entity,
            // linked to a router in the topology

            Router router = null;
            double baud_rate = 100000000;   // 100Mbps, i.e. baud rate of links
            double propDelay = 10;      // propagation delay in milliseconds
            int mtu = 1500;             // max. transmission unit in byte
            int totalMachines = 10;     // num of machines each resource has

            String NAME = "Ex01_";  // a common name
            String gisName = NAME + "Regional_GIS";  // GIS name

            // a network link attached to this regional GIS entity
            Link link = new SimpleLink(gisName + "_link", baud_rate,
                                       propDelay, mtu);


            // HyperExponential: mean, standard deviation, stream
            // how many resources will fail
            HyperExponential failureNumResPattern =
                    new HyperExponential(totalMachines / 2, totalMachines, 4);

            // when they will fail
            HyperExponential failureTimePattern =
                    new HyperExponential(25, 100, 4);

            // how long the failure will be
            HyperExponential failureLengthPattern =
                    new HyperExponential(20, 25, 4); // big test: (20, 100, 4);


            // creates a new Regional GIS entity that generates a resource
            // failure message according to these patterns.
            RegionalGISWithFailure gis = new RegionalGISWithFailure(gisName,
                              link, failureNumResPattern, failureTimePattern,
                              failureLengthPattern);
            gis.setTrace(trace_flag);   // record this GIS activity

            // link these GIS to a router
            router = NetworkReader.getRouter("Router0", routerList);
            linkNetwork(router, gis);

            // print some info messages
            System.out.println("Created a REGIONAL GIS with name " + gisName +
                    " and id = " + gis.get_id() + ", connected to " +
                    router.get_name() );


            //////////////////////////////////////////
            // Fourth step: Creates one or more GridResourceWithFailure
            // entities, linked to a router in the topology

            String sched_alg = "SPACE";  // use space-shared policy
            int totalResource = 3; // number of resources
            ArrayList resList = new ArrayList(totalResource);

            // Each resource may have different baud rate,
            // totalMachine, rating, allocation policy and the router to
            // which it will be connected. However, in this example, we assume
            // all have the same properties for simplicity.
            int totalPE = 4;        // num of PEs each machine has
            int rating = 49000;     // rating (MIPS) of PEs
            int GB = 1000000000;    // 1 GB in bits
            baud_rate = 2.5 * GB;

            for (int i = 0; i < totalResource; i++)
            {
                // gets the router object from the list
                router = NetworkReader.getRouter("Router0", routerList);

                // creates a new grid resource
                String resName = NAME + "Res_" + i;
                GridResourceWithFailure res = createGridResource(resName,
                            baud_rate, propDelay, mtu, totalPE, totalMachines,
                            rating, sched_alg);

                // add a resource into a list
                resList.add(res);
                res.setRegionalGIS(gis);    // set the regional GIS entity
                res.setTrace(trace_flag);   // record this resource activity

                // link a resource to this router object
                linkNetwork(router, res);

                System.out.println("Created a RESOURCE (" + totalMachines +
                    " machines, each with " + totalPE + " PEs) with name = " +
                    resName + " and id = " + res.get_id() +
                    ", connected to router " + router.get_name() +
                    " and registered to " + gis.get_name() );
            }


            //////////////////////////////////////////
            // Fifth step: Creates one GridUserFailure entity,
            // 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
            String userName = NAME + "User0";

            // gets the router object from the list
            router = NetworkReader.getRouter("Router0", routerList);

            // a network link attached to this entity
            Link link2 = new SimpleLink(userName + "_link", baud_rate,
                                        propDelay, mtu);

            GridUserFailureEx01 user = new GridUserFailureEx01(userName, link2,
                    pollTime, glLength, glSize, glSize, trace_flag);

            user.setRegionalGIS(gis); // set the regional GIS entity
            user.setGridletNumber(totalGridlet);

            // link a resource to this router object
            linkNetwork(router, user);

            System.out.println("Created a USER with name " + userName +
                    " and id = " + user.get_id() + ", connected to " +
                    router.get_name() + ", 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 1... \n");
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("Unwanted errors happen");
        }
    }