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

📄 gridsim.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *                <tt>null</tt> or empty     * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[],     *          String)     * @see eduni.simjava.Sim_system#run_stop()     * @pre $none     * @post $none     */    public static void stopGridSimulation() throws NullPointerException    {        try {            Sim_system.run_stop();        }        catch (Sim_exception e)        {            throw new NullPointerException("GridSim.stopGridSimulation() : " +                    "Error - can't stop Grid Simulation.");        }    }    /**     * Gets an object belong to the first event <b>CURRENTLY</b> waiting in this     * entity's deferred queue (incoming buffer).     * If there are no events, then wait indefinitely for an event to arrive.     * @return An event's object     * @deprecated As of GridSim 2.1, replaced by {@link #receiveEventObject()}     * @pre $none     * @post $none     */    protected Object ReceiveEventObject() {        return receiveEventObject();    }    /**     * Gets an object belong to the first event <b>CURRENTLY</b> waiting in this     * entity's deferred queue (incoming buffer).     * If there are no events, then wait indefinitely for an event to arrive.     * @return An event's object     * @pre $none     * @post $none     */    protected Object receiveEventObject()    {        Sim_event ev = new Sim_event();        super.sim_get_next(ev);        return ev.get_data();    }    /**     * Gets an object belong to the first event <b>CURRENTLY</b> waiting in     * the given port.     * If there are no events, then wait indefinitely for an event to arrive.     * @param sourcePort a Sim_port object which is used to connect entities     *                   for event passing     * @return An event's data or <tt>null</tt> if the source port is     *         empty.     * @deprecated As of GridSim 2.1, replaced by     *             {@link #receiveEventObject(Sim_port)}     * @see eduni.simjava.Sim_port     * @pre sourcePort != null     * @post $none     */    protected Object ReceiveEventObject(Sim_port sourcePort) {        return receiveEventObject(sourcePort);    }    /**     * Gets an object belong to the first event <b>CURRENTLY</b> waiting in     * the given port.     * If there are no events, then wait indefinitely for an event to arrive.     * @param sourcePort a Sim_port object which is used to connect entities     *                   for event passing     * @return An event's data or <tt>null</tt> if the source port is     *         empty.     * @see eduni.simjava.Sim_port     * @pre sourcePort != null     * @post $none     */    protected Object receiveEventObject(Sim_port sourcePort)    {        if (sourcePort == null) {            return null;        }        Sim_event ev = new Sim_event();        super.sim_get_next( new Sim_from_port(sourcePort), ev );        return ev.get_data();    }    /**     * Sends a Gridlet to the destination GridResource ID <tt>without</tt>     * any delay. An acknowledgement to denote the successful of this method     * is by default <tt>off or false</tt>.     *     * @param gl       a Gridlet object to be sent     * @param resID    an unique resource ID     * @return <tt>true</tt> if this Gridlet has been submitted to the     *         destination GridResource, <tt>false</tt> otherwise.     *         Submitting a Gridlet can be failed for the one or more     *         following reasons:     *         <ul>     *              <li> if the acknowledgment status in the parameter of this     *                   method is set to <tt>false</tt>     *              <li> if a GridResource ID doesn't exist     *              <li> if a Gridlet ID doesn't exist     *              <li> if a Gridlet's user ID doesn't exist     *              <li> if a Gridlet object is <tt>null</tt> or empty;     *              <li> if a Gridlet object has <tt>finished</tt> executing     *                   beforehand     *         </ul>     *     * @deprecated As of GridSim 2.1, replaced by {@link #gridletSubmit(Gridlet,     *             int)}     * @pre gl != null     * @pre resID >= 0     * @post $none     */    protected boolean GridletSubmit(Gridlet gl, int resID) {        return gridletSubmit(gl, resID);    }    /**     * Sends a Gridlet to the destination GridResource ID <tt>without</tt>     * any delay. An acknowledgement to denote the successful of this method     * is by default <tt>off or false</tt>.     *     * @param gl       a Gridlet object to be sent     * @param resID    an unique resource ID     * @return <tt>true</tt> if this Gridlet has been submitted to the     *         destination GridResource, <tt>false</tt> otherwise.     *         Submitting a Gridlet can be failed for the one or more     *         following reasons:     *         <ul>     *              <li> if the acknowledgment status in the parameter of this     *                   method is set to <tt>false</tt>     *              <li> if a GridResource ID doesn't exist     *              <li> if a Gridlet ID doesn't exist     *              <li> if a Gridlet's user ID doesn't exist     *              <li> if a Gridlet object is <tt>null</tt> or empty;     *              <li> if a Gridlet object has <tt>finished</tt> executing     *                   beforehand     *         </ul>     * @pre gl != null     * @pre resID >= 0     * @post $none     */    protected boolean gridletSubmit(Gridlet gl, int resID) {        return gridletSubmit(gl, resID, GridSimTags.SCHEDULE_NOW, false);    }    /**     * Sends a Gridlet to the destination GridResource ID <tt>with</tt>     * a specified delay.     *     * @param gl            a Gridlet object to be sent     * @param resourceID    an unique resource ID     * @param delay         delay time or <tt>0.0</tt> if want to execute NOW     * @param ack           an acknowledgment status. <tt>true</tt> if want to     *                      know the result of this method, <tt>false</tt>     *                      otherwise or don't care.     * @return <tt>true</tt> if this Gridlet has been submitted to the     *         destination GridResource, <tt>false</tt> otherwise.     *         Submitting a Gridlet can be failed for the one or more     *         following reasons:     *         <ul>     *              <li> if the acknowledgment status in the parameter of this     *                   method is set to <tt>false</tt>     *              <li> if a GridResource ID doesn't exist     *              <li> if a Gridlet ID doesn't exist     *              <li> if a Gridlet's user ID doesn't exist     *              <li> if the delay time is negative     *              <li> if a Gridlet object is <tt>null</tt> or empty;     *              <li> if a Gridlet object has <tt>finished</tt> executing     *                   beforehand     *         </ul>     * @see gridsim.Gridlet#isFinished()     * @see gridsim.GridSim#gridletReceive()     * @pre gl != null     * @pre resourceID >= 0     * @pre delay >= 0.0     * @post $none     */    protected boolean gridletSubmit(Gridlet gl, int resourceID,                                    double delay, boolean ack)    {        // with default net service level, i.e. 0        return gridletSubmit(gl, resourceID, delay, ack, 0);    }    /**     * Sends a Gridlet to the destination GridResource ID <tt>with</tt>     * a specified delay.     *     * @param gl            a Gridlet object to be sent     * @param resourceID    an unique resource ID     * @param delay         delay time or <tt>0.0</tt> if want to execute NOW     * @param ack           an acknowledgment status. <tt>true</tt> if want to     *                      know the result of this method, <tt>false</tt>     *                      otherwise or don't care.     * @param netServiceLevel this can be set so that network entities can     * provide differentiated services if they are supported.     * @return <tt>true</tt> if this Gridlet has been submitted to the     *         destination GridResource, <tt>false</tt> otherwise.     *         Submitting a Gridlet can be failed for the one or more     *         following reasons:     *         <ul>     *              <li> if the acknowledgment status in the parameter of this     *                   method is set to <tt>false</tt>     *              <li> if a GridResource ID doesn't exist     *              <li> if a Gridlet ID doesn't exist     *              <li> if a Gridlet's user ID doesn't exist     *              <li> if the delay time is negative     *              <li> if a Gridlet object is <tt>null</tt> or empty;     *              <li> if a Gridlet object has <tt>finished</tt> executing     *                   beforehand     *         </ul>     * @see gridsim.Gridlet#isFinished()     * @see gridsim.GridSim#gridletReceive()     * @pre gl != null     * @pre resourceID >= 0     * @pre delay >= 0.0     * @post $none     */    protected boolean gridletSubmit(Gridlet gl, int resourceID,                                    double delay, boolean ack,                                    int netServiceLevel)    {        // checks whether a Gridlet is empty or delay is -ve        if (gl == null || delay < 0.0 || netServiceLevel < 0) {            return false;        }        // checks whether a Gridlet has finished executing before        String errorMsg = super.get_name() + ".gridletSubmit(): ";        if (gl.isFinished() == true)        {            System.out.println(errorMsg + "Error - Gridlet #" +                               gl.getGridletID() + " for User #" +                               gl.getUserID() + " is already finished.");            return false;        }        boolean valid = false;        try        {            valid = validateValue(errorMsg, gl.getGridletID(),                                  gl.getUserID(), resourceID);            // if any of the above value invalid, then return            if (valid == false) {                return false;            }            // sends the gridlet to a destination GridResource id with ACK            if (ack == true)            {                send(super.output, delay, GridSimTags.GRIDLET_SUBMIT_ACK,                     new IO_data(gl, gl.getGridletFileSize(), resourceID,                     netServiceLevel)                );                valid = getBooleanResult(gl.getGridletID(),                                         GridSimTags.GRIDLET_SUBMIT_ACK);            }            else   // sends without ACK            {                valid = false;                send(super.output, delay, GridSimTags.GRIDLET_SUBMIT,                     new IO_data(gl, gl.getGridletFileSize(), resourceID,                     netServiceLevel)                );            }        }        catch (Sim_exception sim)        {            valid = false;            System.out.println(errorMsg + "Error from SimJava occurs.");            System.out.println( sim.getMessage() );        }        catch (Exception e)        {            valid = false;            System.out.println(errorMsg + "Error occurs.");            System.out.println( e.getMessage() );        }        return valid;    }    /**     * Gets the result from an incoming event buffer that matches     * the given Gridlet ID and tag name     * @param gridletID     a gridlet ID     * @param matchingTag   a matching tag name     * @return result of the selected event that matches the criteria     * @pre $none     * @post $none     */    private boolean getBooleanResult(int gridletID, int matchingTag)    {        // waiting for a response back from the GridResource        FilterResult tag = new FilterResult(gridletID, matchingTag);        // only look for ack for same Gridlet ID        Sim_event ev = new Sim_event();        super.sim_get_next(tag, ev);        boolean result = false;        try        {            int[] array = (int[]) ev.get_data();            if (array[RESULT] == GridSimTags.TRUE) {                result = true;            }        }        catch (Exception e) {            result = false;        }        return result;    }    /**     * Gets the result from an incoming event buffer that matches     * the given Gridlet ID and tag name     * @param gridletID     a gridlet ID     * @param matchingTag   a matching tag name     * @return result of the selected event that matches the criteria     * @pre $none     * @post $none     */    private int getIntResult(int gridletID, int matchingTag)    {        // waiting for a response back from the GridResource        FilterResult tag = new FilterResult(gridletID, matchingTag);        // only look for ack for same Gridlet ID        Sim_event ev = new Sim_event();        super.sim_get_next(tag, ev);        int result = -1;        try        {

⌨️ 快捷键说明

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