hades.simulator
Class InteractiveSimKernel

java.lang.Object
  extended byhades.simulator.SimKernel
      extended byhades.simulator.InteractiveSimKernel
All Implemented Interfaces:
ContextToolTip, java.lang.Runnable, Simulatable

public class InteractiveSimKernel
extends SimKernel
implements java.lang.Runnable


Field Summary
(package private)  int delta_resync_iterations
           
(package private)  double eventTime
           
(package private)  int global_errors
           
(package private)  double lastSyncTime
           
(package private)  int n_pending
           
(package private)  int n_resync_iterations
           
static int PAUSE
           
(package private)  int PENDING_ARRAY_SIZE
           
(package private)  int pendingArrayIndex
           
(package private)  SimEvent[] pendingEventArray
           
(package private)  Port[] pendingEventTargetArray
           
(package private)  double realTime
           
static int RUNNING
           
(package private)  int simulatorState
           
static int SINGLE_STEP
           
static int STOP
           
 long t_resync
           
 long t_sleep
           
(package private)  long t0
           
(package private)  long t1
           
(package private) static java.lang.String versionString
           
static int VIRGIN
           
 
Fields inherited from class hades.simulator.SimKernel
commandQueue, console, controlPanel, debug, design, ELABORATE, endTime, eventList, n_interactive, n_interactive_transferred, n_iterations, n_processed, n_scheduled, n_simulators, name, painter, PAUSED, RESET, runner, shouldStop, simTime, simulatorID, SINGLESTEP, state, STOPPED
 
Constructor Summary
InteractiveSimKernel()
          constructor for an so far idle simulation engine
 
Method Summary
 void addPendingEvent(SimEvent event, Port target)
          add SimEvents for later execution.
 void checkCreateSimulationThread()
           
(package private)  void checkInteractiveEvents()
          check the CommandQueue for events and execute them, if any.
(package private)  void checkResync()
          check whether we need to re-synchronize simulation time and real time.
(package private)  void collectEvents()
           
 void deleteAllEventsFromSource(SimObject source)
          delete all events scheduled from object 'source' from our event list.
 void elaborateComponents()
           
 void evaluate(java.lang.Object arg)
          evaluate(): called by the Simulation engine.
(package private)  void executeAllPendingEvents()
           
(package private)  void executePendingEvent()
          execute one pending event (the last one).
 void executeSingleStep()
           
 java.lang.String getState()
          getState(): print current state
 void initializeSimulator()
          initialize the simulator: stop any running simulation, then create a new eventlist, initialize start and end times, ...
 boolean isPaused()
          check whether this simulator is currently interrupted
 boolean isRunning()
          check whether this simulator is running
 boolean isSingleStep()
           
 boolean isStarted()
           
 boolean isStopped()
           
 boolean isVirgin()
           
 void msg(java.lang.String s)
           
 void pauseSimulation()
          pause the simulation, if running
 void printStatus()
          printStatus(): print a short message about current simulation and real times, as well as the number of scheduled and processed events, memory status, etc.
(package private)  void reallocatePendingEventArrays()
           
 void resync()
          resync: update our 'realTime' variable from the JVM system clock.
 void run()
          run the simulation until ready or interrupted.
 void runFor(double delta_t)
          continue the simulation for the specified interval of time.
 void runForever()
          set the simulation end time to Double.MAX_VALUE, then start/continue the simulation from the current time.
 void scheduleInteractiveEvent(SimEvent se)
          schedule an interactive event.
(package private)  void simulation()
          simulation: for each iteration, we first check and handle interactive events.
 void singleStep()
          singleStep(): execute the one next event (if any).
 void sleep(long millis)
          tell the simulation Thread to sleep a bit.
 void stopSimulation()
          stop the simulation, no questions asked
 java.lang.String toString()
          standard identification method
 void updateControlPanel()
           
 
Methods inherited from class hades.simulator.SimKernel
checkClearWaveforms, continueSimulation, dbg, elaborate, getDebug, getEventList, getNumberOfProcessedEvents, getNumberOfScheduledEvents, getSimTime, getSyncPainter, getToolTip, hasEvents, isReset, main, message, pauseSimulation_NEW, printNextPendingEvent, processPendingRepaints, run_debug, scheduleEvent, scheduleWakeup, setConsole, setControlPanel, setDebug, setDesign, setName, setSyncPainter, stopSimulation_NEW, usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

t_sleep

public long t_sleep

t_resync

public long t_resync

versionString

static java.lang.String versionString

realTime

double realTime

lastSyncTime

double lastSyncTime

eventTime

double eventTime

t0

long t0

t1

long t1

n_resync_iterations

int n_resync_iterations

delta_resync_iterations

int delta_resync_iterations

global_errors

int global_errors

STOP

public static final int STOP
See Also:
Constant Field Values

SINGLE_STEP

public static final int SINGLE_STEP
See Also:
Constant Field Values

PAUSE

public static final int PAUSE
See Also:
Constant Field Values

RUNNING

public static final int RUNNING
See Also:
Constant Field Values

VIRGIN

public static final int VIRGIN
See Also:
Constant Field Values

simulatorState

int simulatorState

PENDING_ARRAY_SIZE

int PENDING_ARRAY_SIZE

pendingArrayIndex

int pendingArrayIndex

n_pending

int n_pending

pendingEventArray

SimEvent[] pendingEventArray

pendingEventTargetArray

Port[] pendingEventTargetArray
Constructor Detail

