[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Selectors and Probes
From: |
Marcus G. Daniels |
Subject: |
Re: Selectors and Probes |
Date: |
27 Mar 2000 11:52:15 -0800 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "CS" == Charles Staelin <address@hidden> writes:
CS> Is it safe to assume that the flag should be false when creating a
CS> selector for any method I've defined in my Java code, and true
CS> otherwise (i.e., for methods defined in the Swarm layer)?
Yes. All that flag does is let you use Objective C style selector
names like "create:". In Java, there aren't key/value methods,
like "methodName: aZone key1: value1 key2: value2" so whenever that
occurs in Swarm it looks like "methodName$key1$key2 (aZone, value1, value2)"
in Java.
CS> The second involves setting a probe. The following code results
CS> in the runtime errors which follow it.
It's arguably a bug in Swarm -- I need to think about what to do about it.
Meanwhile, here's another way to get the Probe:
VarProbe makeProbeForVariable (String varName) {
VarProbeC vProbeC =
((VarProbeC) (new VarProbeCImpl (new VarProbeImpl ()).
createBegin (getZone ())));
vProbeC.setProbedVariable (varName);
vProbeC.setProbedClass (getClass ());
return (VarProbe) vProbeC.createEnd ();
}
Here's a modified version of your code that can be compiled and run:
// ObserverSwarm.java The observer swarm is collection of objects that
// are used to run and observe the ModelSwarm that actually comprises
// the simulation.
import swarm.Globals;
import swarm.Selector;
import swarm.defobj.Zone;
import swarm.defobj.ZoneImpl;
import swarm.gui.Colormap;
import swarm.gui.ColormapImpl;
import swarm.gui.ZoomRaster;
import swarm.gui.ZoomRasterImpl;
import swarm.space.Value2dDisplay;
import swarm.space.Value2dDisplayImpl;
import swarm.space.Object2dDisplay;
import swarm.space.Object2dDisplay;
import swarm.space.Object2dDisplayImpl;
import swarm.simtoolsgui.GUISwarm;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.activity.ActionGroup;
import swarm.activity.ActionGroupImpl;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.objectbase.Swarm;
import swarm.objectbase.SwarmImpl;
import swarm.objectbase.EmptyProbeMap;
import swarm.objectbase.EmptyProbeMapImpl;
import swarm.objectbase.VarProbe;
import swarm.objectbase.VarProbeC;
import swarm.objectbase.VarProbeImpl;
import swarm.objectbase.VarProbeCImpl;
import swarm.collections.ListImpl;
public class ObserverSwarm extends GUISwarmImpl {
// Declare the display parameters and their default values.
public int displayFrequency = 1;
// Declare other variables local to ObserverSwarm.
ZoomRaster worldRaster;
Value2dDisplay foodDisplay;
Object2dDisplay bugDisplay;
ScheduleImpl displaySchedule;
EmptyProbeMapImpl probeMap;
VarProbe vProbe;
VarProbe makeProbeForVariable (String varName) {
VarProbeC vProbeC =
((VarProbeC) (new VarProbeCImpl (new VarProbeImpl ()).
createBegin (getZone ())));
vProbeC.setProbedVariable (varName);
vProbeC.setProbedClass (getClass ());
return (VarProbe) vProbeC.createEnd ();
}
VarProbe makeProbeForVariableX (String varName) {
return getProbeForVariable (varName);
}
// This is the constructor for a new ObserverSwarm.
public ObserverSwarm (Zone azone) {
// Use the parent class to create an observer swarm.
super (azone);
// Build a custom probe map. Without a probe map, the default
// is to show all variables and messages. Here we choose to
// customize the appearance of the probe, giving a nicer
// interface.
// Create the probe map and give it the ObserverSwarm class.
probeMap = new EmptyProbeMapImpl (azone, getClass());
System.out.println("before");
// Now add probes for the variables we wish to probe.
vProbe = makeProbeForVariable ("displayFrequency");
System.out.println("next");
probeMap.addProbe(vProbe);
System.out.println("after");
// And finaly install our probe into the probeLibrary. Note
// that this library object was automatically created by
// initSwarm.
// Globals.env.probeLibrary.setProbeMap$For(probeMap, getClass());
}
public Object buildObjects () {
super.buildObjects ();
Globals.env.createProbeDisplay (this);
return this;
}
public Activity activateIn (Swarm swarmContext) {
super.activateIn (swarmContext);
return getActivity ();
}
static void main (String []args) {
Globals.env.initSwarm ("test", "0.0", "address@hidden", args);
ObserverSwarm observerSwarm = new ObserverSwarm (Globals.env.globalZone);
observerSwarm.buildObjects ();
observerSwarm.buildActions ();
observerSwarm.activateIn (null);
observerSwarm.go ();
observerSwarm.drop ();
}
}
==================================
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.