Event Interface
The EventInterface is exposed off the builder
and provides two methods: get_emitter,
which returns a callable emitter for the given event type and
register_listener, which adds the
given listener to the event channel for the given event. This is the only part
of the event framework with which client code should interact.
For more information, see the associated event concept note.
- class vivarium.framework.event.interface.EventInterface(manager)[source]
The public interface for the
~system.- Parameters:
manager (EventManager)
- get_emitter(event_name)[source]
Gets an emitter for a named
Event.- Parameters:
event_name (str) – The name of the
Eventthe requested emitter will emit. Users may provide their own namedEventsby requesting an emitter with this function, but should do so with caution as it makes time much more difficult to think about.- Returns:
An emitter for the named
Event. The emitter should be called by the requesting component at the appropriate point in the simulation lifecycle.- Return type:
- register_listener(event_name, listener, priority=5)[source]
Registers a callable as a listener to an
Eventwith the given name.The listening callable will be called with a named
Eventas its only argument any time theEventemitter is invoked from somewhere in the simulation.The framework creates the following
Eventsand emits them at different points in the simulation:At the end of the setup phase:
post_setupEvery time step: -
time_step__prepare-time_step-time_step__cleanup-collect_metricsAt simulation end:
simulation_end
- Parameters:
event_name (str) – The name of the
Eventto listen for.listener (Callable[[Event], None]) – The callable to be invoked any time an
Eventwith the given name is emitted.priority (int) – One of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. An indication of the order in which
Eventlisteners should be called. Listeners with smaller priority values will be called earlier. Listeners with the same priority have no guaranteed ordering. This feature should be avoided if possible. Components should strive to obey the Markov property as they transform the state table (the state of the simulation at the beginning of the next time step should only depend on the current state of the system).
- Return type: