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

📄 spacesharedwithfailure.java

📁 中間件開發详细说明:清华大学J2EE教程讲义(ppt)-Tsinghua University J2EE tutorial lectures (ppt) [上载源码成为会员下载此源码] [成为VIP会
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // IDENTIFY MACHINE which has a free PE and add this Gridlet to it.        Machine myMachine = resource_.getMachineWithFreePE();        // If a Machine is empty then ignore the rest        if (myMachine == null) {            return false;        }        // gets the list of PEs and find one empty PE        PEList MyPEList = myMachine.getPEList();        int freePE = MyPEList.getFreePEID();        // ALLOCATE IMMEDIATELY        rgl.setGridletStatus(Gridlet.INEXEC);   // change Gridlet status        rgl.setMachineAndPEID(myMachine.getMachineID(), freePE);        // add this Gridlet into execution list        gridletInExecList_.add(rgl);        // Set allocated PE to BUSY status        super.resource_.setStatusPE(PE.BUSY, rgl.getMachineID(), freePE);        // Identify Completion Time and Set Interrupt        int rating = machineRating_[ rgl.getMachineID() ];        double time = forecastFinishTime( rating ,                                          rgl.getRemainingGridletLength() );        int roundUpTime = (int) (time+1);   // rounding up        rgl.setFinishTime(roundUpTime);        // then send this into itself        super.sendInternalEvent(roundUpTime);        return true;    }    /**     * Forecast finish time of a Gridlet.     * <tt>Finish time = length / available rating</tt>     * @param availableRating   the shared MIPS rating for all Gridlets     * @param length   remaining Gridlet length     * @return Gridlet's finish time.     * @pre availableRating >= 0.0     * @pre length >= 0.0     * @post $none     */    private double forecastFinishTime(double availableRating, double length)    {        double finishTime = (length / availableRating);        // This is as a safeguard since the finish time can be extremely        // small close to 0.0, such as 4.5474735088646414E-14. Hence causing        // some Gridlets never to be finished and consequently hang the program        if (finishTime < 1.0) {            finishTime = 1.0;        }        return finishTime;    }    /**     * Checks all Gridlets in the execution list whether they are finished or     * not.     * @pre $none     * @post $none     */    private void checkGridletCompletion()    {        ResGridlet obj = null;        int i = 0;        // NOTE: This one should stay as it is since gridletFinish()        // will modify the content of this list if a Gridlet has finished.        // Can't use iterator since it will cause an exception        while ( i < gridletInExecList_.size() )        {            obj = (ResGridlet) gridletInExecList_.get(i);            if (obj.getRemainingGridletLength() == 0.0)            {                gridletInExecList_.remove(obj);                gridletFinish(obj, Gridlet.SUCCESS);                continue;            }            i++;        }        // if there are still Gridlets left in the execution        // then send this into itself for an hourly interrupt        // NOTE: Setting the internal event time too low will make the        //       simulation more realistic, BUT will take longer time to        //       run this simulation. Also, size of sim_trace will be HUGE!        if (gridletInExecList_.size() > 0) {            super.sendInternalEvent(60.0*60.0);        }    }    /**     * Updates the Gridlet's properties, such as status once a     * Gridlet is considered finished.     * @param rgl   a ResGridlet object     * @param status   the Gridlet status     * @pre rgl != null     * @pre status >= 0     * @post $none     */    private void gridletFinish(ResGridlet rgl, int status)    {        // Set PE on which Gridlet finished to FREE        super.resource_.setStatusPE(PE.FREE, rgl.getMachineID(), rgl.getPEID());        // the order is important! Set the status first then finalize        // due to timing issues in ResGridlet class        rgl.setGridletStatus(status);        rgl.finalizeGridlet();        super.sendFinishGridlet( rgl.getGridlet() );        allocateQueueGridlet();   // move Queued Gridlet into exec list    }    /**     * Handles an operation of canceling a Gridlet in either execution list     * or paused list.     * @param gridletId    a Gridlet ID     * @param userId       the user or owner's ID of this Gridlet     * @param an object of ResGridlet or <tt>null</tt> if this Gridlet is not     *        found     * @pre gridletId > 0     * @pre userId > 0     * @post $none     */    private ResGridlet cancel(int gridletId, int userId)    {        ResGridlet rgl = null;        // Find in EXEC List first        int found = super.findGridlet(gridletInExecList_, gridletId, userId);        if (found >= 0)        {            // update the gridlets in execution list up to this point in time            updateGridletProcessing();            // Get the Gridlet from the execution list            rgl = (ResGridlet) gridletInExecList_.remove(found);            // if a Gridlet is finished upon cancelling, then set it to success            // instead.            if (rgl.getRemainingGridletLength() == 0.0) {                rgl.setGridletStatus(Gridlet.SUCCESS);            }            else {                rgl.setGridletStatus(Gridlet.CANCELED);            }            // Set PE on which Gridlet finished to FREE            super.resource_.setStatusPE( PE.FREE, rgl.getMachineID(),                                        rgl.getPEID() );            allocateQueueGridlet();            return rgl;        }        // Find in QUEUE list        found = super.findGridlet(gridletQueueList_, gridletId, userId);        if (found >= 0)        {            rgl = (ResGridlet) gridletQueueList_.remove(found);            rgl.setGridletStatus(Gridlet.CANCELED);        }        // if not, then find in the Paused list        else        {            found = super.findGridlet(gridletPausedList_, gridletId, userId);            // if found in Paused list            if (found >= 0)            {                rgl = (ResGridlet) gridletPausedList_.remove(found);                rgl.setGridletStatus(Gridlet.CANCELED);            }        }        return rgl;    }    /**     * Sets the status of all Gridlets in this resource to <tt>FAILED</tt>.     * Then sends them back to users, and clean up the relevant lists.     */    public void setGridletsFailed()    {        ResGridlet rgl;        int gridletPausedList_size = gridletPausedList_.size();        int gridletInExecList_size = gridletInExecList_.size();        int gridletQueueList_size = gridletQueueList_.size();        // start with the gridlet paused list.        for (int i = 0; i<gridletPausedList_size; i++)        {            rgl = (ResGridlet) gridletPausedList_.get(0);            int status = rgl.getGridletStatus();            // if the gridlet has already finished, then just send it back.            // Otherwise, set status to FAILED_RESOURCE_UNAVAILABLE            if (status != Gridlet.SUCCESS)            {                rgl.setGridletStatus(Gridlet.FAILED_RESOURCE_UNAVAILABLE);            }            rgl.finalizeGridlet();            super.sendFinishGridlet(rgl.getGridlet());            gridletPausedList_.remove(0);        }        updateGridletProcessing();        // go on with the gridlet in exec list.        for (int i = 0; i < gridletInExecList_size; i++)        {            rgl = (ResGridlet) gridletInExecList_.get(0);            int status = rgl.getGridletStatus();            // if the gridlet has already finished, then just send it back.            // Otherwise, set status to FAILED_RESOURCE_UNAVAILABLE            if (status != Gridlet.SUCCESS)            {                rgl.setGridletStatus(Gridlet.FAILED_RESOURCE_UNAVAILABLE);            }            rgl.finalizeGridlet();            super.sendFinishGridlet(rgl.getGridlet());            gridletInExecList_.remove(0);        }        // finally, the gridlet in queue list.        for (int i = 0; i < gridletQueueList_size; i++)        {            rgl = (ResGridlet) gridletQueueList_.get(0);            int status = rgl.getGridletStatus();            // if the gridlet has already finished, then just send it back.            // Otherwise, set status to FAILED_RESOURCE_UNAVAILABLE            if (status != Gridlet.SUCCESS)            {                rgl.setGridletStatus(Gridlet.FAILED_RESOURCE_UNAVAILABLE);            }            rgl.finalizeGridlet();            super.sendFinishGridlet(rgl.getGridlet());            gridletQueueList_.remove(0);        }    }    /**     * Sets the status of all Gridlets in this machine to <tt>FAILED</tt>.     * Then sends them back to users, and clean up the relevant lists.     * @param failedMachID  the id of the failed machine     */    public void setGridletsFailed(int failedMachID)    {        /***************        // Uncomment this to get more info on the progress of sims        System.out.println("################# " + super.get_name() +            ". Cleaning gridlets in InExec list which are being executed in the failed machines." +            ". gridletInExecList_.size (including all the machines of the resource): " +            gridletInExecList_.size());        ****************/        int gridletInExecList_size = gridletInExecList_.size();        ResGridlet rgl;        // go on with the gridlet in InExec list.        int machID;        for (int i = 0; i < gridletInExecList_size; i++) {            rgl = (ResGridlet) gridletInExecList_.get(0);            machID = rgl.getMachineID();            // only fail gridlets allocated to the machines which have failed            if (machID == failedMachID)            {                int status = rgl.getGridletStatus();                // if the gridlet has already finished, then just send it back.                // Otherwise, set status to FAILED                if (status != Gridlet.SUCCESS)                {                    rgl.setGridletStatus(Gridlet.FAILED);                }                rgl.finalizeGridlet();                super.sendFinishGridlet(rgl.getGridlet());                gridletInExecList_.remove(0);            }        }    }} // end class

⌨️ 快捷键说明

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