vanetsim.simulation
Class SimulationMaster

java.lang.Object
  extended by java.lang.Thread
      extended by vanetsim.simulation.SimulationMaster
All Implemented Interfaces:
java.lang.Runnable

public final class SimulationMaster
extends java.lang.Thread

This thread delegates the simulation processing to subthreads and then calls a repaint on the drawing area.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int TIME_PER_STEP
          How much time passes in one step (in milliseconds). 40ms results in a smooth animation with 25fps.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SimulationMaster()
          Instantiates a new simulation master.
 
Method Summary
 WorkerThread[] createWorkers(int timePerStep, int threads)
          Function to set up the worker threads with their corresponding regions.
 void doOneStep()
          Proceed one single step forward.
static long getStartTime()
           
 boolean isGuiEnabled()
           
static boolean isLogPerformance_()
           
 boolean isSimulationRunning()
          Returns if a simulation is currently running or not.
 void jumpToTime(int time)
          Allows to jump to a specific time.
 void run()
          The main method for the simulation master initializes the worker threads, manages them and initiates the render process and statistics updates.
 void setGuiEnabled(boolean guiEnabled)
           
static void setStartTime(long theStartTime)
           
 void setTargetStepTime(int time)
          Sets the target step time.
 void startThread()
          Method to let this thread start delegating work to subthreads.
 void stopThread()
          Method to let this thread stop delegating work to subthreads.
static void writeAnyTextToFile(java.lang.String anyText, java.lang.String fileName, boolean append)
          Writes any data to file
 
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TIME_PER_STEP

public static final int TIME_PER_STEP
How much time passes in one step (in milliseconds). 40ms results in a smooth animation with 25fps.

See Also:
Constant Field Values
Constructor Detail

SimulationMaster

public SimulationMaster()
Instantiates a new simulation master.

Method Detail

startThread

public void startThread()
Method to let this thread start delegating work to subthreads. Work in the main function is resumed, the subthreads (workers) will wake up again and the Renderer is notified to get active again.


stopThread

public void stopThread()
Method to let this thread stop delegating work to subthreads. Work in the main function is suspended, the subthreads (workers) will go to sleep and the Renderer is notified to get inactive.


jumpToTime

public void jumpToTime(int time)
Allows to jump to a specific time. While this mode is active, no display and statistics update is done.

Parameters:
time - the target time in milliseconds

setTargetStepTime

public void setTargetStepTime(int time)
Sets the target step time. Decrease to get a faster simulation, increase to get a slower.

Parameters:
time -

doOneStep

public void doOneStep()
Proceed one single step forward.


createWorkers

public WorkerThread[] createWorkers(int timePerStep,
                                    int threads)
Function to set up the worker threads with their corresponding regions. Each thread gets an equal amount of regions (some might get one more because of rounding). The amount of items in a region is not used as a method to improve equality between threads as this value might change over time (moving vehicles!). This function expects to get 2x the amount of CPU cores as threads so that the negative effects of an unequal allocation (some threads finishing faster as others => unused cpu power) are reduced.

Parameters:
timePerStep - the time per step in milliseconds
threads - the amount of threads that shall be created
Returns:
the worker thread array

run

public void run()
The main method for the simulation master initializes the worker threads, manages them and initiates the render process and statistics updates.

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

isSimulationRunning

public boolean isSimulationRunning()
Returns if a simulation is currently running or not.

Returns:
true if a simulation is running, else false

isGuiEnabled

public boolean isGuiEnabled()

setGuiEnabled

public void setGuiEnabled(boolean guiEnabled)

writeAnyTextToFile

public static void writeAnyTextToFile(java.lang.String anyText,
                                      java.lang.String fileName,
                                      boolean append)
Writes any data to file


isLogPerformance_

public static boolean isLogPerformance_()

getStartTime

public static long getStartTime()

setStartTime

public static void setStartTime(long theStartTime)