Pubsub

class maze.core.events.pubsub.Pubsub(event_collector: maze.core.events.event_service.EventService)

Implementation of a message broker (Pubsub stands for publish and subscribe).

clear_events()None

Resets the aggregated events of all registered subscribers

Returns

None

create_event_topic(interface_class: Type[T]) → T

Returns a proxy instance of the event interface, which the publisher can use to publish events. Behind the scenes every event invocation is serialized as EventRecord object and then routed to the registered subscribers.

Parameters

interface_class – The class object of an abstract interface that defines the events as methods.

Returns

A proxy object, dynamically derived from the passed interface_class. This class is intended to be used by the publisher to trigger events.

interface_to_subscribers: Dict[Type[T], List[Subscriber]]

map of interface class to the list of subscribed receivers

notify_event(event: maze.core.events.event_record.EventRecord)None

Notify about a new event. This is invoked by the EventService.

:param event The event to be added.

register_subscriber(new_subscriber: maze.core.events.pubsub.Subscriber)
Register a subscriber to receive events from certain published interfaces,

specified by Subscriber.get_interfaces()

Parameters

new_subscriber – the subscriber to be registered

Returns

None

subscribers: List[Subscriber]

all registered subscribers