baroque.entities package¶
Submodules¶
baroque.entities.event module¶
-
class
baroque.entities.event.
Event
(eventtype, payload=None, description=None, owner=None)¶ Bases:
object
An event that can be published.
Parameters: - eventtype (
baroque.entities.eventtype.EventType
instance or type object) – the type of the event - payload (dict, optional) – the content of this event
- description (str, optional) – the description of this event
- owner (str, optional) – the owner of this event
-
json
()¶ Dumps this object to a JSON string.
Returns: str
-
md5
()¶ Returns the MD5 hash of this object.
Returns: str
-
set_published
()¶ Sets the status of this event to published.
-
set_unpublished
()¶ Sets the status of this event to unpublished.
-
touch
()¶ Sets the current time as timestamp of this event
- eventtype (
baroque.entities.eventtype module¶
-
class
baroque.entities.eventtype.
EventType
(jsonschema, description=None, owner=None)¶ Bases:
object
The type of an event, describing its semantics and content.
Parameters: - jsonschema (str) – the JSON schema string describing the content of the events having this type
- description (str, optional) – the description of this event type
- owner (str, optional) – the owner of this event type
-
json
()¶ Dumps this object to a JSON string.
Returns: str
-
md5
()¶ Returns the MD5 hash of this object.
Returns: str
-
static
validate
(evt, evttype)¶ Validates the content of an event against the JSON schema of its type.
Parameters: - evt (
baroque.entities.event.Event
) – the event to be validated - evttype (
baroque.entities.eventtype.EventType
) – the type of - event that needs to be validated (the) –
Returns: True
if validation is OK,False
otherwise- evt (
baroque.entities.reactor module¶
-
class
baroque.entities.reactor.
Reactor
(reaction, condition=None)¶ Bases:
object
An action to be executed whenever some type of events are published, with an optional condition to be satisfied satisfied. If a condition is set, this is checked out and if the outcome is
True
then the action is executed. If no condition is set, then the action is always executed.Parameters: - reaction (function) – the action to be executed
- condition (function, optional) – the boolean condition to be satisfied
Raises: AssertionError – when the supplied reaction is None or is not a callable, or (when supplied) when the condition is not a callable
-
count_reactions
()¶ Gives the number of times this reactor’s action has been executed
Returns: int
-
last_event_reacted
()¶ Gives the ID of the last event this reactor reacted on
Returns: str
-
last_reacted_on
()¶ Gives the timestamp of the last time when the reactor’s action has been executed
Returns: str if reactor reacted at least once, None
otherwise
-
only_if
(condition)¶ Sets the boolean condition for this reactor.
Parameters: condition (function) – the boolean condition to be satisfied
-
react
(event)¶ Execute the action of this reactor.
Note
the condition of this reactor is out of the scope of this method (please see method :obj:
react_conditionally()
)Parameters: - reaction (function) – the action to be executed
- condition (function, optional) – the boolean condition to be satisfied
-
react_conditionally
(event)¶ First checks if the condition is satisfied, then based on the outcome executes the action.
Parameters: event ( baroque.entities.event.Event
) – the triggering event
baroque.entities.topic module¶
-
class
baroque.entities.topic.
Topic
(name, eventtypes, description=None, owner=None, tags=None)¶ Bases:
object
A distribution channel where events of specific types can be published and can be seen by subscribers of the topic. Topic subscribers will attach a reactor to the topic, which will be fired whenever any event of the types that are supported by the topic is published on the topic itself.
Parameters: - name (str) – the name of this topic
- eventtypes (collection) – the
baroque.entities.eventtype.EventType
objects that characterize this topic - description (str, optional) – a description of this topic
- owner (str, optional) – the owner of this topic
- tags (set, optional) – the set of tags that describe this topic
Raises: AssertionError – name or tags are None or have a wrong type
-
eventtypes
¶ baroque.datastructures.bags.EventTypesBag
– bag containing the event types of this topic
-
json
()¶ Dumps this object to a JSON string.
Returns: str
-
md5
()¶ Returns the MD5 hash of this object.
Returns: str
-
touch
()¶ Sets the current time as timestamp of this topic