[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Compound Actions
From: |
Marcus G. Daniels |
Subject: |
Re: Compound Actions |
Date: |
29 Oct 1999 18:52:23 -0700 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "LM" == LIK MUI <address@hidden> writes:
LM> I am trying to have an "initial action" and then a set of
LM> different repeating actions:
Below is an example of the approach Benedikt describes.
Some highlights:
1) The `event' Schedule has a relative time (vs. its activation) and
a repeat interval. Note the event schedule starts two time steps
after the when the event schedule *tiling* starts. The
output of this program looks like this:
start @ 10
step @ 12
step @ 15
step @ 18
stopping @ 20
What you see is the first interval starting at timestep 10
and from then on there are tiles of 3 timestep units with the
first event within the tile is 2 timesteps in. The
error you got was telling you that you starting offset was
bigger than the tile.
2) A `manager' schedule. This schedule is used to start the
the repeating interval at timestep 10, and to stop it
at timestep 20.
In the `start' method note the more complicated Schedule setup.
In the Java layer, the notion of object `phases' are preserved by
introducing variant names for class implementations. In
Objective C, the type name for the class in `Creating' phase is
the same as the type name for `Using' phase. Java makes strict
distinctions between these types / method-lists.
3) In Java, not only do phases have distinct names but so
do classes and interfaces (unlike the unified class / protocol
in Objective C Swarm), e.g. "Swarm" for the interface
and "SwarmImpl" for the class. Java calls the notion
of named method lists "interfaces" (in Objective C they are
called "protocols").
4) In Java, the bad things that can happen have explicit
contingencies, e.g. the try/catch of exceptions for
method selector lookup.
import swarm.Globals;
import swarm.objectbase.SwarmImpl;
import swarm.objectbase.Swarm;
import swarm.activity.Schedule;
import swarm.activity.ScheduleCImpl;
import swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.defobj.Zone;
import swarm.Selector;
import swarm.SignatureNotFoundException;
import swarm.NonUniqueMethodSignatureException;
public class SequenceExample extends SwarmImpl {
Schedule managerSchedule;
Schedule eventSchedule;
SequenceExample (Zone aZone) {
super (aZone);
}
public Object start () {
System.out.println ("start @ " + Globals.env.getCurrentTime ());
{
ScheduleCImpl schedule = new ScheduleCImpl (new ScheduleImpl ());
schedule.createBegin (getZone ());
schedule.setRepeatInterval (3);
schedule.setRelativeTime (true);
eventSchedule = (Schedule) schedule.createEnd ();
}
try {
eventSchedule.at$createActionTo$message
(2, this, new Selector (getClass (), "step", false));
} catch (SignatureNotFoundException e) {
e.printStackTrace ();
} catch (NonUniqueMethodSignatureException e) {
e.printStackTrace ();
}
eventSchedule.activateIn (this);
return this;
}
public Object step () {
System.out.println ("step @ " + Globals.env.getCurrentTime ());
return this;
}
public Object stop () {
System.out.println ("stopping @ " + Globals.env.getCurrentTime ());
Globals.env.getCurrentSwarmActivity ().terminate ();
return this;
}
public Object buildActions () {
Zone aZone = getZone ();
managerSchedule = new ScheduleImpl (aZone);
try {
managerSchedule.at$createActionTo$message
(10, this, new Selector (getClass (), "start", false));
managerSchedule.at$createActionTo$message
(20, this, new Selector (getClass (), "stop", false));
} catch (SignatureNotFoundException e) {
e.printStackTrace ();
} catch (NonUniqueMethodSignatureException e) {
e.printStackTrace ();
}
return this;
}
public Activity activateIn (Swarm swarmContext) {
super.activateIn (swarmContext);
managerSchedule.activateIn (this);
return getActivity ();
}
public static void main (String[] args) {
// Swarm initialization: all Swarm apps must call this first.
Globals.env.initSwarm ("sequence", "0.0", "address@hidden", args);
SequenceExample modelSwarm = new SequenceExample (Globals.env.globalZone);
modelSwarm.buildActions ();
modelSwarm.activateIn (null).run ();
}
}
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.