Package microsim.engine
Class SimulationEngine
- java.lang.Object
-
- java.lang.Thread
-
- microsim.engine.SimulationEngine
-
- All Implemented Interfaces:
java.lang.Runnable
public class SimulationEngine extends java.lang.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. Using the addSimWindow() method each simulation windows is managed by the engine. It is able to show windows destroyed by user. When the windows is shown the engine put the windows in the location where it was when the project document was saved to disk. The window size is stored, too.Title: JAS
Description: Java Agent-based Simulation library
Copyright (C) 2002 Michele Sonnessa
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.- Author:
- Michele Sonnessa
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addEngineListener(EngineListener engineListener)
Install a listener for events generated by the simulation engine.SimulationManager
addSimulationManager(java.lang.String managerClassName)
SimulationManager
addSimulationManager(SimulationManager simulationManager)
Notify the engine to manage a SimModel.void
buildModels()
Call the buildModel() method of each active SimModel.java.lang.Class<?>[]
disposeModels()
Dispose from memory all running models.void
end()
Stops the simulation and call the simulationEnd method of each running model.java.lang.Class<?>
getBuilderClass()
java.lang.ClassLoader
getClassLoader()
Experiment
getCurrentExperiment()
int
getCurrentRunNumber()
java.util.ArrayList<EngineListener>
getEngineListeners()
EventQueue
getEventQueue()
Return a reference to the current EventQueue.ExperimentBuilder
getExperimentBuilder()
static SimulationEngine
getInstance()
SimulationManager
getManager(java.lang.String id)
SimulationManager[]
getModelArray()
Return an array representing the running SimModels.boolean
getModelBuildStatus()
Return true if buildModels() method has been called.java.lang.String
getMultiRunId()
java.util.Random
getRandom()
long
getRandomSeed()
Return the current random seed.static java.util.Random
getRnd()
Return a reference to the current Random generator.boolean
getRunningStatus()
Return current simulation running status.double
getTime()
Return a reference to the current SimTime.boolean
isTurnOffDatabaseConnection()
boolean
isTurnOffDatabaseConnectionAvailable()
void
pause()
Stop simulation.void
performAction(SystemEventType actionType)
React to system events.void
quit()
Stop the simulation, dispose everything and the quit the JVM.void
rebuildModels()
Dispose and rebuild each running model.void
removeEngineListener(EngineListener engineListener)
void
reset()
void
run()
Start the independent thread running simulation.void
setBuilderClass(java.lang.Class<?> builderClass)
Deprecated.void
setClassLoader(java.lang.ClassLoader classLoader)
void
setCurrentRunNumber(int currentRunNumber)
void
setEventTimeTreshold(int millis)
Set the delay time beetween two simulation steps.void
setExperimentBuilder(ExperimentBuilder experimentBuilder)
void
setMultiRunId(java.lang.String multiRunId)
void
setRandomSeed(long newSeed)
Set the current random seed.void
setRunningStatus(boolean running)
Set current simulation running status.void
setTurnOffDatabaseConnection(boolean turnOffDatabaseConnection)
void
setup()
void
startSimulation()
Start simulation.void
step()
void
step(int forSteps)
Make forSteps simulation steps.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Method Detail
-
isTurnOffDatabaseConnection
public boolean isTurnOffDatabaseConnection()
-
setTurnOffDatabaseConnection
public void setTurnOffDatabaseConnection(boolean turnOffDatabaseConnection)
-
getBuilderClass
public java.lang.Class<?> getBuilderClass()
-
getExperimentBuilder
public ExperimentBuilder getExperimentBuilder()
-
setExperimentBuilder
public void setExperimentBuilder(ExperimentBuilder experimentBuilder)
-
isTurnOffDatabaseConnectionAvailable
public boolean isTurnOffDatabaseConnectionAvailable()
-
setBuilderClass
@Deprecated public void setBuilderClass(java.lang.Class<?> builderClass)
Deprecated.
-
getInstance
public static SimulationEngine getInstance()
-
getCurrentRunNumber
public int getCurrentRunNumber()
-
setCurrentRunNumber
public void setCurrentRunNumber(int currentRunNumber)
-
getCurrentExperiment
public Experiment getCurrentExperiment()
-
getManager
public SimulationManager getManager(java.lang.String id)
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
-
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)
-
getEngineListeners
public java.util.ArrayList<EngineListener> getEngineListeners()
-
setup
public void setup()
-
getModelArray
public SimulationManager[] getModelArray()
Return an array representing the running SimModels.- Returns:
- A list of running models.
-
getEventQueue
public EventQueue getEventQueue()
Return a reference to the current EventQueue.- Returns:
- The event queue.
-
getTime
public double getTime()
Return a reference to the current SimTime.- Returns:
- The current time object.
-
getRnd
public static java.util.Random getRnd()
Return a reference to the current Random generator.- Returns:
- The current random generator.
-
step
public void step(int forSteps) throws SimulationException
Make forSteps simulation steps.- Parameters:
forSteps
- The number of steps to be done.- Throws:
SimulationException
-
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 freezed until next step is called.
-
quit
public void quit()
Stop the simulation, dispose everything and the quit the JVM.
-
addSimulationManager
public SimulationManager addSimulationManager(SimulationManager simulationManager)
Notify the engine to manage a SimModel. This method is mandatory to let a model work. The current event queue is joined to the given model.- Parameters:
model
- The model to be added.
-
addSimulationManager
public SimulationManager addSimulationManager(java.lang.String managerClassName) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
- Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.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 java.lang.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.
-
getRandomSeed
public long getRandomSeed()
Return the current random seed.- Returns:
- The current random seed.
-
setRandomSeed
public void setRandomSeed(long 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.
-
getRunningStatus
public boolean getRunningStatus()
Return current simulation running status.
-
setRunningStatus
public void setRunningStatus(boolean running)
Set current simulation running status.
-
setEventTimeTreshold
public void setEventTimeTreshold(int millis)
Set the delay time beetween two simulation steps.
-
step
public void step() throws SimulationException
- Throws:
SimulationException
-
run
public void run()
Start the independent thread running simulation. It fire events only if running status is set to true.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
getRandom
public java.util.Random getRandom()
-
getMultiRunId
public java.lang.String getMultiRunId()
-
setMultiRunId
public void setMultiRunId(java.lang.String multiRunId)
-
-