application¶
The application layer brings together the domain and infrastructure layers.
simple¶
-
class
eventsourcing.application.simple.
SimpleApplication
(name='', persistence_policy=None, persist_event_type=None, cipher_key=None, sequenced_item_class=None, sequenced_item_mapper_class=None, record_manager_class=None, stored_event_record_class=None, event_store_class=None, snapshot_record_class=None, setup_table=True, contiguous_record_ids=True, pipeline_id=0, json_encoder_class=None, json_decoder_class=None, notification_log_section_size=None)[source]¶ Bases:
abc.ABC
Base class for event sourced applications.
Constructs infrastructure objects such as the repository and event store, and also the notification log which presents the application state as a sequence of events.
Needs actual infrastructure classes.
-
infrastructure_factory_class
¶ alias of
eventsourcing.infrastructure.factory.InfrastructureFactory
-
__init__
(name='', persistence_policy=None, persist_event_type=None, cipher_key=None, sequenced_item_class=None, sequenced_item_mapper_class=None, record_manager_class=None, stored_event_record_class=None, event_store_class=None, snapshot_record_class=None, setup_table=True, contiguous_record_ids=True, pipeline_id=0, json_encoder_class=None, json_decoder_class=None, notification_log_section_size=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
event_store_class
¶
-
construct_infrastructure_factory
(*args, **kwargs)[source]¶ Return type: InfrastructureFactory
-
-
class
eventsourcing.application.simple.
ApplicationWithConcreteInfrastructure
(name='', persistence_policy=None, persist_event_type=None, cipher_key=None, sequenced_item_class=None, sequenced_item_mapper_class=None, record_manager_class=None, stored_event_record_class=None, event_store_class=None, snapshot_record_class=None, setup_table=True, contiguous_record_ids=True, pipeline_id=0, json_encoder_class=None, json_decoder_class=None, notification_log_section_size=None)[source]¶ Bases:
eventsourcing.application.simple.SimpleApplication
Subclasses have actual infrastructure.
snapshotting¶
policies¶
notificationlog¶
-
class
eventsourcing.application.notificationlog.
AbstractNotificationLog
[source]¶ Bases:
abc.ABC
Presents a sequence of sections from a sequence of notifications.
-
class
eventsourcing.application.notificationlog.
Section
(section_id, items, previous_id=None, next_id=None)[source]¶ Bases:
object
Section of a notification log.
Contains items, and has an ID.
May also have either IDs of previous and next sections of the notification log.
-
class
eventsourcing.application.notificationlog.
LocalNotificationLog
(section_size=None)[source]¶ Bases:
eventsourcing.application.notificationlog.AbstractNotificationLog
Presents a sequence of sections from a sequence of notifications.
-
class
eventsourcing.application.notificationlog.
RecordManagerNotificationLog
(record_manager, section_size)[source]¶ Bases:
eventsourcing.application.notificationlog.LocalNotificationLog
-
class
eventsourcing.application.notificationlog.
BigArrayNotificationLog
(big_array, section_size)[source]¶ Bases:
eventsourcing.application.notificationlog.LocalNotificationLog
-
class
eventsourcing.application.notificationlog.
NotificationLogReader
(notification_log, use_direct_query_if_available=False)[source]¶ Bases:
abc.ABC
-
__init__
(notification_log, use_direct_query_if_available=False)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
seek
(position)[source]¶ Sets position of reader in notification log sequence.
This represents the position of the last notification read by the reader. The next notification returned by the reader will be the next position.
Parameters: position (int) – Position is notification log sequence. Raises: ValueError – if the position is less than zero
-
django¶
-
class
eventsourcing.application.django.
DjangoApplication
(name='', persistence_policy=None, persist_event_type=None, cipher_key=None, sequenced_item_class=None, sequenced_item_mapper_class=None, record_manager_class=None, stored_event_record_class=None, event_store_class=None, snapshot_record_class=None, setup_table=True, contiguous_record_ids=True, pipeline_id=0, json_encoder_class=None, json_decoder_class=None, notification_log_section_size=None)[source]¶ Bases:
eventsourcing.application.simple.ApplicationWithConcreteInfrastructure
-
record_manager_class
¶ alias of
eventsourcing.infrastructure.django.manager.DjangoRecordManager
-
stored_event_record_class
¶ alias of
eventsourcing.infrastructure.django.models.StoredEventRecord
-
snapshot_record_class
¶ alias of
eventsourcing.infrastructure.django.models.EntitySnapshotRecord
-
sqlalchemy¶
-
class
eventsourcing.application.sqlalchemy.
SQLAlchemyApplication
(uri=None, session=None, **kwargs)[source]¶ Bases:
eventsourcing.application.simple.ApplicationWithConcreteInfrastructure
-
infrastructure_factory_class
¶ alias of
eventsourcing.infrastructure.sqlalchemy.factory.SQLAlchemyInfrastructureFactory
-
stored_event_record_class
¶ alias of
eventsourcing.infrastructure.sqlalchemy.records.StoredEventRecord
-
snapshot_record_class
¶ alias of
eventsourcing.infrastructure.sqlalchemy.records.EntitySnapshotRecord
-
popo¶
-
class
eventsourcing.application.popo.
PopoApplication
(name='', persistence_policy=None, persist_event_type=None, cipher_key=None, sequenced_item_class=None, sequenced_item_mapper_class=None, record_manager_class=None, stored_event_record_class=None, event_store_class=None, snapshot_record_class=None, setup_table=True, contiguous_record_ids=True, pipeline_id=0, json_encoder_class=None, json_decoder_class=None, notification_log_section_size=None)[source]¶ Bases:
eventsourcing.application.simple.ApplicationWithConcreteInfrastructure
-
infrastructure_factory_class
¶ alias of
eventsourcing.infrastructure.popo.factory.PopoInfrastructureFactory
-
sequenced_item_mapper_class
¶ alias of
eventsourcing.infrastructure.popo.mapper.SequencedItemMapperForPopo
-
pipeline¶
-
class
eventsourcing.application.pipeline.
PipelineExpression
(left, right)[source]¶ Bases:
object
Implements a left-to-right association between two objects.
process¶
-
class
eventsourcing.application.process.
ProcessApplication
(name=None, policy=None, setup_table=False, **kwargs)[source]¶ Bases:
eventsourcing.application.pipeline.Pipeable
,eventsourcing.application.simple.SimpleApplication
-
__init__
(name=None, policy=None, setup_table=False, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
publish_prompt
(event=None)[source]¶ Publishes prompt for a given event.
Used to prompt downstream process application when an event is published by this application’s model, which can happen when application command methods, rather than the process policy, are called.
Wraps exceptions with PromptFailed, to avoid application policy exceptions being seen directly in other applications when running synchronously in single thread.
-
-
class
eventsourcing.application.process.
ProcessApplicationWithSnapshotting
(snapshot_period=None, snapshot_record_class=None, **kwargs)[source]¶ Bases:
eventsourcing.application.snapshotting.SnapshottingApplication
,eventsourcing.application.process.ProcessApplication
command¶
-
class
eventsourcing.application.command.
CommandProcess
(name=None, policy=None, setup_table=False, **kwargs)[source]¶ Bases:
eventsourcing.application.process.ProcessApplication
-
persist_event_type
¶
-
system¶
-
class
eventsourcing.application.system.
SystemRunner
(system: eventsourcing.application.system.System, infrastructure_class=None, setup_tables=False)[source]¶ Bases:
abc.ABC
-
class
eventsourcing.application.system.
InProcessRunner
(system: eventsourcing.application.system.System, infrastructure_class=None, setup_tables=False)[source]¶ Bases:
eventsourcing.application.system.SystemRunner
Runs a system in the current process, either in the current thread, or with one thread for each process in the system.
-
class
eventsourcing.application.system.
SingleThreadedRunner
(system: eventsourcing.application.system.System, infrastructure_class=<class 'eventsourcing.application.popo.PopoApplication'>, *args, **kwargs)[source]¶ Bases:
eventsourcing.application.system.InProcessRunner
Runs a system in the current thread.
-
__init__
(system: eventsourcing.application.system.System, infrastructure_class=<class 'eventsourcing.application.popo.PopoApplication'>, *args, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
eventsourcing.application.system.
MultiThreadedRunner
(system: eventsourcing.application.system.System, poll_interval=None, clock_speed=None)[source]¶ Bases:
eventsourcing.application.system.InProcessRunner
Runs a system with a thread for each process.
-
__init__
(system: eventsourcing.application.system.System, poll_interval=None, clock_speed=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
eventsourcing.application.system.
PromptQueuedApplicationThread
(process: eventsourcing.application.process.ProcessApplication, poll_interval=5, inbox=None, outbox=None, clock_event=None)[source]¶ Bases:
threading.Thread
Application thread which uses queues of prompts.
It loops on an “inbox” queue of prompts, and adds its prompts to an “outbox” queue.
-
__init__
(process: eventsourcing.application.process.ProcessApplication, poll_interval=5, inbox=None, outbox=None, clock_event=None)[source]¶ This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
-
class
eventsourcing.application.system.
PromptOutbox
[source]¶ Bases:
object
Has a collection of downstream prompt inboxes.
-
class
eventsourcing.application.system.
SteppingRunner
(normal_speed=1, scale_factor=1, is_verbose=False, *args, **kwargs)[source]¶
-
class
eventsourcing.application.system.
SteppingSingleThreadedRunner
(*args, **kwargs)[source]¶
-
class
eventsourcing.application.system.
ClockThread
(*args, **kwargs)[source]¶ Bases:
threading.Thread
-
__init__
(*args, **kwargs)[source]¶ This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
-
class
eventsourcing.application.system.
ProcessRunningClockThread
(normal_speed, scale_factor, stop_event: threading.Event, is_verbose=False, seen_prompt_events=None, processes=None)[source]¶ Bases:
eventsourcing.application.system.ClockThread
-
__init__
(normal_speed, scale_factor, stop_event: threading.Event, is_verbose=False, seen_prompt_events=None, processes=None)[source]¶ This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
-
class
eventsourcing.application.system.
SteppingMultiThreadedRunner
(*args, **kwargs)[source]¶ Bases:
eventsourcing.application.system.SteppingRunner
Has a clock thread, and a thread for each application process in the system. The clock thread loops until stopped, waiting for a barrier, after sleeping for remaining tick interval timer. Application threads loop until stopped, waiting for the same barrier. Then, after all threads are waiting at the barrier, the barrier is lifted. The clock thread proceeds by sleeping for the clock tick interval. The application threads proceed by getting new notifications and processing all of them.
There are actually two barriers, so that each application thread waits before getting notifications, and then waits for all processes to complete getting notification before processing the notifications through the application policy. This avoids events created by a process application “bleeding” into the notifications of another process application in the same clock cycle.
Todo: Receive prompts, but set an event for the prompting process, to avoid unnecessary runs.
Allow commands to be scheduled at future clock tick number, and execute when reached.
-
class
eventsourcing.application.system.
BarrierControlledApplicationThread
(process: eventsourcing.application.process.ProcessApplication, fetch_barrier: threading.Barrier, execute_barrier: threading.Barrier, stop_event: threading.Event)[source]¶ Bases:
threading.Thread
-
__init__
(process: eventsourcing.application.process.ProcessApplication, fetch_barrier: threading.Barrier, execute_barrier: threading.Barrier, stop_event: threading.Event)[source]¶ This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
-
class
eventsourcing.application.system.
BarrierControllingClockThread
(normal_speed, scale_factor, tick_interval, fetch_barrier: threading.Barrier, execute_barrier: threading.Barrier, stop_event: threading.Event, is_verbose=False)[source]¶ Bases:
eventsourcing.application.system.ClockThread
-
__init__
(normal_speed, scale_factor, tick_interval, fetch_barrier: threading.Barrier, execute_barrier: threading.Barrier, stop_event: threading.Event, is_verbose=False)[source]¶ This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
multiprocess¶
-
class
eventsourcing.application.multiprocess.
MultiprocessRunner
(system: eventsourcing.application.system.System, pipeline_ids=(0, ), poll_interval=None, setup_tables=False, sleep_for_setup_tables=0, *args, **kwargs)[source]¶
-
class
eventsourcing.application.multiprocess.
OperatingSystemProcess
(application_process_class, infrastructure_class, upstream_names, pipeline_id=0, poll_interval=5, setup_tables=False, inbox=None, outbox=None, *args, **kwargs)[source]¶ Bases:
multiprocessing.context.Process
actors¶
-
class
eventsourcing.application.actors.
ActorModelRunner
(system: eventsourcing.application.system.System, pipeline_ids, system_actor_name='system', shutdown_on_close=False, **kwargs)[source]¶ Bases:
eventsourcing.application.system.SystemRunner
Uses actor model framework to run a system of process applications.
-
class
eventsourcing.application.actors.
SystemActor
[source]¶ Bases:
thespian.actors.Actor
-
__init__
()[source]¶ Called to initialize the Actor.
Override this initialization method as needed in defined Actors.
N.B. Currently the Actor is not yet fully realized in the ActorSystem when __init__ is invoked. This means that the Actor __init__ cannot invoke any ActorSystem-related operations (no .send(), .handleDeadLetters(), .notifyOnSystemRegistrationChanges(), etc.)
Also note that there is post-__init__ processing of a created Actor object by the ActorSystem that is necessary for it to become a full Actor. The Actor’s __init__() must not perform Actor-related operations, and the __init__() is not sufficient to fully initialize an Actor object. This ensures that the ActorSystem is involved in the creation of a useable Actor (i.e. the ActorSystem is the Factory for an Actor).
-
-
class
eventsourcing.application.actors.
PipelineActor
[source]¶ Bases:
thespian.actors.Actor
-
__init__
()[source]¶ Called to initialize the Actor.
Override this initialization method as needed in defined Actors.
N.B. Currently the Actor is not yet fully realized in the ActorSystem when __init__ is invoked. This means that the Actor __init__ cannot invoke any ActorSystem-related operations (no .send(), .handleDeadLetters(), .notifyOnSystemRegistrationChanges(), etc.)
Also note that there is post-__init__ processing of a created Actor object by the ActorSystem that is necessary for it to become a full Actor. The Actor’s __init__() must not perform Actor-related operations, and the __init__() is not sufficient to fully initialize an Actor object. This ensures that the ActorSystem is involved in the creation of a useable Actor (i.e. the ActorSystem is the Factory for an Actor).
-
-
class
eventsourcing.application.actors.
ProcessMaster
[source]¶ Bases:
thespian.actors.Actor
-
__init__
()[source]¶ Called to initialize the Actor.
Override this initialization method as needed in defined Actors.
N.B. Currently the Actor is not yet fully realized in the ActorSystem when __init__ is invoked. This means that the Actor __init__ cannot invoke any ActorSystem-related operations (no .send(), .handleDeadLetters(), .notifyOnSystemRegistrationChanges(), etc.)
Also note that there is post-__init__ processing of a created Actor object by the ActorSystem that is necessary for it to become a full Actor. The Actor’s __init__() must not perform Actor-related operations, and the __init__() is not sufficient to fully initialize an Actor object. This ensures that the ActorSystem is involved in the creation of a useable Actor (i.e. the ActorSystem is the Factory for an Actor).
-
-
class
eventsourcing.application.actors.
ProcessSlave
[source]¶ Bases:
thespian.actors.Actor
-
__init__
()[source]¶ Called to initialize the Actor.
Override this initialization method as needed in defined Actors.
N.B. Currently the Actor is not yet fully realized in the ActorSystem when __init__ is invoked. This means that the Actor __init__ cannot invoke any ActorSystem-related operations (no .send(), .handleDeadLetters(), .notifyOnSystemRegistrationChanges(), etc.)
Also note that there is post-__init__ processing of a created Actor object by the ActorSystem that is necessary for it to become a full Actor. The Actor’s __init__() must not perform Actor-related operations, and the __init__() is not sufficient to fully initialize an Actor object. This ensures that the ActorSystem is involved in the creation of a useable Actor (i.e. the ActorSystem is the Factory for an Actor).
-