-
- All Implemented Interfaces:
-
java.lang.Runnable
public interface Simulation<T, P extends Position<out P>> implements Runnable
This interface forces simulations to be independent threads, and make them controllable from an external console.
-
-
Method Summary
Modifier and Type Method Description abstract voidaddOutputMonitor(OutputMonitor<T, P> op)Adds an OutputMonitor to this simulation. abstract Environment<T, P>getEnvironment()Allows to access the current environment. abstract Optional<Throwable>getError()abstract longgetFinalStep()abstract TimegetFinalTime()Allows to at which time this simulation will end. abstract StatusgetStatus()Allows to access the current status. abstract longgetStep()Allows to access the current simulation step. abstract TimegetTime()Allows to know which is the current simulation time. abstract voidgoToStep(long steps)Executes a certain number of steps, then pauses it. abstract voidgoToTime(Time t)Executes the simulation until the target time is reached, then pauses it. abstract voidneighborAdded(Node<T> node, Node<T> n)This method must get called in case a a communication link connecting two nodes gets created during the simulation. abstract voidneighborRemoved(Node<T> node, Node<T> n)This method must get called in case a a communication link connecting two nodes gets broken during the simulation. abstract voidnodeAdded(Node<T> node)This method must get called in case a node is added to the environment during the simulation and after its neighborhood has been computed (or can be consistently computed by the simulated environment). abstract voidnodeMoved(Node<T> node)This method must get called in case a node is moved in the environment during the simulation and after its neighborhood has been computed (or can be consistently computed by the simulated environment). abstract voidnodeRemoved(Node<T> node, Neighborhood<T> oldNeighborhood)This method must get called in case a node is removed from the environment during the simulation and after its neighborhood has been computed (or can be consistently computed by the simulated environment). abstract voidpause()Sends a pause command to the simulation. abstract voidplay()Sends a play command to the simulation. abstract voidreactionAdded(Reaction<T> reactionToAdd)Adds a reaction during the simulation to the scheduler and start to execute it. abstract voidreactionRemoved(Reaction<T> reactionToRemove)Removes a reaction during the simulation from the scheduler and stop to execute it. abstract voidremoveOutputMonitor(OutputMonitor<T, P> op)Removes an OutputMonitor to this simulation. abstract voidschedule(CheckedRunnable r)Schedules a runnable to be executed by the Simulation thread, useful for synchronization purposes (e.g. abstract voidterminate()Sends a terminate command to the simulation. abstract StatuswaitFor(Status s, long timeout, TimeUnit timeunit)Suspends the caller until the simulation reaches the selected Status or the timeout ends. -
-
Method Detail
-
addOutputMonitor
abstract void addOutputMonitor(OutputMonitor<T, P> op)
Adds an OutputMonitor to this simulation.
- Parameters:
op- the OutputMonitor to add
-
getEnvironment
abstract Environment<T, P> getEnvironment()
Allows to access the current environment.
-
getFinalStep
abstract long getFinalStep()
-
getFinalTime
abstract Time getFinalTime()
Allows to at which time this simulation will end.
-
getStep
abstract long getStep()
Allows to access the current simulation step.
-
goToStep
abstract void goToStep(long steps)
Executes a certain number of steps, then pauses it.
- Parameters:
steps- the number of steps to execute
-
goToTime
abstract void goToTime(Time t)
Executes the simulation until the target time is reached, then pauses it.
- Parameters:
t- the target time
-
neighborAdded
abstract void neighborAdded(Node<T> node, Node<T> n)
This method must get called in case a a communication link connecting two nodes gets created during the simulation. This method provides dependency and scheduling times re-computation for all the reactions interested by such change.
- Parameters:
node- the noden- the second node
-
neighborRemoved
abstract void neighborRemoved(Node<T> node, Node<T> n)
This method must get called in case a a communication link connecting two nodes gets broken during the simulation. This method provides dependency and scheduling times re-computation for all the reactions interested by such change.
- Parameters:
node- the noden- the second node
-
nodeAdded
abstract void nodeAdded(Node<T> node)
This method must get called in case a node is added to the environment during the simulation and after its neighborhood has been computed (or can be consistently computed by the simulated environment). This method provides dependency computation and is responsible of correctly scheduling the Node's new reactions.
- Parameters:
node- the freshly added node
-
nodeMoved
abstract void nodeMoved(Node<T> node)
This method must get called in case a node is moved in the environment during the simulation and after its neighborhood has been computed (or can be consistently computed by the simulated environment). This method provides dependency computation and is responsible of correctly scheduling the Node's reactions.
- Parameters:
node- the node
-
nodeRemoved
abstract void nodeRemoved(Node<T> node, Neighborhood<T> oldNeighborhood)
This method must get called in case a node is removed from the environment during the simulation and after its neighborhood has been computed (or can be consistently computed by the simulated environment). This method provides dependency computation and is responsible of correctly removing the Node's reactions from the scheduler.
- Parameters:
node- the freshly removed nodeoldNeighborhood- the neighborhood of the node as it was before it was removed (used to calculate reverse dependencies)
-
pause
abstract void pause()
Sends a pause command to the simulation. There is no guarantee on when this command will be actually processed.
-
play
abstract void play()
Sends a play command to the simulation. There is no guarantee on when this command will be actually processed.
-
reactionAdded
abstract void reactionAdded(Reaction<T> reactionToAdd)
Adds a reaction during the simulation to the scheduler and start to execute it. The reaction addition is not propagated in the Node entity. To do that call also the method addReaction.
- Parameters:
reactionToAdd- the reaction to add
-
reactionRemoved
abstract void reactionRemoved(Reaction<T> reactionToRemove)
Removes a reaction during the simulation from the scheduler and stop to execute it. The reaction removal is not propagated in the Node entity. To do that call also the method removeReaction.
- Parameters:
reactionToRemove- the reaction to remove
-
removeOutputMonitor
abstract void removeOutputMonitor(OutputMonitor<T, P> op)
Removes an OutputMonitor to this simulation. If the OutputMonitor was not among those already added, this method does nothing.
- Parameters:
op- the OutputMonitor to add
-
schedule
abstract void schedule(CheckedRunnable r)
Schedules a runnable to be executed by the Simulation thread, useful for synchronization purposes (e.g. make sure that the environment is not being changed while the requested operation is being executed). An exception thrown by the passed runnable will make the simulation terminate.
- Parameters:
r- the runnable to execute
-
terminate
abstract void terminate()
Sends a terminate command to the simulation. There is no guarantee on when this command will be actually processed.
-
-
-
-