The Physiologist's Friend Simulation API

ch.unizh.ini.friend.simulation
Class ThreadedSimulation

java.lang.Object
  extended by ch.unizh.ini.friend.simulation.AbstractSimulation
      extended by ch.unizh.ini.friend.simulation.ThreadedSimulation
All Implemented Interfaces:
SimulationTask, Runnable

public class ThreadedSimulation
extends AbstractSimulation
implements Runnable

Implementation of the simulation loop in a separate thread.

Version:
$Revision: 1.13 $
Author:
Christof Marti

Field Summary
protected  Thread thread
          The simulation thread.
 
Fields inherited from class ch.unizh.ini.friend.simulation.AbstractSimulation
delay, on, step
 
Constructor Summary
ThreadedSimulation(SimulationStep step)
          Creates a new instance with the given simulation step.
ThreadedSimulation(SimulationStep step, long delay)
           
 
Method Summary
 void addUpdateable(Updateable u)
          Adds an updateable to the simulation.
 void removeUpdateable(Updateable u)
          Removes an updateable from the simulation.
 void run()
          The main-loop of the simulation.
 void start()
          Starts the thread on the main-loop.
 void stop()
          Tells the main-loop to stop by the end of the current iteration.
 
Methods inherited from class ch.unizh.ini.friend.simulation.AbstractSimulation
getDelay, getNumberOfIterationsPerStep, getStep, isOn, setDelay, setNumberOfIterationsPerStep
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thread

protected Thread thread
The simulation thread.

Constructor Detail

ThreadedSimulation

public ThreadedSimulation(SimulationStep step)
Creates a new instance with the given simulation step.

Parameters:
step - The simulation step instance.

ThreadedSimulation

public ThreadedSimulation(SimulationStep step,
                          long delay)
Parameters:
step - the simulation step
delay - sleep delay between iterations
Method Detail

run

public void run()
The main-loop of the simulation.

Specified by:
run in interface Runnable

start

public void start()
Starts the thread on the main-loop.

Specified by:
start in interface SimulationTask
Specified by:
start in class AbstractSimulation

stop

public void stop()
Tells the main-loop to stop by the end of the current iteration.

Specified by:
stop in interface SimulationTask
Specified by:
stop in class AbstractSimulation

addUpdateable

public void addUpdateable(Updateable u)
Adds an updateable to the simulation. The precondition is that the simulation isn't running.

Specified by:
addUpdateable in interface SimulationTask
Specified by:
addUpdateable in class AbstractSimulation
Parameters:
u - An updateable.

removeUpdateable

public void removeUpdateable(Updateable u)
Removes an updateable from the simulation. The precondition is that the simulation isn't running.

Specified by:
removeUpdateable in interface SimulationTask
Specified by:
removeUpdateable in class AbstractSimulation
Parameters:
u - An updateable.

http://www.ini.unizh.ch/~tobi/friend