* 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();
}
}