|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.engine.SimState
SimState represents the simulation proper. Your simulations generally will contain one top-level object which subclasses from SimState.
A SimState contains the random number generator and the simulator's schedule. You should not change the schedule to another Schedule object.
When a simulation is begun, SimState's start() method is called. Then the schedule is stepped some N times. Last, the SimState's finish() method is called, and the simulation is over.
SimStates are serializable; if you wish to be able to checkpoint your simulation and read from checkpoints, you should endeavor to make all objects in the simulation serializable as well. Prior to serializing to a checkpoint, preCheckpoint() is called. Then after serialization, postCheckpoint() is called. When a SimState is loaded from a checkpoint, awakeFromCheckpoint() is called to give you a chance to make any adjustments. SimState also implements several methods which call these methods and then serialize the SimState to files and to streams.
SimState also maintains a private registry of Asynchronous objects (such as AsynchronousSteppable), and handles pausing and resuming them during the checkpointing process, and killing them during finish() in case they had not completed yet.
If you override any of the methods foo() in SimState, should remember to always call super.foo() for any such method foo().
Field Summary | |
boolean |
cleaningAsynchronous
|
MersenneTwisterFast |
random
The SimState's random number generator |
Schedule |
schedule
SimState's schedule |
Constructor Summary | |
SimState(MersenneTwisterFast random,
Schedule schedule)
|
Method Summary | |
boolean |
addToAsynchronousRegistry(Asynchronous stop)
Registers an Asynchronous to get its pause() method called prior to checkpointing, its resume() method to be called after checkpointing or recovery, and its stop() method to be called at finish() time. |
Asynchronous[] |
asynchronousRegistry()
Returns all the Asynchronous items presently in the registry. |
void |
awakeFromCheckpoint()
Called after the SimState was created by reading from a checkpointed object. |
void |
finish()
Called either at the proper or a premature end to the simulation. |
void |
postCheckpoint()
Called just after the SimState was checkpointed (serialized out to a file to be unserialized and fired up at a future time). |
void |
preCheckpoint()
Called just before the SimState is being checkpointed (serialized out to a file to be unserialized and fired up at a future time). |
static SimState |
readFromCheckpoint(java.io.File file)
Creates a SimState from checkpoint. |
static SimState |
readFromCheckpoint(java.io.InputStream stream)
Creates and returns a new SimState object read in from the provided stream. |
void |
removeFromAsynchronousRegistry(Asynchronous stop)
Unregisters an Asynchronous from the asynchronous registry. |
void |
setRandom(MersenneTwisterFast random)
|
void |
start()
Called immediately prior to starting the simulation, or in-between simulation runs. |
SimState |
writeToCheckpoint(java.io.File file)
Writes the state to a checkpoint and returns the state. |
void |
writeToCheckpoint(java.io.OutputStream stream)
Serializes out the SimState, and the entire simulation state (not including the graphical interfaces) to the provided stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public MersenneTwisterFast random
public Schedule schedule
public boolean cleaningAsynchronous
Constructor Detail |
public SimState(MersenneTwisterFast random, Schedule schedule)
Method Detail |
public void setRandom(MersenneTwisterFast random)
public void start()
public void finish()
public boolean addToAsynchronousRegistry(Asynchronous stop)
An Asynchronous cannot be added multiple times to the same registry -- if it's there it's there. Returns false if the Asynchronous could not be added, either because the simulation is stopped or in the process of finish()ing.
public void removeFromAsynchronousRegistry(Asynchronous stop)
public Asynchronous[] asynchronousRegistry()
public void preCheckpoint()
public void postCheckpoint()
public void awakeFromCheckpoint()
public void writeToCheckpoint(java.io.OutputStream stream) throws java.io.IOException
java.io.IOException
public SimState writeToCheckpoint(java.io.File file)
public static SimState readFromCheckpoint(java.io.File file)
public static SimState readFromCheckpoint(java.io.InputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException, java.io.OptionalDataException, java.lang.ClassCastException
java.io.IOException
java.lang.ClassNotFoundException
java.io.OptionalDataException
java.lang.ClassCastException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |