Package org.axonframework.eventsourcing
Class EventSourcedAggregate<T>
java.lang.Object
org.axonframework.messaging.Scope
org.axonframework.modelling.command.AggregateLifecycle
org.axonframework.modelling.command.inspection.AnnotatedAggregate<T>
org.axonframework.eventsourcing.EventSourcedAggregate<T>
- Type Parameters:
T- The type of the aggregate root object
Implementation of an
Aggregate that is sourced from events that have
been published by the aggregate.-
Field Summary
Fields inherited from class org.axonframework.modelling.command.inspection.AnnotatedAggregate
inspector -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEventSourcedAggregate(AggregateModel<T> model, EventBus eventBus, SnapshotTrigger snapshotTrigger) Creates a new EventSourcedAggregate instance based on the givenmodel, which publishes events to the giveneventBus.protectedEventSourcedAggregate(AggregateModel<T> model, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) Creates a new EventSourcedAggregate instance based on the givenmodel, which publishes events to the giveneventBus.protectedEventSourcedAggregate(T aggregateRoot, AggregateModel<T> model, EventBus eventBus, SnapshotTrigger snapshotTrigger) Initializes an Aggregate instance for the givenaggregateRoot, based on the givenmodel, which publishes events to the giveneventBus.protectedEventSourcedAggregate(T aggregateRoot, AggregateModel<T> model, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) Initializes an Aggregate instance for the givenaggregateRoot, based on the givenmodel, which publishes events to the giveneventBus. -
Method Summary
Modifier and TypeMethodDescription<P> ApplyMoreApply aDomainEventMessagewith given payload and metadata (metadata from interceptors will be combined with the provided metadata).protected booleanIndicates whether this Aggregate instance is 'live'.The trigger instance that monitors this aggregate to trigger a snapshotstatic <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) Initializes an EventSourcedAggregate instance using the givenaggregateFactory, based on the giveninspector, which publishes events to the giveneventBusand stores events in the giveneventStore.static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) Initializes an EventSourcedAggregate instance using the givenaggregateFactory, based on the giveninspector, which publishes events to the giveneventBusand stores events in the giveneventStore.static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) Initializes an EventSourcedAggregate instance for the givenaggregateRoot, based on the giveninspector, which publishes events to the giveneventBus.static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) Initializes an EventSourcedAggregate instance for the givenaggregateRoot, based on the giveninspector, which publishes events to the giveneventBus.voidinitializeState(DomainEventStream eventStream) Initialize the state of this Event Sourced Aggregate with the events from the giveneventStream.protected voidpublish(EventMessage<?> msg) Publish an event to the aggregate root and its entities first and external event handlers (using the given event bus) later.protected voidpublishOnEventBus(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, SnapshotTrigger snapshotTrigger) Reconstructs an EventSourcedAggregate instance with givenaggregateRoot.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 givenaggregateRoot.version()Gets the version of the aggregate.Methods inherited from class org.axonframework.modelling.command.inspection.AnnotatedAggregate
andThen, andThenApply, applyMessageOrPayload, createMessage, doCreateNew, doMarkDeleted, execute, getAggregateRoot, handle, identifier, initialize, initialize, initialize, initialize, initialize, initialize, initSequence, initSequence, invoke, isDeleted, lastSequence, registerRoot, rootType, typeMethods inherited from class org.axonframework.modelling.command.AggregateLifecycle
apply, apply, createNew, describeScope, execute, getInstance, getVersion, isLive, markDeletedMethods inherited from class org.axonframework.messaging.Scope
describeCurrentScope, endScope, executeWithResult, getCurrentScope, startScopeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.modelling.command.Aggregate
identifierAsStringMethods inherited from interface org.axonframework.modelling.command.ApplyMore
andThenApplyIf, andThenIf
-
Constructor Details
-
EventSourcedAggregate
protected EventSourcedAggregate(T aggregateRoot, AggregateModel<T> model, EventBus eventBus, SnapshotTrigger snapshotTrigger) Initializes an Aggregate instance for the givenaggregateRoot, based on the givenmodel, which publishes events to the giveneventBus.- Parameters:
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 initialization
-
EventSourcedAggregate
protected EventSourcedAggregate(T aggregateRoot, AggregateModel<T> model, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) Initializes an Aggregate instance for the givenaggregateRoot, based on the givenmodel, which publishes events to the giveneventBus.- Parameters:
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 initialization
-
EventSourcedAggregate
protected EventSourcedAggregate(AggregateModel<T> model, EventBus eventBus, SnapshotTrigger snapshotTrigger) Creates a new EventSourcedAggregate instance based on the givenmodel, which publishes events to the giveneventBus. This aggregate is not assigned a root instance yet.- Parameters:
model- The model describing the aggregate structureeventBus- The event store to store generated events insnapshotTrigger- The trigger to notify of events and initialization- See Also:
-
EventSourcedAggregate
protected EventSourcedAggregate(AggregateModel<T> model, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) Creates a new EventSourcedAggregate instance based on the givenmodel, which publishes events to the giveneventBus. This aggregate is not assigned a root instance yet.- Parameters:
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 initialization- See Also:
-
-
Method Details
-
initialize
public static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) Initializes an EventSourcedAggregate instance for the givenaggregateRoot, based on the giveninspector, which publishes events to the giveneventBus.- Type Parameters:
T- the aggregate root type- Parameters:
aggregateRoot- 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 initialization- Returns:
- the initialized EventSourcedAggregate instance
-
initialize
public static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) Initializes an EventSourcedAggregate instance for the givenaggregateRoot, based on the giveninspector, which publishes events to the giveneventBus.- Type Parameters:
T- the aggregate root type- Parameters:
aggregateRoot- 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 initialization- Returns:
- the initialized EventSourcedAggregate instance
-
initialize
public static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) throws Exception Initializes an EventSourcedAggregate instance using the givenaggregateFactory, based on the giveninspector, which publishes events to the giveneventBusand stores events in the giveneventStore.- Type Parameters:
T- the aggregate root type- Parameters:
aggregateFactory- 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 initialization- Returns:
- the initialized EventSourcedAggregate instance
- Throws:
Exception- if the aggregate cannot be initialized
-
initialize
public static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) throws Exception Initializes an EventSourcedAggregate instance using the givenaggregateFactory, based on the giveninspector, which publishes events to the giveneventBusand stores events in the giveneventStore.- Type Parameters:
T- the aggregate root type- Parameters:
aggregateFactory- 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 initialization- Returns:
- the initialized EventSourcedAggregate instance
- Throws:
Exception- if the aggregate cannot be initialized
-
reconstruct
public static <T> EventSourcedAggregate<T> reconstruct(T aggregateRoot, AggregateModel<T> model, long seqNo, boolean isDeleted, EventBus eventBus, SnapshotTrigger snapshotTrigger) Reconstructs an EventSourcedAggregate instance with givenaggregateRoot. The aggregate's sequence number should be set to the givenseqNoand its deleted flag to the givenisDeleted.Use this method to initialize an EventSourcedAggregate without having to replay the aggregate from events.
- Type Parameters:
T- the aggregate root type- Parameters:
aggregateRoot- 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 initialization- Returns:
- the reconstructed EventSourcedAggregate instance
-
reconstruct
public 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 givenaggregateRoot. The aggregate's sequence number should be set to the givenseqNoand its deleted flag to the givenisDeleted.Use this method to initialize an EventSourcedAggregate without having to replay the aggregate from events.
- Type Parameters:
T- the aggregate root type- Parameters:
aggregateRoot- 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 initialization- Returns:
- the reconstructed EventSourcedAggregate instance
-
doApply
Description copied from class:AggregateLifecycleApply aDomainEventMessagewith 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 returnedApplyMoreinstance should allow for additional events to be applied after this event.- Overrides:
doApplyin classAnnotatedAggregate<T>- Parameters:
payload- the payload of the event to applymetaData- any meta-data that must be registered with the Event- Returns:
- a gizmo to apply additional events after the given event has been processed by the entire aggregate
- See Also:
-
publish
Description copied from class:AnnotatedAggregatePublish an event to the aggregate root and its entities first and external event handlers (using the given event bus) later.- Overrides:
publishin classAnnotatedAggregate<T>- Parameters:
msg- the event message to publish
-
publishOnEventBus
Description copied from class:AnnotatedAggregatePublish an event to external event handlers using the given event bus.- Overrides:
publishOnEventBusin classAnnotatedAggregate<T>- Parameters:
msg- the event message to publish
-
version
Description copied from class:AggregateLifecycleGets the version of the aggregate. -
initializeState
Initialize the state of this Event Sourced Aggregate with the events from the giveneventStream.- Parameters:
eventStream- The Event Stream containing the events to be used to reconstruct this Aggregate's state.
-
getIsLive
protected boolean getIsLive()Description copied from class:AggregateLifecycleIndicates whether this Aggregate instance is 'live'. This means events currently applied represent events that are currently happening, as opposed to events representing historic decisions.- Overrides:
getIsLivein classAnnotatedAggregate<T>- Returns:
trueif the aggregate is 'live',falseif the aggregate is initializing state based on historic events
-
getSnapshotTrigger
The trigger instance that monitors this aggregate to trigger a snapshot- Returns:
- the trigger instance assigned to this aggregate instance
-