分享

GridSim例子三的另外一部分:Test实体

 炀炀的妈妈 2012-10-30
 * Test类制定输入输出实体。Test类监听模拟事件,等待从另一个GridSim实体(Example31)
 * 接收网格作业,然后Test类将这个网格作业再发送回Example3类
 */
 
import java.util.*;
import gridsim.*;
import eduni.simjava.Sim_event;

class Test extends GridSim
{
    /**
     * Allocates a new Test object
     * @param name  the Entity name
     * @param baud_rate  the communication speed
     * @throws Exception This happens when creating this entity before
     *                   initializing GridSim package or the entity name is
     *                   <tt>null</tt> or empty
     * @see gridsim.GridSim#Init(int, Calendar, boolean, String[], String[],
     *          String)
     */
    Test(String name, double baud_rate) throws Exception
    {
        // Don't need to create Input and Output entities if baud_rate is
        // known. GridSim will create them during the super() call.
        super(name, baud_rate);
        System.out.println("... 创建一个Test对象");
    }
    /**
     * Processes one event at one time. Receives a Gridlet object from the
     * other GridSim entity. Modifies the Gridlet's status and sends it back
     * to the sender.
     */
    public void body()
    {
        int entityID;
        Sim_event ev = new Sim_event();
        Gridlet gridlet;
        // Gets one event at a time
        for ( sim_get_next(ev); ev.get_tag() != GridSimTags.END_OF_SIMULATION;
                sim_get_next(ev) )
        {
            // Gets the Gridlet object sent by Example3 class
            gridlet = (Gridlet) ev.get_data();
            // Change the Gridlet status, meaning that the Gridlet has been
            // received successfully
            try {
                gridlet.setGridletStatus(Gridlet.SUCCESS);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("... 在Test.body()内 => 收到网格作业 "+
                    gridlet.getGridletID() + " 从对象Example31中");
            // get the sender ID, i.e Example3 class
            entityID = ev.get_src();
            // sends back the modified Gridlet to the sender
            super.send(entityID, GridSimTags.SCHEDULE_NOW,
                       GridSimTags.GRIDLET_RETURN, gridlet);
        }
        // when simulation ends, terminate the Input and Output entities
        super.terminateIOEntities();
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多