Class SimulationEngine

java.lang.Object
  |
  +--SimulationEngine

public class SimulationEngine
extends java.lang.Object
implements java.lang.Runnable

The SimulationEngine coordinates reading Commands via the CommandParser and feeding those Commands to the Robot model.


Field Summary
protected  boolean requestStop
          A flag indicating a request to stop the simulation.
protected  java.lang.Thread simulationThread
          The Thread controlling the simulation.
protected  CommandParser theCommandParser
          The CommandParser used to read Commands.
protected  CommandQueue theCommandQueue
          The CommandQueue of Commands to be processed.
 
Constructor Summary
SimulationEngine()
          Constructor, initialize the variables.
 
Method Summary
 boolean isComplete()
          Indicates if the simulation has finished.
 boolean isReady()
          Returns if the CommandQueue has been loaded and is not empty.
 void loadCommandQueue(java.io.Reader r)
          Parse the given Reader stream for Commands using the current CommandParser, and load the CommandQueue object for the simulation.
 void run()
          The loop for the SimulationEngine Thread, which steps the simulation to the next state while the CommandQueue has more Commands to process.
 void setCommandParser(CommandParser theCommandParser)
          Sets the current CommandParser object.
 void start()
          Starts the SimulationEngine's Thread with NORMAL_PRIORITY.
 void step()
          Gets the next Command object from the CommandQueue, and feeds the Command to the Robot to get the destination Robot state.
 void stop()
          Stops the simulation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theCommandParser

protected CommandParser theCommandParser
The CommandParser used to read Commands.

theCommandQueue

protected CommandQueue theCommandQueue
The CommandQueue of Commands to be processed.

requestStop

protected boolean requestStop
A flag indicating a request to stop the simulation.

simulationThread

protected java.lang.Thread simulationThread
The Thread controlling the simulation.
Constructor Detail

SimulationEngine

public SimulationEngine()
Constructor, initialize the variables.
Method Detail

setCommandParser

public void setCommandParser(CommandParser theCommandParser)
Sets the current CommandParser object.
Parameters:
theCommandParser - the new CommandParser object.

loadCommandQueue

public void loadCommandQueue(java.io.Reader r)
                      throws SimulationEngineException
Parse the given Reader stream for Commands using the current CommandParser, and load the CommandQueue object for the simulation.
Parameters:
r - the Reader stream to parse for simulation commands.
Throws:
SimulationEngineException - indicates error parsing Reader.

step

public void step()
          throws java.lang.Exception
Gets the next Command object from the CommandQueue, and feeds the Command to the Robot to get the destination Robot state. The Robot is then incrementally moved from the current Robot to the destination state until the destination state is reached.
Throws:
java.lang.Exception - indicates error in simulation.

start

public void start()
Starts the SimulationEngine's Thread with NORMAL_PRIORITY.

run

public void run()
The loop for the SimulationEngine Thread, which steps the simulation to the next state while the CommandQueue has more Commands to process. Once the CommandQueue is empty, the SimulationEngine Thread run() loop is exited and the Thread is stopped. Note: This method still needs to be able to raise an exception.
Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Stops the simulation. Note that this method is NOT meant to implement Runnable.stop(), as that method has been deprecated in JDK 1.2. Instead, this method properly sets a boolean value which causes the run() loop to exit, allows the Thread to terminate properly.

isComplete

public boolean isComplete()
Indicates if the simulation has finished.
Returns:
indicates is simulation is complete.

isReady

public boolean isReady()
Returns if the CommandQueue has been loaded and is not empty.
Returns:
indicates if the CommandQueue is loaded and not empty.