Skip to main content

Broker

MaaS Blender advances the simulation through the coordinated execution of multiple components that interact exclusively via events. At any given simulation time, only one component is active; components never execute in parallel. The order in which components are executed is fully deterministic, and as long as each component itself behaves deterministically, the entire simulation is deterministic.

The Broker is responsible for controlling this execution order. It selects which component should run next, invokes that component to generate events, and then propagates the generated events to all other components.

Component Interface

Each simulation component must expose the following three APIs:

  • peek() Returns the simulation time at which the component’s next event is scheduled to occur.

  • step() Executes the component and causes it to emit one or more events.

  • triggered(event) Receives an event that was generated by another component.

Simulation Loop

The simulation progresses by repeatedly executing the following steps:

  1. The Broker calls peek() on all components and selects the component with the smallest returned time.
  2. The Broker invokes step() on the selected component. The component executes and returns the events it has generated.
  3. The Broker propagates each generated event by invoking triggered(event) on all components.
  4. The process returns to step 1 and continues until the simulation terminates.

Through this loop, the Broker ensures that events are processed in strict temporal order and that component interactions remain consistent and reproducible.

API Details

  • peek()

    • Returns:

      { "next": number }

      where next is the simulation time at which the component’s next event will occur.

  • step()

    • Returns:

      { "now": number, "events": Event[] }

      where now is the simulation time at which the events occur. If multiple events occur at the same time, they are returned as an array.

  • triggered(event)

    • Arguments:

      • event: an event emitted by another component
    • Returns: none