/* Marcus Daniels August 2, 2001 OJ> It seems that I can't remove Action of a ConcurrentGroup. MGD> How are you acquiring this ConcurrentGroup? The createActionTo$message will have the side-effect of creating ActionConcurrent objects, but it will return ActionTo objects. For example, the program below works for me. */ import swarm.activity.ScheduleImpl; import swarm.activity.Schedule; import swarm.activity.Activity; import swarm.activity.ActionTo; import swarm.objectbase.SwarmImpl; import swarm.objectbase.Swarm; import swarm.defobj.Zone; import swarm.Selector; import swarm.Globals; import java.util.LinkedList; import java.util.List; import java.util.Iterator; abstract class Agent { public void step () { System.out.println ("step " + getClass ().getName () + " @ " + Globals.env.getCurrentTime ()); } public void stepA () { System.out.println ("stepA " + getClass ().getName () + " @ " + Globals.env.getCurrentTime ()); } } class Agent1 extends Agent { } class Agent2 extends Agent { } public class RemovalDemoList extends SwarmImpl { RemovalDemoList (Zone aZone) { super (aZone); } Schedule schedule; Agent1 agent1; Agent2 agent2; List actionList; public void clean () { Iterator iterator = actionList.iterator (); while (iterator.hasNext ()) { Object obj = iterator.next (); schedule.remove (obj); } } public Object buildObjects () { super.buildObjects (); agent1 = new Agent1 (); agent2 = new Agent2 (); return this; } public Object buildActions () { super.buildActions (); actionList = new LinkedList (); schedule = new ScheduleImpl (getZone (), false); try { Selector stepSel = new Selector (Agent.class, "step", false); Selector stepSela = new Selector (Agent.class, "stepA", false); Selector cleanSel = new Selector (getClass (), "clean", false); actionList.add (schedule.at$createActionTo$message (0, agent1, stepSel)); actionList.add (schedule.at$createActionTo$message (10, agent2, stepSel)); schedule.at$createActionTo$message (10, this, cleanSel); actionList.add (schedule.at$createActionTo$message (100, agent1, stepSel)); actionList.add (schedule.at$createActionTo$message (110, agent2, stepSel)); actionList.add (schedule.at$createActionTo$message (110, agent2, stepSela)); actionList.add (schedule.at$createActionTo$message (200, agent1, stepSel)); actionList.add (schedule.at$createActionTo$message (210, agent2, stepSel)); Globals.env.xfprint (schedule); } catch (Exception e) { e.printStackTrace (System.err); System.exit (1); } return this; } public Activity activateIn (Swarm swarmContext) { super.activateIn (swarmContext); schedule.activateIn (this); return getActivity (); } static void main (String args[]) { Globals.env.initSwarm ("RemovalDemoList", "0.0", "bug-swarm@swarm.org", args); RemovalDemoList demo = new RemovalDemoList (Globals.env.globalZone); demo.buildObjects (); demo.buildActions (); demo.activateIn (null).run (); } }