baroque.datastructures package¶
Submodules¶
baroque.datastructures.bags module¶
-
class
baroque.datastructures.bags.EventTypesBag(eventtypes=None)¶ Bases:
objectA type-aware collection of event types
Parameters: eventtypes (collection, optional) – collection of baroque.entities.eventtypes.EventTypeitems.-
add(eventtypes)¶ Adds a collection of eventtypes to this bag.
Parameters: of (list) – the event types to be added Raises: AssertionError – when the supplied arg is not a collection or its items are not baroque.entities.eventtypes.EventTypeinstances orbaroque.entities.eventtypes.EventTypesubclasses
-
-
class
baroque.datastructures.bags.ReactorsBag¶ Bases:
objectA type-aware collection of reactors.
-
count()¶ Tells how many reactors are in this bag.
Returns: int
-
remove(reactor)¶ Removes a reactor from this bag.
Parameters: reactor ( baroque.entities.reactor.Reactor) – the reactor to be removed
-
remove_all()¶ Removes all reactors from this bag.
-
run(reactor)¶ Adds a reactor to this bag.
Parameters: reactor ( baroque.entities.reactor.Reactor) – the reactor to be addedRaises: AssertionError – when the supplied arg is not a baroque.entities.reactor.Reactorinstance
-
trigger(reactor)¶ Alias for baroque.datastructures.bags.ReactorBag.run method
Parameters: reactor ( baroque.entities.reactor.Reactor) – the reactor to be addedRaises: AssertionError – when the supplied arg is not a baroque.entities.reactor.Reactorinstance
-
baroque.datastructures.counters module¶
-
class
baroque.datastructures.counters.EventCounter¶ Bases:
objectA counter of events.
-
count(eventtype)¶ Tells how many events have been counted of the specified type
Parameters: eventtype ( baroque.entities.eventtype.EventType) – the type of events to be countedReturns: int
-
count_all()¶ Tells how many events have been counted globally
Returns: int
-
increment_counting(event)¶ Counts an event
Parameters: event ( baroque.entities.event.Event) – the event to be counted
-
baroque.datastructures.registries module¶
-
class
baroque.datastructures.registries.EventTypesRegistry¶ Bases:
objectInterface adapter to an event bag.
-
count()¶ Tells how many event types are registered on this registry
Returns: int
-
register(eventtype)¶ Adds an event type to this registry.
Parameters: eventtype ( baroque.entities.eventtypes.EventTypeinstance or type object) – the event type to be addedRaises: AssertionError – when argument is not an baroque.entities.eventtypes.EventTypeinstance or a type object
-
remove(eventtype)¶ Removes an event type from this registry
Parameters: eventtype ( baroque.entities.eventtypes.EventTypeinstance or type object) – the event type to be removedRaises: AssertionError – when argument is not an baroque.entities.eventtypes.EventTypeinstance or a type object
-
remove_all()¶ Removes all event types from this registry.
-
-
class
baroque.datastructures.registries.ReactorsRegistry¶ Bases:
objectA tracker for reaactors. Each reactor is intended to be executed when a certain type of events is fired: the reactors-eventtypes relationship is stored internally using a dict of bag datastructures.
Some reactors must be executed upon any event firing: these are stored internally into a “jolly bag”.
-
get_bag(eventtype)¶ Gives the reactors bag associated to the specified event type.
Parameters: eventtype ( baroque.entities.eventtype.EventType) – the associated event typeReturns: baroque.datastructures.bags.ReactorsBagRaises: AssertionError – when the supplied event type is not a baroque.entities.eventtype.EventTypeinstance or a type object
-
get_event_types_registry()¶ Gives the encapsulated event type registry
Returns: baroque.registries.EventTypeRegistry
-
get_jolly_bag()¶ Gives the encapsulated bag that contains reactors to be executed upon any event firing.
Returns: baroque.registries.EventTypeRegistry
-
get_or_create_bag(eventtype)¶ Gives the reactors bag associated to the specified event type, or creates one in case it does not exist yet.
Parameters: eventtype ( baroque.entities.eventtype.EventTypeinstance or type object) – the associated event typeReturns: baroque.datastructures.bags.ReactorsBagRaises: AssertionError – when the supplied event type is not a baroque.entities.eventtype.EventTypeinstance or a type object
-
remove_all()¶ Clears the contents of all the encapsulated reactor bags.
-
to(eventtype)¶ Gives the encapsulated bag that contains reactors to be executed upon the firing of events of the supplied type.
Parameters: eventtype ( baroque.entities.eventtype.EventType) – the associated event typeReturns: baroque.datastructures.bags.ReactorsBag
-
to_any_event()¶ Gives the encapsulated jolly bag, containing reactors to be executed upon the firing of any event.
Returns: baroque.datastructures.bags.ReactorsBag
-
-
class
baroque.datastructures.registries.TopicsRegistry¶ Bases:
objectA tracker for reactors to be executed upong event firing of events on specified topics: the reactors-topics relationship is stored internally using a dict
-
count()¶ Tells how many topics are registered.
Returns: int
-
new(name, eventtypes, **kwargs)¶ Creates a new topic, adds it to the registry and returns it.
Parameters: name (str) – name of the new topic - eventtypes (collection): the
baroque.entities.eventtype.EventTypeobjects that characterize the new topic - **kwargs: positional arguments for Topic instantiation
Returns: baroque.entities.topic.Topic- eventtypes (collection): the
-
of(owner)¶ Returns the topics belonging to the supplied owner
Parameters: owner (str) – the topics owner Returns: list of baroque.entities.topic.Topicitems
-
on_topic_run(topic, reactor)¶ Binds the specified reactor to event firing on the specified topic.
Parameters: - topic (:obj:`baroque.entities.topic.Topic) – the topic
- reactor (
baroque.entities.reactor.Reactor) – the reactor
Raises: AssertionError – when any of the supplied args is of wrong type
-
publish_on_topic(event, topic)¶ - Publishes an event on a tracked topic, executing all the reactors
- bound to that topic.
Parameters: - event (:obj:`baroque.entities.event.Event) – the event to be published
- topic (:obj:`baroque.entities.topic.Topic) – the target topic
Raises: AssertionError – when any of the supplied args is of wrong type
-
register(topic)¶ Adds a topic to the registry.
Parameters: topic ( baroque.entities.topic.Topic) – the topic to be added
-
remove(topic)¶ Removes a topic from the registry.
Parameters: topic ( baroque.entities.topic.Topic) – the topic to be removed
-
remove_all()¶ Clears all the topics from the registry.
-
with_id(id)¶ Returns the topic with the specified identifier
Parameters: id (str) – the topic id Returns: baroque.entities.topic.Topic
-
with_name(name)¶ Returns the topic with the specified name (exact string matching)
Parameters: name (str) – the topic name Returns: baroque.entities.topic.Topic
Returns the topics marked by the specified tags.
Parameters: tags (set of str items) – the tag set Returns: list of baroque.entities.topic.TopicitemsRaises: AssertionError – when the supplied tag set is not an iterable
-