verinec.netsim.gui
Class SimulatorThread

java.lang.Object
  extended by java.lang.Thread
      extended by verinec.netsim.gui.SimulatorThread
All Implemented Interfaces:
Runnable

public class SimulatorThread
extends Thread

This thread is responsible for animating the simulation. Calls the animate methode of the events in well defined time intervals. It also manages a time subunit and when this subunit reaches a defined value, the progressbar of the Toolbar will be updated. If the environment variable verinec.netsim.loop is set, the simulation loops endlessly instead of stopping when the last step has been reached.

Author:
Renato Loeffel

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  int end
           
private  boolean freeze
           
private  boolean running
           
private  SimulationScheduler simuScheduler
           
private  int speed
           
private  int start
           
private  int substep
           
static int SUBSTEP_UNITY
          Number of substeps for each step.
private  SimulationToolbar toolbar
           
private  VerinecStudio verinecStudio
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SimulatorThread(Element events, int initSpeed, SimulationToolbar toolbar, VerinecStudio parent)
          Initalizes the thread and creates a scheduler for the events.
 
Method Summary
 void pauseSimulation()
          Pauses the simulation.
 void playSimulation()
          Launches the thread.
 void progress(int time)
          Loads the new events to the panel.
 void run()
          Animates in every slope the events.
 void setSimulationBoundaries(int start, int end)
          Set start and stop time of the simulation.
 void setSpeed(int value)
          Changes the simulationspeed.
 void stepBackward()
          Jumps one time unit backward and animates the steps.
 void stepForward()
          Jumps one time unit forward and animates the steps.
 void stopSimulation()
          Stops the simulation.
 void terminateSimulation()
          Terminates the simulation, that is set running=false, stop the simulation and notify the scheduler.
private  void wakeup()
          Wakes up the sleeping thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SUBSTEP_UNITY

public static int SUBSTEP_UNITY
Number of substeps for each step.
500 substeps are 1 time unit.


toolbar

private SimulationToolbar toolbar

simuScheduler

private SimulationScheduler simuScheduler

verinecStudio

private VerinecStudio verinecStudio

speed

private int speed

start

private int start

end

private int end

substep

private int substep

freeze

private boolean freeze

running

private boolean running
Constructor Detail

SimulatorThread

public SimulatorThread(Element events,
                       int initSpeed,
                       SimulationToolbar toolbar,
                       VerinecStudio parent)
                throws SimulationException
Initalizes the thread and creates a scheduler for the events.

Parameters:
events - The whole testfile.
initSpeed - The current speed.
toolbar - A reference to the toolbar. (needed to perform updates to the progressbar)
parent - A reference to the main application window.
Throws:
SimulationException - When a network ressource cannot be found or the events are invalid.
Method Detail

setSimulationBoundaries

public void setSimulationBoundaries(int start,
                                    int end)
Set start and stop time of the simulation.

Parameters:
start - the startvalue.
end - the endvalue.

playSimulation

public void playSimulation()
Launches the thread.


wakeup

private void wakeup()
Wakes up the sleeping thread.


pauseSimulation

public void pauseSimulation()
Pauses the simulation.


stopSimulation

public void stopSimulation()
Stops the simulation.


stepForward

public void stepForward()
Jumps one time unit forward and animates the steps. Afterwards, a pause is scheduled.


stepBackward

public void stepBackward()
Jumps one time unit backward and animates the steps. Afterward, a pause is scheduled.


setSpeed

public void setSpeed(int value)
Changes the simulationspeed.

Parameters:
value - the new speed of the simulation.

progress

public void progress(int time)
Loads the new events to the panel.

Parameters:
time - The time point to load events for.

terminateSimulation

public void terminateSimulation()
Terminates the simulation, that is set running=false, stop the simulation and notify the scheduler.


run

public void run()
Animates in every slope the events. Also updates the progressbar when necessary. Also responsible to animate the simulation at the same real time speed on every machine.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

Copyright © 2005 Verinec, DIUF