[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Hypothetical Question
From: |
Marcus G. Daniels |
Subject: |
Re: Hypothetical Question |
Date: |
09 Oct 2000 17:37:58 -0700 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "D4" == Doug Donalson <address@hidden> writes:
D4> Question: Suppose I am executing an event at time 1262.536894 and
D4> in the process a new event is generated with the exact time value
D4> as the event presently being executed. How does the scheduler
D4> handle this?
It should work. You're using the latest swarm.dll, yes? Here's a
test case that does such a side-effect same-time schedule:
import swarm.Globals;
import swarm.defobj.Zone;
import swarm.objectbase.SwarmImpl;
import swarm.objectbase.Swarm;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.ScheduleC;
import swarm.activity.ScheduleCImpl;
import swarm.activity.ConcurrentScheduleCImpl;
import swarm.activity.ConcurrentSchedule;
import swarm.activity.Activity;
import swarm.activity.ScheduleActivity;
import swarm.Selector;
import java.text.DecimalFormat;
import java.util.Arrays;
public class DoubleScheduleSame extends SwarmImpl {
Schedule schedule;
ScheduleActivity scheduleActivity;
Schedule stopSchedule;
DecimalFormat formatter;
public Selector stepSel;
int sameStepCount = 0;
double timestep = 1262.536894;
final int precision = 1000000;
final int digits =
(int) Math.rint (Math.log ((double) precision) / Math.log (10));
DoubleScheduleSame (Zone aZone) {
super (aZone);
ConcurrentScheduleCImpl typeProto =
new ConcurrentScheduleCImpl ();
Object concGroupType;
ScheduleC scheduleProto;
typeProto.customizeBegin (aZone);
typeProto.setAutoDrop (true);
concGroupType = typeProto.customizeEnd ();
scheduleProto = new ScheduleCImpl (new ScheduleImpl ());
scheduleProto.createBegin (aZone);
scheduleProto.setAutoDrop (true);
scheduleProto.setConcurrentGroupType (concGroupType);
schedule = (Schedule) scheduleProto.createEnd ();
formatter = (DecimalFormat) DecimalFormat.getInstance ();
char ary[] = new char[digits];
Arrays.fill (ary, '0');
formatter.applyPattern (new String (ary));
try {
stepSel = new Selector (getClass (), "step", false);
} catch (Exception e) {
e.printStackTrace (System.err);
System.exit (1);
}
}
public Object step () {
int subtval = (Globals.env.getCurrentTime () + 5) / 10;
System.out.println (formatter.format (scheduleActivity.getCurrentTime ())
+ "." +
formatter.format (subtval));
double lastTimestep = timestep;
int inc = Globals.env.uniformIntRand.getIntegerWithMin$withMax (0, 99);
timestep = timestep + (double) inc / (100 * precision);
if (timestep == lastTimestep)
System.out.println ("same " + timestep);
else
at (timestep, stepSel);
return this;
}
void at (double val, Selector sel) {
ConcurrentSchedule cschedule =
(ConcurrentSchedule) schedule.insertGroup ((int) val);
cschedule.
at$createActionTo$message
((int) ((val - Math.floor (val)) * precision * 10), this, sel);
}
public Activity activateIn (Swarm swarmContext) {
super.activateIn (swarmContext);
scheduleActivity = (ScheduleActivity) schedule.activateIn (this);
return getActivity ();
}
void go () {
activateIn (null).run ();
}
static void main (String args[]) {
Globals.env.initSwarm ("DoubleScheduleSame", "0.0", "address@hidden",
args);
DoubleScheduleSame modelSwarm =
new DoubleScheduleSame (Globals.env.globalZone);
try {
modelSwarm.at (1262.536894, modelSwarm.stepSel);
} catch (Exception e) {
e.printStackTrace ();
}
modelSwarm.go ();
}
}
==================================
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.