InteractiveSimKernel

public InteractiveSimKernel()
constructor for an so far idle simulation engine

Method Detail

addPendingEvent

public void addPendingEvent(SimEvent event,
                            Port target)
add SimEvents for later execution. We use arrays as datastructures, the first SimEvent/Ports goes into position 0. The index is incremented after adding a SimEvent/Port pair. The arrays are reallocated as necessary.

Overrides:
addPendingEvent in class SimKernel

reallocatePendingEventArrays

void reallocatePendingEventArrays()

executePendingEvent

void executePendingEvent()
execute one pending event (the last one). We decrement the index into the SimEvent/Port arrays, access the data at the resulting index, and process it.


executeAllPendingEvents

void executeAllPendingEvents()

isStopped

public boolean isStopped()

isSingleStep

public boolean isSingleStep()
Overrides:
isSingleStep in class SimKernel

isPaused

public boolean isPaused()
Description copied from class: SimKernel
check whether this simulator is currently interrupted

Overrides:
isPaused in class SimKernel

isRunning

public boolean isRunning()
Description copied from class: SimKernel
check whether this simulator is running

Overrides:
isRunning in class SimKernel

isStarted

public boolean isStarted()

isVirgin

public boolean isVirgin()

getState

public java.lang.String getState()
getState(): print current state

Overrides:
getState in class SimKernel

elaborateComponents

public void elaborateComponents()
Overrides:
elaborateComponents in class SimKernel

runForever

public void runForever()
set the simulation end time to Double.MAX_VALUE, then start/continue the simulation from the current time.

Overrides:
runForever in class SimKernel

runFor

public void runFor(double delta_t)
continue the simulation for the specified interval of time.

Overrides:
runFor in class SimKernel

checkCreateSimulationThread

public void checkCreateSimulationThread()

initializeSimulator

public void initializeSimulator()
Description copied from class: SimKernel
initialize the simulator: stop any running simulation, then create a new eventlist, initialize start and end times, ...

Overrides:
initializeSimulator in class SimKernel

evaluate

public void evaluate(java.lang.Object arg)
Description copied from class: SimKernel
evaluate(): called by the Simulation engine. This method is used to implement simulation controlled interrupts by scheduling InterruptEvent objects at the desired simulation times.

Specified by:
evaluate in interface Simulatable
Overrides:
evaluate in class SimKernel

run

public void run()
run the simulation until ready or interrupted. This method processes all remaining SimEvents in 'real time' as follows: All Events with scheduled time smaller than the current time are processed as fast as possible. If no such Events remain, the simulator Thread will sleep() itself for 100msec. each, until the user generates new Events or the time is ripe for the Events scheduled for later times.

Variable 't0' holds the JVM clock at start of the simulation, 't1' is used for the curent JVM clock value.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class SimKernel

simulation

void simulation()
simulation: for each iteration, we first check and handle interactive events. Next, we check simulation and real-time and re-synchronize, if necessary.

Finally, we collect and execute the events.


checkInteractiveEvents

void checkInteractiveEvents()
check the CommandQueue for events and execute them, if any. This method should only be called by the simulation Thread.


scheduleInteractiveEvent

public void scheduleInteractiveEvent(SimEvent se)
schedule an interactive event. This method will typically be called from the AWT event handler thread, and is therefore not allowed to access the event list directly. Therefore, we just create an interactive 'SimulatorScheduleCommand' for processing by the simulation Thread.

Overrides:
scheduleInteractiveEvent in class SimKernel

deleteAllEventsFromSource

public void deleteAllEventsFromSource(SimObject source)
delete all events scheduled from object 'source' from our event list. This method may be called by any thread. To avoid synchronisation problems, we don't modify the event list directly. Instead, a 'DeleteAllEventsFromSourceCommand' is scheduled for processing by the simulation Thread (which may safely modify its event list).

Overrides:
deleteAllEventsFromSource in class SimKernel

singleStep

public void singleStep()
Description copied from class: SimKernel
singleStep(): execute the one next event (if any). Start and elaborate the simulation, if necessary. Also, print information about the next event (if any) to allow the user to concentrate on that event.

Overrides:
singleStep in class SimKernel

pauseSimulation

public void pauseSimulation()
Description copied from class: SimKernel
pause the simulation, if running

Overrides:
pauseSimulation in class SimKernel

stopSimulation

public void stopSimulation()
Description copied from class: SimKernel
stop the simulation, no questions asked

Overrides:
stopSimulation in class SimKernel

updateControlPanel

public void updateControlPanel()

checkResync

void checkResync()
check whether we need to re-synchronize simulation time and real time. Currently, this is done after every n_resync_iterations cycles, or every 0.5 seconds of real time.


collectEvents

void collectEvents()

executeSingleStep

public void executeSingleStep()
Overrides:
executeSingleStep in class SimKernel

resync

public void resync()
resync: update our 'realTime' variable from the JVM system clock.


printStatus

public void printStatus()
printStatus(): print a short message about current simulation and real times, as well as the number of scheduled and processed events, memory status, etc.

Overrides:
printStatus in class SimKernel

sleep

public void sleep(long millis)
tell the simulation Thread to sleep a bit. The sleep time can be specified via the 'Hades.Simulator.SleepMillis' property.


toString

public java.lang.String toString()
Description copied from class: SimKernel
standard identification method

Overrides:
toString in class SimKernel

msg

public void msg(java.lang.String s)