Package 

Interface Simulation

  • 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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract void addOutputMonitor(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 long getFinalStep()
      abstract Time getFinalTime() Allows to at which time this simulation will end.
      abstract Status getStatus() Allows to access the current status.
      abstract long getStep() Allows to access the current simulation step.
      abstract Time getTime() Allows to know which is the current simulation time.
      abstract void goToStep(long steps) Executes a certain number of steps, then pauses it.
      abstract void goToTime(Time t) Executes the simulation until the target time is reached, then pauses it.
      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.
      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.
      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).
      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).
      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).
      abstract void pause() Sends a pause command to the simulation.
      abstract void play() Sends a play command to the simulation.
      abstract void reactionAdded(Reaction<T> reactionToAdd) Adds a reaction during the simulation to the scheduler and start to execute it.
      abstract void reactionRemoved(Reaction<T> reactionToRemove) Removes a reaction during the simulation from the scheduler and stop to execute it.
      abstract void removeOutputMonitor(OutputMonitor<T, P> op) Removes an OutputMonitor to this simulation.
      abstract void schedule(CheckedRunnable r) Schedules a runnable to be executed by the Simulation thread, useful for synchronization purposes (e.g.
      abstract void terminate() Sends a terminate command to the simulation.
      abstract Status waitFor(Status s, long timeout, TimeUnit timeunit) Suspends the caller until the simulation reaches the selected Status or the timeout ends.
      • Methods inherited from class java.lang.Runnable

        run
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • getFinalTime

         abstract Time getFinalTime()

        Allows to at which time this simulation will end.

      • getStatus

         abstract Status getStatus()

        Allows to access the current status.

      • getStep

         abstract long getStep()

        Allows to access the current simulation step.

      • getTime

         abstract Time getTime()

        Allows to know which is the current simulation time.

      • 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 node
        n - 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 node
        n - 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 node
        oldNeighborhood - 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
      • 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.

      • waitFor

         abstract Status waitFor(Status s, long timeout, TimeUnit timeunit)

        Suspends the caller until the simulation reaches the selected Status or the timeout ends. Please note that waiting for a status does not mean that every OutputMonitor will already be notified of the update.

        Parameters:
        s - The Status the simulation should reach before returning from this method
        timeout - The maximum lapse of time the caller wants to wait before being resumed
        timeunit - The TimeUnit used to define "timeout"