[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FArguments follow up
From: |
pauljohn |
Subject: |
FArguments follow up |
Date: |
Thu, 19 Jul 2001 00:00:47 -0500 |
I created a test case of the createCall() boilerplate method
that we could eventually stick into Selector or some other
class. I've fiddled this for several hours, and the selector is
created and used, but no matter what I do, I can't get it to
accept the double argument. Can you explain why? (Here I'm just
working with the test case of an argument vector with just the
one double element, but if I can make this work, I can
generalize....)
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.FArgumentsCImpl;
import swarm.defobj.FArguments;
import swarm.defobj.FArgumentsC;
import swarm.Selector;
import swarm.Globals;
public class TestFActionArgs2 extends SwarmImpl {
TestFActionArgs2 (Zone aZone) {
super (aZone);
}
Schedule schedule;
Schedule stopSchedule;
public void stepArg (float val) {
System.out.println ("next @ " + Globals.env.getCurrentTime
() +
" val: " + val);
}
public void end () {
System.out.println ("it just told me to end");
getActivity ().terminate ();
}
public Object buildActions () {
super.buildActions ();
schedule = new ScheduleImpl (this, 1);
stopSchedule = new ScheduleImpl (this, true);
//My Argument Array has only one element, a double:
Object argArray[] = new Object[1];
argArray[0] = new Double(2.5);
//Use the class method in Action (below) to create the FCall
FCall stepCall = Action.createCall (getZone(),
this,"stepArg", argArray);
//Schedule the FAction
schedule.at$createFAction (0,stepCall);
//Use Action (below) to create a call to end the model.
stopSchedule.at$createFAction (10, Action.createCall
(getZone(), this, "end", null));
return this;
}
public Activity activateIn (Swarm swarmContext) {
super.activateIn (swarmContext);
schedule.activateIn (this);
stopSchedule.activateIn (this);
return getActivity ();
}
public static void main (String[] args) {
Globals.env.initSwarm ("TestFActionArgs2", "0.0",
"address@hidden",
args);
TestFActionArgs2 swarm = new TestFActionArgs2
(Globals.env.globalZone);
swarm.buildObjects ();
swarm.buildActions ();
swarm.activateIn (null).run ();
}
}
class Action{
public static FCall createCall (Zone aZone, Object target,
String aMethodName, Object[] inputs){
try {
Selector sel = new Selector (target.getClass(),
aMethodName, false);
FArgumentsC creating = new FArgumentsCImpl (new
FArgumentsImpl ());
System.out.println("Zone" + aZone + " Object: " +
target.getClass() + " MethodName: " + aMethodName + " inputs:"
+ inputs);
creating.createBegin (aZone);
creating.setSelector (sel);
if (inputs != null) processArgs (creating, inputs);
//brute force does not help! try: creating.addDouble (2.5);
return new FCallImpl (aZone, target , sel,
(FArguments) creating.createEnd() );
} catch (Exception e) {
System.out.println ("Exception in createCall");
e.printStackTrace (System.err);
}
return null;
}
static void processArgs (FArgumentsC proto, Object[]
inputArray ){
for ( int i =0 ; i < inputArray.length ; i++ ){
Object obj = inputArray[i];
double val = ((Double) obj).doubleValue();
proto.addDouble(val);
System.out.println("Supposedly, we just added a double
argument: " + val);
}
}
}
The output from this looks like this:
address@hidden Object: class TestFActionArgs2
MethodName: stepArg inputs:[Ljava.lang.Object;@80688a0
Supposedly, we just added a double argument: 2.5
address@hidden Object: class TestFActionArgs2
MethodName: end inputs:null
next @ 0 val: 0.0
next @ 1 val: 0.0
next @ 2 val: 0.0
next @ 3 val: 0.0
next @ 4 val: 0.0
next @ 5 val: 0.0
next @ 6 val: 0.0
next @ 7 val: 0.0
next @ 8 val: 0.0
next @ 9 val: 0.0
next @ 10 val: 0.0
it just told me to end
--
Paul E. Johnson email: address@hidden
Dept. of Political Science
http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
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.
- FArguments follow up,
pauljohn <=