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

📄 gridsim.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            initCommonVariable(cal, traceFlag, numUser, reportWriterName);            GridStatistics stat = null;            // creates a GridStatistics object            stat = new GridStatistics("GridStatistics", "GridSim_stat.txt",true,                                      excludeFromFile, excludeFromProcessing);            // create a GIS object            gis_ = new GridInformationService("GridInformationService",                                              GridSimTags.DEFAULT_BAUD_RATE);            // set all the above entity IDs            gisID_ = gis_.get_id();            statsID_ = stat.get_id();        }        catch (Sim_exception s)        {            System.out.println("GridSim.init(): Unwanted errors happen");            System.out.println( s.getMessage() );        }        catch (Exception e)        {            System.out.println("GridSim.init(): Unwanted errors happen");            System.out.println( e.getMessage() );        }    }    /**     * Initializes GridSim parameters <b>without</b> any statistical     * entities. Therefore, if a simulation requires to record any statistical     * data, then need to use     * {@link #init(int, Calendar, boolean, String[], String[], String)}     * instead. This method should be called before creating any entities.     * <p>     * Inside this method, it will create the following GridSim entities:     * <ul>     *     <li>GridSimRandom     *     <li>GridInformationService     *     <li>GridSimShutdown     * </ul>     * <p>     * The Calendar object can be specified using     * <tt>Calendar.getInstance()</tt> to denote the start of the simulation     * time.     * This simulation time is <b>very important</b> in handling     * advanced reservations functionalities.     *     * @param numUser  the number of User Entities created.     *                 This parameters indicates that     *                 {@link gridsim.GridSimShutdown} first waits for     *                 User Entities's END_OF_SIMULATION signal before     *                 issuing terminate signal to other entities     * @param cal          starting time for this simulation. If it is     *        <tt>null</tt>, then the time will be taken from     *        <tt>Calendar.getInstance()</tt>     * @param traceFlag    true if GridSim trace need to be written     * @see gridsim.GridSimShutdown     * @see gridsim.GridInformationService     * @see gridsim.GridSimRandom     * @see gridsim.GridSim#init(int,Calendar,boolean,String[],String[],String)     * @pre numUser >= 0     * @post $none     */    public static void init(int numUser, Calendar cal, boolean traceFlag)    {        try        {            initCommonVariable(cal, traceFlag, numUser, null);            // create a GIS object            gis_ = new GridInformationService("GridInformationService",                                              GridSimTags.DEFAULT_BAUD_RATE);            // set all the above entity IDs            gisID_ = gis_.get_id();        }        catch (Sim_exception s)        {            System.out.println("GridSim.init(): Unwanted errors happen");            System.out.println( s.getMessage() );        }        catch (Exception e)        {            System.out.println("GridSim.init(): Unwanted errors happen");            System.out.println( e.getMessage() );        }    }    /**     * Initializes GridSim parameters <b>without</b> any statistical     * entities. Therefore, if a simulation requires to record any statistical     * data, then need to use     * {@link #init(int, Calendar, boolean, String[], String[], String)}     * instead. This method should be called before creating any entities.     * <p>     * Inside this method, it will create the following GridSim entities:     * <ul>     *     <li>GridSimRandom     *     <li>GridInformationService -- if the parameter <tt>gis</tt> set to     *         <tt>true</tt>. <br>     *         NOTE: If you want to use your own GIS entity, you need     *         to set <tt>gis</tt> parameter to <tt>false</tt>. Then, use     *         {@link #setGIS(GridInformationService)} method before running     *         or starting the simulation.     *     <li>GridSimShutdown     * </ul>     * <p>     * The Calendar object can be specified using     * <tt>Calendar.getInstance()</tt> to denote the start of the simulation     * time.     * This simulation time is <b>very important</b> in handling     * advanced reservations functionalities.     *     * @param numUser  the number of User Entities created.     *                 This parameters indicates that     *                 {@link gridsim.GridSimShutdown} first waits for     *                 all user entities's END_OF_SIMULATION signal before     *                 issuing terminate signal to other entities     * @param cal          starting time for this simulation. If it is     *        <tt>null</tt>, then the time will be taken from     *        <tt>Calendar.getInstance()</tt>     * @param traceFlag  <tt>true</tt> if GridSim trace need to be written     * @param gis        <tt>true</tt> if you want to use a <b>DEFAULT</b>     *                   {@link gridsim.GridInformationService} entity.     * @see gridsim.GridSimShutdown     * @see gridsim.GridInformationService     * @see gridsim.GridSimRandom     * @see gridsim.GridSim#setGIS(GridInformationService)     * @see gridsim.GridSim#init(int,Calendar,boolean,String[],String[],String)     * @pre numUser >= 0     * @post $none     */    public static void init(int numUser, Calendar cal, boolean traceFlag,                            boolean gis)    {        try        {            initCommonVariable(cal, traceFlag, numUser, null);            if (gis == true)            {                // create a GIS object                gis_ = new GridInformationService("GridInformationService",                                    GridSimTags.DEFAULT_BAUD_RATE);                // set all the above entity IDs                gisID_ = gis_.get_id();            }        }        catch (Sim_exception s)        {            System.out.println("GridSim.init(): Unwanted errors happen");            System.out.println( s.getMessage() );        }        catch (Exception e)        {            System.out.println("GridSim.init(): Unwanted errors happen");            System.out.println( e.getMessage() );        }    }    /**     * Sets a <tt>GridInformationService</tt> (GIS) entity.     * This method is useful is you write a different type of GIS entity.     * This method must be called before {@link #startGridSimulation()} method.     * @param gis  a GIS object     * @return <tt>true</tt> if successful, <tt>false</tt> otherwise     * @pre gis != null     * @post $none     * @see gridsim.GridSim#startGridSimulation()     */    public static boolean setGIS(GridInformationService gis)    {        if (gis == null) {            return false;        }        gis_ = gis;        gisID_ = gis.get_id();        return true;    }    /**     * Initializes all the common attributes     * @param cal   the starting time for this simulation. If it is     *        <tt>null</tt>, then the time will be taken from     *        <tt>Calendar.getInstance()</tt>.     * @param traceFlag   true if GridSim trace need to be written     * @throws Exception This happens when creating this entity before     *                   initializing GridSim package or this entity name is     *                   <tt>null</tt> or empty     * @pre $none     * @post $none     */    private static void initCommonVariable(Calendar cal, boolean traceFlag,               int numUser, String reportWriterName) throws Exception    {        // NOTE: the order for the below 3 lines are important        Sim_system.initialise();        Sim_system.set_trc_level(1);        Sim_system.set_auto_trace(traceFlag);        // Set the current Wall clock time as the starting time of simulation        calendar_ = cal;        if (cal == null) {            calendar_ = Calendar.getInstance();        }        SimulationStartDate = calendar_.getTime();        rand = new GridSimRandom();        // creates a GridSimShutdown object        GridSimShutdown shutdown = new GridSimShutdown("GridSimShutdown",                                              numUser, reportWriterName);        shutdownID_ = shutdown.get_id();    }    /**     * Starts the execution of GridSim simulation.     * It waits for complete execution of all entitities, i.e. until     * all entities threads reach non-RUNNABLE state by exiting from the     * <tt>body()</tt> method. Then, it kills threads of all entities.     * <p>     * <b>Note</b>: This method should be called after all the entities     *              have been setup and added, and their ports are linked.     * @deprecated As of GridSim 2.1, replaced by {@link #startGridSimulation()}     * @throws NullPointerException 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 $none     * @post $none     */    public static void Start() throws NullPointerException {        startGridSimulation();    }    /**     * Starts the execution of GridSim simulation.     * It waits for complete execution of all entitities, i.e. until     * all entities threads reach non-RUNNABLE state by exiting from the     * <tt>body()</tt> method. Then, it kills threads of all entities.     * <p>     * <b>Note</b>: This method should be called after all the entities     *              have been setup and added, and their ports are linked.     * @throws NullPointerException 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 $none     * @post $none     */    public static void startGridSimulation() throws NullPointerException    {        System.out.println("Starting GridSim version 4.0");        try {            Sim_system.run();        }        catch (Sim_exception e)        {            throw new NullPointerException("GridSim.startGridSimulation() :" +                    " Error - you haven't initialized GridSim.");        }    }    /**     * Gets the current simulation time (based on SimJava simulation clock)     * @return The current simulation time from the simulation clock     * @deprecated As of GridSim 2.1, replaced by {@link #clock()}     * @see eduni.simjava.Sim_system#clock()     * @pre $none     * @post $result >= 0.0     */    public static double Clock() {        return clock();    }    /**     * Gets the current simulation time (based on SimJava simulation clock)     * @return The current simulation time from the simulation clock     * @see eduni.simjava.Sim_system#clock()     * @pre $none     * @post $result >= 0.0     */    public static double clock() {        return Sim_system.clock();    }    /**     * Causes the entity to hold for <tt>duration</tt> units of simulation time     * @param duration the amount of time to hold     * @deprecated As of GridSim 2.1, replaced by {@link #gridSimHold(double)}     * @pre $none     * @post $none     */    public void GridSimHold(double duration) {        gridSimHold(duration);    }    /**     * Causes the entity to hold for <tt>duration</tt> units of simulation time     * @param duration the amount of time to hold     * @pre $none     * @post $none     */    public void gridSimHold(double duration)    {        // if duration is -ve, then no use to hold -ve time.        if (duration < 0.0) {            return;        }        super.sim_process(duration);    }    /**     * Stops Grid Simulation (based on SimJava Sim_system.run_stop()).     * This should be ony called if any of the user defined entities     * <b>explicitly</b> want     * to terminate simulation during execution.     * @see eduni.simjava.Sim_system#run_stop()     * @deprecated As of GridSim 2.1, replaced by {@link #stopGridSimulation()}     * @throws NullPointerException 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 $none     * @post $none     */    public static void Stop() throws NullPointerException {        stopGridSimulation();    }    /**     * Stops Grid Simulation (based on SimJava Sim_system.run_stop()).     * This should be ony called if any of the user defined entities     * <b>explicitly</b> want     * to terminate simulation during execution.     * @throws NullPointerException This happens when creating this entity     *                before initializing GridSim package or this entity name is

⌨️ 快捷键说明

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