Simulation

A manager for a single simulation case.

We view a simulation as a case or workflow of simulated tasks. This class is responsible for keeping track of all the tasks for the corresponding simulation, informing the Coordinator of new tasks to be added and informing the simulation processes when a task is completed.

=Basic Interaction Flow= The interaction flow with the Coordinator is expected as follows:

  1. The simulation logic starts executing via run.
  2. Tasks are added via task.
  3. When the simulation logic finishes producing tasks, it should call ready.
  4. Eventually, one of the tasks completes and complete is called. The simulation logic resumes execution.
  5. The simulation may now produce further tasks in reaction to the completed one(s). It can either handle and acknowledge each completed task individually using ack or use ready in one go as above.
  6. When the simulation logic completes, it can use succeed (instead of ack or ready) to notify the Coordinator of its result.

=Additional Functions= The simulation may also:

  1. React to things happening to other simulations. It can send a request to wait using simWait. The Coordinator will then wait for the Simulation to send new tasks or to complete, as if a task just completed. This needs to happen while the Coordinator is still waiting for the other simulation(s) we are reacting to.
  2. Abort previously added tasks using abort.
  3. Report completion due to failure using fail.
  4. Optionally maintain a Lookahead structure of future tasks, returning it through getLookahead.
Companion
object
class Object
trait Matchable
class Any

Document{}

def abort(ids: UUID*): Unit

Declare IDs of TaskInstances that need to be aborted.

Declare IDs of TaskInstances that need to be aborted.

Value Params
ids

The UUIDs of the TaskInstances.

def ack(taskIDs: Seq[UUID]): Unit

Declares that the simulation has finished processing one or more completed TaskInstances.

Declares that the simulation has finished processing one or more completed TaskInstances.

Identifies the tasks via their UUID.

def complete(task: TaskInstance, time: Long): Unit

Manages a completed TaskInstance.

Manages a completed TaskInstance.

The simulation logic must react to this by either registering more tasks or finishing.

If new tasks are produced, the completed TaskInstance must be acknowledged via ack. Alternatively, if we do not want to ack all completed tasks, we can just call ready. Finally, if the simulation completes, we can use done, succeed or fail accordingly.

Value Params
task

The completed TaskInstance.

time

The timestamp of completion and current time.

def done(result: Try[Any]): Unit

Declares that the simulation completed.

Declares that the simulation completed.

Value Params
result

The result of the simulation.

def fail(exception: Throwable): Unit

Declares that the simulation has failed or has been aborted.

Declares that the simulation has failed or has been aborted.

Value Params
exception

The Throwable that caused the failure.

Calculates an optional Lookahead structure for tasks that are expected in the future.

Calculates an optional Lookahead structure for tasks that are expected in the future.

This is called via ready.

Returns

The current Lookahead structure.

def ready(): Unit

Declares that the simulation has finished calculating and is ready for virtual time to proceed.

Declares that the simulation has finished calculating and is ready for virtual time to proceed.

def simWait(): Unit

Requests that the Manager waits for this simulation before it continues.

Requests that the Manager waits for this simulation before it continues.

The simulation needs to either register more tasks and become ready or finish.

Note

We assume the Manager is already waiting for another simulation when the request is made. Otherwise virtual time may progress unexpectedly and cause unpredictable behaviour depending on the timing of the Manager messages.

def succeed(result: Any): Unit

Declares that the simulation completed successfully.

Declares that the simulation completed successfully.

Value Params
result

The successful result of the simulation.

def task(t: Task): Unit

Declare a new Task that needs to be sent for simulation.

Declare a new Task that needs to be sent for simulation.

Value Params
t

The Task to send.

Value members

Concrete methods

override
def completed(time: Long, tasks: Seq[TaskInstance]): Unit
Definition Classes

Inherited methods

def name: String

A unique name for the simulation.

A unique name for the simulation.

Returns

The name of the SimulationRef.

Inherited from
SimulationRef
def run(): Unit

Starts the simulation.

Starts the simulation.

Inherited from
SimulationRef
def stop(): Unit

Stops/aborts the simuation.

Stops/aborts the simuation.

Inherited from
SimulationRef