T
- The type of the aggregate root objectpublic class EventSourcedAggregate<T> extends AnnotatedAggregate<T>
Aggregate
that is sourced from events that have
been published by the aggregate.Modifier | Constructor and Description |
---|---|
protected |
EventSourcedAggregate(AggregateModel<T> model,
EventBus eventBus,
RepositoryProvider repositoryProvider,
SnapshotTrigger snapshotTrigger)
Creates a new EventSourcedAggregate instance based on the given
model , which publishes events to the
given eventBus . |
protected |
EventSourcedAggregate(AggregateModel<T> model,
EventBus eventBus,
SnapshotTrigger snapshotTrigger)
Creates a new EventSourcedAggregate instance based on the given
model , which publishes events to the
given eventBus . |
protected |
EventSourcedAggregate(T aggregateRoot,
AggregateModel<T> model,
EventBus eventBus,
RepositoryProvider repositoryProvider,
SnapshotTrigger snapshotTrigger)
Initializes an Aggregate instance for the given
aggregateRoot , based on the given model , which
publishes events to the given eventBus . |
protected |
EventSourcedAggregate(T aggregateRoot,
AggregateModel<T> model,
EventBus eventBus,
SnapshotTrigger snapshotTrigger)
Initializes an Aggregate instance for the given
aggregateRoot , based on the given model , which
publishes events to the given eventBus . |
Modifier and Type | Method and Description |
---|---|
<P> ApplyMore |
doApply(P payload,
MetaData metaData)
Apply a
DomainEventMessage with given payload and metadata (metadata from interceptors will be combined
with the provided metadata). |
protected boolean |
getIsLive()
Indicates whether this Aggregate instance is 'live'.
|
SnapshotTrigger |
getSnapshotTrigger()
The trigger instance that monitors this aggregate to trigger a snapshot
|
static <T> EventSourcedAggregate<T> |
initialize(Callable<T> aggregateFactory,
AggregateModel<T> inspector,
EventBus eventBus,
RepositoryProvider repositoryProvider,
SnapshotTrigger snapshotTrigger)
Initializes an EventSourcedAggregate instance using the given
aggregateFactory , based on the given inspector , which publishes events to the given eventBus and stores events in the given eventStore . |
static <T> EventSourcedAggregate<T> |
initialize(Callable<T> aggregateFactory,
AggregateModel<T> inspector,
EventBus eventBus,
SnapshotTrigger snapshotTrigger)
Initializes an EventSourcedAggregate instance using the given
aggregateFactory , based on the given inspector , which publishes events to the given eventBus and stores events in the given eventStore . |
static <T> EventSourcedAggregate<T> |
initialize(T aggregateRoot,
AggregateModel<T> inspector,
EventBus eventBus,
RepositoryProvider repositoryProvider,
SnapshotTrigger snapshotTrigger)
Initializes an EventSourcedAggregate instance for the given
aggregateRoot , based on the given inspector , which publishes events to the given eventBus . |
static <T> EventSourcedAggregate<T> |
initialize(T aggregateRoot,
AggregateModel<T> inspector,
EventBus eventBus,
SnapshotTrigger snapshotTrigger)
Initializes an EventSourcedAggregate instance for the given
aggregateRoot , based on the given inspector , which publishes events to the given eventBus . |
void |
initializeState(DomainEventStream eventStream)
Initialize the state of this Event Sourced Aggregate with the events from the given
eventStream . |
protected void |
publish(EventMessage<?> msg)
Publish an event to the aggregate root and its entities first and external event handlers (using the given
event bus) later.
|
protected void |
publishOnEventBus(EventMessage<?> msg)
Publish an event to external event handlers using the given event bus.
|
static <T> EventSourcedAggregate<T> |
reconstruct(T aggregateRoot,
AggregateModel<T> model,
long seqNo,
boolean isDeleted,
EventBus eventBus,
RepositoryProvider repositoryProvider,
SnapshotTrigger snapshotTrigger)
Reconstructs an EventSourcedAggregate instance with given
aggregateRoot . |
static <T> EventSourcedAggregate<T> |
reconstruct(T aggregateRoot,
AggregateModel<T> model,
long seqNo,
boolean isDeleted,
EventBus eventBus,
SnapshotTrigger snapshotTrigger)
Reconstructs an EventSourcedAggregate instance with given
aggregateRoot . |
Long |
version()
Gets the version of the aggregate.
|
andThen, andThenApply, applyMessageOrPayload, createMessage, doCreateNew, doMarkDeleted, execute, getAggregateRoot, handle, identifier, initialize, initialize, initialize, initialize, initialize, initialize, initSequence, initSequence, invoke, isDeleted, lastSequence, registerRoot, rootType, type
apply, apply, createNew, describeScope, execute, getInstance, getVersion, isLive, markDeleted, registerWithUnitOfWork
describeCurrentScope, endScope, executeWithResult, getCurrentScope, startScope
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
identifierAsString
protected EventSourcedAggregate(T aggregateRoot, AggregateModel<T> model, EventBus eventBus, SnapshotTrigger snapshotTrigger)
aggregateRoot
, based on the given model
, which
publishes events to the given eventBus
.aggregateRoot
- The aggregate root instancemodel
- The model describing the aggregate structureeventBus
- The event store to store generated events insnapshotTrigger
- The trigger to notify of events and initializationprotected EventSourcedAggregate(T aggregateRoot, AggregateModel<T> model, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger)
aggregateRoot
, based on the given model
, which
publishes events to the given eventBus
.aggregateRoot
- The aggregate root instancemodel
- The model describing the aggregate structureeventBus
- The event store to store generated events inrepositoryProvider
- Provides repositories for specific aggregate typessnapshotTrigger
- The trigger to notify of events and initializationprotected EventSourcedAggregate(AggregateModel<T> model, EventBus eventBus, SnapshotTrigger snapshotTrigger)
model
, which publishes events to the
given eventBus
. This aggregate is not assigned a root instance yet.model
- The model describing the aggregate structureeventBus
- The event store to store generated events insnapshotTrigger
- The trigger to notify of events and initializationAnnotatedAggregate.registerRoot(Callable)
protected EventSourcedAggregate(AggregateModel<T> model, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger)
model
, which publishes events to the
given eventBus
. This aggregate is not assigned a root instance yet.model
- The model describing the aggregate structureeventBus
- The event store to store generated events inrepositoryProvider
- Provides repositories for specific aggregate typessnapshotTrigger
- The trigger to notify of events and initializationAnnotatedAggregate.registerRoot(Callable)
public static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger)
aggregateRoot
, based on the given inspector
, which publishes events to the given eventBus
.T
- the aggregate root typeaggregateRoot
- The aggregate root instanceinspector
- The inspector describing the aggregate structureeventBus
- The event bus to send generated events tosnapshotTrigger
- The trigger to notify of events and initializationpublic static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger)
aggregateRoot
, based on the given inspector
, which publishes events to the given eventBus
.T
- the aggregate root typeaggregateRoot
- The aggregate root instanceinspector
- The inspector describing the aggregate structureeventBus
- The event bus to send generated events torepositoryProvider
- Provides repositories for specific aggregate typessnapshotTrigger
- The trigger to notify of events and initializationpublic static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) throws Exception
aggregateFactory
, based on the given inspector
, which publishes events to the given eventBus
and stores events in the given eventStore
.T
- the aggregate root typeaggregateFactory
- The aggregate root factoryinspector
- The inspector describing the aggregate structureeventBus
- The event bus to send generated events tosnapshotTrigger
- The trigger to notify of events and initializationException
- if the aggregate cannot be initializedpublic static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) throws Exception
aggregateFactory
, based on the given inspector
, which publishes events to the given eventBus
and stores events in the given eventStore
.T
- the aggregate root typeaggregateFactory
- The aggregate root factoryinspector
- The inspector describing the aggregate structureeventBus
- The event bus to send generated events torepositoryProvider
- Provides repositories for specific aggregate typessnapshotTrigger
- The trigger to notify of events and initializationException
- if the aggregate cannot be initializedpublic static <T> EventSourcedAggregate<T> reconstruct(T aggregateRoot, AggregateModel<T> model, long seqNo, boolean isDeleted, EventBus eventBus, SnapshotTrigger snapshotTrigger)
aggregateRoot
. The aggregate's sequence number
should be set to the given seqNo
and its deleted flag to the given isDeleted
.
Use this method to initialize an EventSourcedAggregate without having to replay the aggregate from events.
T
- the aggregate root typeaggregateRoot
- The aggregate root instancemodel
- The model describing the aggregate structureseqNo
- The last event sequence number of the aggregateisDeleted
- Flag to indicate whether or not the aggregate is deletedeventBus
- The event bus to send generated events tosnapshotTrigger
- The trigger to notify of events and initializationpublic static <T> EventSourcedAggregate<T> reconstruct(T aggregateRoot, AggregateModel<T> model, long seqNo, boolean isDeleted, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger)
aggregateRoot
. The aggregate's sequence number
should be set to the given seqNo
and its deleted flag to the given isDeleted
.
Use this method to initialize an EventSourcedAggregate without having to replay the aggregate from events.
T
- the aggregate root typeaggregateRoot
- The aggregate root instancemodel
- The model describing the aggregate structureseqNo
- The last event sequence number of the aggregateisDeleted
- Flag to indicate whether or not the aggregate is deletedeventBus
- The event bus to send generated events torepositoryProvider
- Provides repositories for specific aggregate typessnapshotTrigger
- The trigger to notify of events and initializationpublic <P> ApplyMore doApply(P payload, MetaData metaData)
AggregateLifecycle
DomainEventMessage
with given payload and metadata (metadata from interceptors will be combined
with the provided metadata). The event should be applied to the aggregate immediately and scheduled for
publication to other event handlers.
The event should be applied on all entities part of this aggregate. If the event is applied from an event handler
of the aggregate and additional events need to be applied that depends on state changes brought about by the
first event the returned ApplyMore
instance should allow for additional events to be applied after this
event.doApply
in class AnnotatedAggregate<T>
payload
- the payload of the event to applymetaData
- any meta-data that must be registered with the EventApplyMore
protected void publish(EventMessage<?> msg)
AnnotatedAggregate
publish
in class AnnotatedAggregate<T>
msg
- the event message to publishprotected void publishOnEventBus(EventMessage<?> msg)
AnnotatedAggregate
publishOnEventBus
in class AnnotatedAggregate<T>
msg
- the event message to publishpublic Long version()
AggregateLifecycle
public void initializeState(DomainEventStream eventStream)
eventStream
.eventStream
- The Event Stream containing the events to be used to reconstruct this Aggregate's state.protected boolean getIsLive()
AggregateLifecycle
getIsLive
in class AnnotatedAggregate<T>
true
if the aggregate is 'live', false
if the aggregate is initializing state based on
historic eventspublic SnapshotTrigger getSnapshotTrigger()
Copyright © 2010–2018. All rights reserved.