[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] Time efficiency of at$createActionTo$message
From: |
Marcus G. Daniels |
Subject: |
Re: [Swarm-Support] Time efficiency of at$createActionTo$message |
Date: |
Tue, 18 Feb 2003 09:49:57 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.3b) Gecko/20030211 |
Marcus G. Daniels wrote:
use createFActionForEachHomogeneous$call. This avoids all
indirection for the callout to a Java method.
An example..
import swarm.objectbase.SwarmImpl;
import swarm.defobj.Zone;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.objectbase.Swarm;
import swarm.activity.Activity;
import swarm.defobj.FCallImpl;
import swarm.defobj.FCall;
import swarm.defobj.FArgumentsImpl;
import swarm.defobj.FArguments;
import swarm.Selector;
import swarm.Globals;
import java.util.List;
import java.util.LinkedList;
public class TestFActionForEach extends SwarmImpl {
class Agent {
int id;
Agent (int id) {
this.id = id;
}
public void stepAgent (long val) {
System.out.println ("step # " + id + " @ " +
Globals.env.getCurrentTime ());
}
}
TestFActionForEach (Zone aZone) {
super (aZone);
}
Schedule schedule;
Schedule stopSchedule;
List agentList;
public void stopMe () {
getActivity ().terminate ();
}
public FCall createCall (Object target, String name) {
try {
Selector sel = new Selector (target.getClass (), name, false);
FArguments fa = new FArgumentsImpl (getZone (), sel);
return new FCallImpl (getZone (), target, sel, fa);
} catch (Exception e) {
e.printStackTrace (System.err);
System.exit (1);
}
return null;
}
public Object buildObjects () {
super.buildObjects ();
agentList = new LinkedList ();
agentList.add (new Agent (1));
agentList.add (new Agent (2));
return this;
}
public Object buildActions () {
super.buildActions ();
schedule = new ScheduleImpl (this, 1);
stopSchedule = new ScheduleImpl (this, true);
schedule.at$createFActionForEachHomogeneous$call
(0,
agentList,
createCall (new Agent (-1), "stepAgent"));
stopSchedule.at$createFAction (10, createCall (this, "stopMe"));
return this;
}
public Activity activateIn (Swarm swarmContext) {
super.activateIn (swarmContext);
schedule.activateIn (this);
stopSchedule.activateIn (this);
return getActivity ();
}
static void main (String[] args) {
Globals.env.initSwarm ("TestFActionForEach", "0.0",
"address@hidden",
args);
TestFActionForEach test = new TestFActionForEach
(Globals.env.globalZone);
test.buildObjects ();
test.buildActions ();
test.activateIn (null).run ();
}
}
RE: [Swarm-Support] Time efficiency of at$createActionTo$message, Marshall, James A R, 2003/02/18
RE: [Swarm-Support] Time efficiency of at$createActionTo$message, Marshall, James A R, 2003/02/18
RE: [Swarm-Support] Time efficiency of at$createActionTo$message, Marshall, James A R, 2003/02/19