I
- The type of the identifier of this aggregate@MappedSuperclass public abstract class AbstractEventSourcedAggregateRoot<I> extends AbstractAggregateRoot<I> implements EventSourcedAggregateRoot<I>
DomainEventStream
, which can be used for event sourcing.Constructor and Description |
---|
AbstractEventSourcedAggregateRoot() |
Modifier and Type | Method and Description |
---|---|
protected void |
apply(Object eventPayload)
Apply the provided event.
|
protected void |
apply(Object eventPayload,
MetaData metaData)
Apply the provided event.
|
void |
commitEvents()
Clears the events currently marked as "uncommitted" and clears any known EventRegistrationCallbacks (see
AggregateRoot.addEventRegistrationCallback(EventRegistrationCallback) ). |
protected abstract Iterable<? extends EventSourcedEntity> |
getChildEntities()
Returns a collection of event sourced entities directly referenced by this entity.
|
Long |
getVersion()
Returns the current version number of the aggregate, or
null if the aggregate is newly created. |
protected abstract void |
handle(DomainEventMessage event)
Apply state changes based on the given event.
|
void |
initializeState(DomainEventStream domainEventStream)
Initialize the state of this aggregate using the events in the provided
DomainEventStream . |
protected boolean |
isLive()
Indicates whether this aggregate is in "live" mode.
|
addEventRegistrationCallback, getLastCommittedEventSequenceNumber, getUncommittedEventCount, getUncommittedEvents, initializeEventStream, isDeleted, markDeleted, registerEvent, registerEvent
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addEventRegistrationCallback, getIdentifier, getUncommittedEventCount, getUncommittedEvents, isDeleted
public void initializeState(DomainEventStream domainEventStream)
DomainEventStream
. A call to this method on an aggregate that has already been
initialized will result in an IllegalStateException
.
This implementation is aware of a special type of DomainEvents
: the AggregateSnapshot
,
which is a snapshot event, containing the actual aggregate inside.
AggregateSnapshot
events are used to initialize the aggregate with the correct version (getVersion()
).initializeState
in interface EventSourcedAggregateRoot<I>
domainEventStream
- the event stream containing the events that describe the state changes of this
aggregateIllegalStateException
- if this aggregate was already initialized.protected void apply(Object eventPayload)
handle(org.axonframework.domain.DomainEventMessage)
event handler method} for processing.
The event is applied on all entities part of this aggregate.eventPayload
- The payload of the event to applyprotected void apply(Object eventPayload, MetaData metaData)
handle(org.axonframework.domain.DomainEventMessage)
event handler method} for processing.
The event is applied on all entities part of this aggregate.eventPayload
- The payload of the event to applymetaData
- any meta-data that must be registered with the Eventpublic void commitEvents()
AbstractAggregateRoot
AggregateRoot.addEventRegistrationCallback(EventRegistrationCallback)
).commitEvents
in interface AggregateRoot<I>
commitEvents
in class AbstractAggregateRoot<I>
EventContainer.commit()
protected boolean isLive()
isLive()
returns
false
. If an event is being handled because is was applied as a result of the current command being
executed, it returns true
.
isLive()
can be used to prevent expensive calculations while event sourcing.true
if the aggregate is live, false
when the aggregate is relaying historic
events.protected abstract Iterable<? extends EventSourcedEntity> getChildEntities()
protected abstract void handle(DomainEventMessage event)
event
- The event to handlepublic Long getVersion()
AbstractAggregateRoot
null
if the aggregate is newly created.
This
version must reflect the version number of the aggregate on which changes are applied.
Each time the aggregate is modified and stored in a repository, the version number must be increased by
at least 1. This version number can be used by optimistic locking strategies and detection of conflicting
concurrent modification.
Typically the sequence number of the last committed event on this aggregate is used as version number.getVersion
in interface AggregateRoot<I>
getVersion
in class AbstractAggregateRoot<I>
null
if no events were ever committedCopyright © 2010-2014. All Rights Reserved.