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

📄 timesharedwithfailure.java

📁 中間件開發详细说明:清华大学J2EE教程讲义(ppt)-Tsinghua University J2EE tutorial lectures (ppt) [上载源码成为会员下载此源码] [成为VIP会
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @param   ack   an acknowledgement, i.e. <tt>true</tt> if wanted to know     *        whether this operation is success or not, <tt>false</tt>     *        otherwise (don't care)     * @pre gridletId > 0     * @pre userId > 0     * @post $none     */    public void gridletPause(int gridletId, int userId, boolean ack)    {        boolean status = false;        // find this Gridlet in the execution list        int found = super.findGridlet(gridletInExecList_, gridletId, userId);        if (found >= 0)        {            // update Gridlets in execution list up to this point in time            updateGridletProcessing();            // get a Gridlet from execution list            ResGridlet rgl = (ResGridlet) gridletInExecList_.remove(found);            // if a Gridlet is finished upon pausing, then set it to success            // instead.            if (rgl.getRemainingGridletLength() == 0.0)            {                System.out.println(super.resName_                        + ".TimeSharedWithFailure.gridletPause(): Cannot pause"                        + " Gridlet #" + gridletId + " for User #" + userId                        + " since it is FINISHED.");                gridletFinish(rgl, Gridlet.SUCCESS);            }            else            {                status = true;                rgl.setGridletStatus(Gridlet.PAUSED);                // add the Gridlet into the paused list                gridletPausedList_.add(rgl);                System.out.println(super.resName_ +                ".TimeSharedWithFailure.gridletPause(): Gridlet #" + gridletId +                " with User #" + userId + " has been sucessfully PAUSED.");            }            // forecast all Gridlets in the execution list            forecastGridlet();        }        else   // if not found in the execution list        {            System.out.println(super.resName_ +                    ".TimeSharedWithFailure.gridletPause(): Cannot find " +                    "Gridlet #" + gridletId + " for User #" + userId);        }        // sends back an ack        if (ack == true)        {            super.sendAck(GridSimTags.GRIDLET_PAUSE_ACK, status,                          gridletId, userId);        }    }    /**     * Moves a Gridlet from this GridResource entity to a different one.     * This method will search in both the execution and paused list.     * The User ID is important as many Users might have the same Gridlet ID     * in the lists.     * <p>     * If a Gridlet has finished beforehand, then this method will send back     * the Gridlet to sender, i.e. the <tt>userId</tt> and sets the     * acknowledgment to false (if required).     *     * @param gridletId    a Gridlet ID     * @param userId       the user or owner's ID of this Gridlet     * @param destId       a new destination GridResource ID for this Gridlet     * @param   ack   an acknowledgement, i.e. <tt>true</tt> if wanted to know     *        whether this operation is success or not, <tt>false</tt>     *        otherwise (don't care)     * @pre gridletId > 0     * @pre userId > 0     * @pre destId > 0     * @post $none     */    public void gridletMove(int gridletId, int userId, int destId, boolean ack)    {        // cancel the Gridlet first        ResGridlet rgl = cancel(gridletId, userId);        // If no found then print an error msg        if (rgl == null)        {            System.out.println(super.resName_ +                    ".TimeSharedWithFailure.gridletMove(): Cannot find " +                    "Gridlet #" + gridletId + " for User #" + userId);            if (ack == true)   // sends ack that this operation fails            {                super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false,                              gridletId, userId);            }            return;        }        // if found        rgl.finalizeGridlet();   // finalise Gridlet        Gridlet gl = rgl.getGridlet();        // if a Gridlet has finished execution        if (gl.getGridletStatus() == Gridlet.SUCCESS)        {            System.out.println(super.resName_                    + ".TimeSharedWithFailure.gridletMove(): Cannot move"                    + " Gridlet #" + gridletId + " for User #" + userId                    + " since it has FINISHED.");            if (ack == true)            {                super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId,                              userId);            }            super.sendFinishGridlet(gl);   // sends the Gridlet back to sender        }        // moves this Gridlet to another GridResource entity        else {            super.gridletMigrate(gl, destId, ack);        }    }    /**     * Resumes a Gridlet only in the paused list.     * The User ID is important as many Users might have the same Gridlet ID     * in the lists.     * @param gridletId    a Gridlet ID     * @param userId       the user or owner's ID of this Gridlet     * @param   ack   an acknowledgement, i.e. <tt>true</tt> if wanted to know     *        whether this operation is success or not, <tt>false</tt>     *        otherwise (don't care)     * @pre gridletId > 0     * @pre userId > 0     * @post $none     */    public void gridletResume(int gridletId, int userId, boolean ack)    {        boolean success = false;        // finds in the execution list first        int found = super.findGridlet(gridletPausedList_, gridletId, userId);        if (found >= 0)        {            // need to update Gridlets in execution up to this point in time            updateGridletProcessing();            // remove a Gridlet from paused list and change the status            ResGridlet rgl = (ResGridlet) gridletPausedList_.remove(found);            rgl.setGridletStatus(Gridlet.RESUMED);            // add the Gridlet back to in execution list            gridletInExecList_.add(rgl);            // then forecast Gridlets in execution list            forecastGridlet();            success = true;            System.out.println(super.resName_ +            ".TimeSharedWithFailure.gridletResume(): Gridlet #" + gridletId +            " with User #" + userId + " has been sucessfully RESUMED.");        }        else  // if no found then prints an error msg        {            System.out.println(super.resName_ +            ".TimeSharedWithFailure.gridletResume(): Cannot find Gridlet #" +            gridletId + " for User #" + userId);        }        // sends back an ack to sender        if (ack == true)        {            super.sendAck(GridSimTags.GRIDLET_RESUME_ACK, success,                          gridletId, userId);        }    }    ////////////////////// PRIVATE METHODS //////////////////////////////    /**     * Updates the execution of all Gridlets for a period of time.     * The time period is determined from the last update time up to the     * current time. Once this operation is successfull, then the last update     * time refers to the current time.     * @pre $none     * @post $none     */    private void updateGridletProcessing()    {        // Identify MI share for the duration (from last event time)        double time = GridSim.clock();        double timeSpan = time - lastUpdateTime_;        // if current time is the same or less than the last update time,        // then ignore        if (timeSpan <= 0.0) {            return;        }        // Update Current Time as the Last Update        lastUpdateTime_ = time;        // update the GridResource load        int size = gridletInExecList_.size();        double load = super.calculateTotalLoad(size);        super.addTotalLoad(load);       // add the current resource load        // if no Gridlets in execution then ignore the rest        if (size == 0) {            return;        }        // gets MI Share for all Gridlets        MIShares shares = getMIShare(timeSpan, size);        ResGridlet obj = null;        // a loop that allocates MI share for each Gridlet accordingly        // In this algorithm, Gridlets at the front of the list        // (range = 0 until MIShares.maxCount-1) will be given max MI value        // For example, 2 PEs and 3 Gridlets. PE #0 processes Gridlet #0        // PE #1 processes Gridlet #1 and Gridlet #2        int i = 0;  // a counter        Iterator iter = gridletInExecList_.iterator();        while ( iter.hasNext() )        {            obj = (ResGridlet) iter.next();            // Updates the Gridlet length that is currently being executed            if (i < shares.maxCount) {                obj.updateGridletFinishedSoFar(shares.max);            }            else {                obj.updateGridletFinishedSoFar(shares.min);            }            i++;   // increments i        }    }    /**     * Identifies MI share (max and min) for all Gridlets in     * a given time duration     * @param timeSpan duration     * @param size    total number of Gridlets in the execution list     * @return  the total MI share that a Gridlet gets for a given     *          <tt>timeSpan</tt>     */    private MIShares getMIShare(double timeSpan, int size)    {        // 1 - localLoad_ = available MI share percentage        double localLoad = super.resCalendar_.getCurrentLoad();        double TotalMIperPE = super.resource_.getMIPSRatingOfOnePE() * timeSpan                              * (1 - localLoad);        // This TimeSharedWithFailure is not Round Robin where each PE for        // 1 Gridlet only.        // a PE can have more than one Gridlet executing.        // minimum number of Gridlets that each PE runs.        int glDIVpe = size / super.totalPE_;        // number of PEs that run one extra Gridlet        int glMODpe = size % super.totalPE_;        // If num Gridlets in execution > total PEs in a GridResource,        // then divide MIShare by the following constraint:        // - obj.max = MIShare of a PE executing n Gridlets        // - obj.min = MIShare of a PE executing n+1 Gridlets        // - obj.maxCount = a threshold number of Gridlets will be assigned to        //                  max MI value.        //        // In this algorithm, Gridlets at the front of the list        // (range = 0 until maxCount-1) will be given max MI value        if (glDIVpe > 0)        {            // this is for PEs that run one extra Gridlet            share_.min = TotalMIperPE / (glDIVpe + 1);            share_.max = TotalMIperPE / glDIVpe;            share_.maxCount = (super.totalPE_ - glMODpe) * glDIVpe;        }        // num Gridlet in Exec < total PEs, meaning it is a        // full PE share: i.e a PE is dedicated to execute a single Gridlet        else        {            share_.max = TotalMIperPE;            share_.min = TotalMIperPE;            share_.maxCount = size;   // number of Gridlet        }        return share_;    }

⌨️ 快捷键说明

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