Class SimulationEngine

java.lang.Object
java.lang.Thread
microsim.engine.SimulationEngine
All Implemented Interfaces:
Runnable

public class SimulationEngine extends Thread
The simulation engine. The engine keeps a reference to an EventQueue object to manage temporal sequence of events. Every object of the running simulation can schedule events at a specified time point and the engine will notify to it at the right time. The SimEngine stores a list of windows created by models.
  • Field Details

  • Constructor Details

    • SimulationEngine

      protected SimulationEngine()
  • Method Details

    • getInstance

      @NonNull public static @NonNull SimulationEngine getInstance()
    • setTurnOffDatabaseConnection

      public void setTurnOffDatabaseConnection(boolean turnOffDatabaseConnection)
    • getManager

      @Nullable public @Nullable SimulationManager getManager(@Nullable @Nullable String id)
    • addEngineListener

      public void addEngineListener(EngineListener engineListener)
      Install a listener for events generated by the simulation engine.
      Parameters:
      engineListener - An object implementing the ISimEngineListener interface.
    • removeEngineListener

      public void removeEngineListener(EngineListener engineListener)
    • setup

      public void setup()
    • getModelArray

      public SimulationManager[] getModelArray()
      Return an array representing the running SimModels.
      Returns:
      A list of running models.
    • getTime

      public double getTime()
      Return a reference to the current SimTime.
      Returns:
      The current time object.
    • step

      public void step(int forSteps) throws SimulationException
      Make forSteps simulation steps.
      Parameters:
      forSteps - The number of steps to be done.
      Throws:
      SimulationException - //TODO finish this
    • reset

      public void reset()
    • startSimulation

      public void startSimulation()
      Start simulation. A new thread starts and calls step() method until something stops it.
    • pause

      public void pause()
      Stop simulation. The running thread is frozen until next step is called.
    • quit

      public void quit()
      Stops the simulation and then quits the JVM.
    • addSimulationManager

      public SimulationManager addSimulationManager(SimulationManager simulationManager)
      Notifies the engine to manage a SimModel. This method is mandatory to let the model work. The current event queue is joined to the given model.
    • addSimulationManager

      public SimulationManager addSimulationManager(String managerClassName) throws InstantiationException, IllegalAccessException, ClassNotFoundException
      Throws:
      InstantiationException
      IllegalAccessException
      ClassNotFoundException
    • buildModels

      public void buildModels()
      Call the buildModel() method of each active SimModel.
    • getModelBuildStatus

      public boolean getModelBuildStatus()
      Return true if buildModels() method has been called. False otherwise.
      Returns:
      True is models have been built, false otherwise.
    • disposeModels

      public Class<?>[] disposeModels()
      Dispose from memory all running models. Return an array representing the Class of each disposed models. It is used by rebuildModels().
      Returns:
      The list of disposed models.
    • rebuildModels

      public void rebuildModels()
      Dispose and rebuild each running model. It is used to restart simulation.
    • setRandomSeed

      public void setRandomSeed(int newSeed)
      Set the current random seed.
      Parameters:
      newSeed - The new random seed.
    • end

      public void end()
      Stops the simulation and call the simulationEnd method of each running model.
    • performAction

      public void performAction(SystemEventType actionType)
      React to system events.
      Parameters:
      actionType - Reacts in case of EVENT_SIMULATION_END, EVENT_SIMULATION_RESTART, EVENT_SHUTDOWN events.
    • setRunningStatus

      public void setRunningStatus(boolean running)
      Set current simulation running status.
    • step

      public void step() throws SimulationException
      Throws:
      SimulationException
    • notifySimulationListeners

      protected void notifySimulationListeners(SystemEventType event)
    • run

      public void run()
      Start the independent thread running simulation. It fires events only if running status is set to true.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • getCurrentExperiment

      @NonNull public @NonNull Experiment getCurrentExperiment()