|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jasi.sim.basic.AbstractSimKernel
public abstract class AbstractSimKernel
Basic implementation of a simulation kernel based on the singleton design pattern. This class provides elementary methods to control the execution of a simulation.
A simulation kernel application is created by extension of this class and
implementing a run-method like this:
Time end = ...;
Time current = startSimulation();
try {
while (isRunning()) {
if (current.isGE(end)) {
break; // The requested end time has been reached
}
current = continueSimulation(current, end);
}
}
finally {
inishSimulation();
}
The simulation thread can be started and finished in the following way:
sim.start();
try {
sim.join();
} catch (InterruptedException e) {
System.err.println(e);
} finally {
sim.writeArchive();
}
Constructor Summary | |
---|---|
protected |
AbstractSimKernel(SimController c,
AbstractSimArchive a)
Constructor of SimKernel. |
Method Summary | |
---|---|
AbstractSimArchive |
archive()
Get archive of the simulation. |
Calendar |
calendar()
Get calendar of the simulation. |
protected Time |
continueSimulation(Time from,
Time to)
The simulation thread continues its execution. |
SimController |
controller()
Get the external controller of this simulation (federation). |
Time |
currentTime()
Get current time of the simulation. |
Elements |
elements()
Get the element utility class of this simulation. |
protected void |
finishSimulation()
The simulation thread finishes. |
static AbstractSimKernel |
getInstance()
Get the simulation instance. |
AbstractSimKernel |
init()
Initialize this simulation instance. |
protected static void |
initialize(AbstractSimKernel kernel)
Initialize the simulation instance. |
boolean |
isRunning()
Ask, if this simulation is running. |
void |
join()
Join waiting thread with the simulation thread. |
SimProxy |
proxy()
Get the proxy for simulation state change listeners. |
void |
readArchive(java.lang.String file)
Read state of this simulation from an archive. |
void |
start()
Start the simulation thread. |
protected Time |
startSimulation()
The simulation thread is started. |
void |
stop()
Stop the simulation thread. |
Tables |
tables()
Get the table utility class of this simulation. |
void |
writeArchive(java.lang.String file)
Write state of simulation into an archive. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.lang.Runnable |
---|
run |
Constructor Detail |
---|
protected AbstractSimKernel(SimController c, AbstractSimArchive a)
c
- A simulation controller.a
- The simulation archive.instance
,
Time.ZERO
Method Detail |
---|
public final AbstractSimKernel init()
protected static void initialize(AbstractSimKernel kernel)
kernel
- The instance of the kernel.public static AbstractSimKernel getInstance()
sim = new Simulation(...);
SimKernel.initialize(sim);
or
sim = new Simulation(...).init();
protected final Time startSimulation()
SimController.start(jasi.sim.basic.value.Time)
protected final Time continueSimulation(Time from, Time to)
from
- The current simulation time.to
- The requested simulation time.
protected final void finishSimulation()
public final void readArchive(java.lang.String file)
file
- The archive's file name without extension.public final void writeArchive(java.lang.String file)
file
- The archive's file name without extension.public final boolean isRunning()
public final void join() throws java.lang.InterruptedException
java.lang.InterruptedException
- Whenever this thread is interrupted.public final void start()
public final void stop()
public final Time currentTime()
public final SimController controller()
public final SimProxy proxy()
public final AbstractSimArchive archive()
public final Calendar calendar()
public final Elements elements()
public final Tables tables()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |