Class AggregateLifecycle
java.lang.Object
org.axonframework.messaging.Scope
org.axonframework.modelling.command.AggregateLifecycle
- Direct Known Subclasses:
AnnotatedAggregate,StubAggregateLifecycle
Abstract base class of a component that models an aggregate's life cycle.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ApplyMoreApply aDomainEventMessagewith given payload without metadata (though interceptors can also be used to provide metadata).static ApplyMoreApply aDomainEventMessagewith given payload and metadata (metadata from interceptors will be combined with the provided metadata).static <T> Aggregate<T> Creates a new aggregate instance.Provide a description of thisScope.protected abstract <T> ApplyMoreApply aDomainEventMessagewith given payload and metadata (metadata from interceptors will be combined with the provided metadata).protected abstract <T> Aggregate<T> doCreateNew(Class<T> aggregateType, Callable<T> factoryMethod) Creates a new aggregate instance.protected abstract voidMarks this aggregate as deleted.protected voidExecutes the given task.protected static AggregateLifecycleGet the currentAggregateLifecycleinstance for the current thread.protected abstract booleanIndicates whether this Aggregate instance is 'live'.static LongGets the version of the aggregate.protected abstract ObjectRetrieve aObjectdenoting the identifier of this Aggregate.static booleanisLive()Indicates whether this Aggregate instance is 'live'.static voidMarks this aggregate as deleted, instructing a repository to remove that aggregate at an appropriate time.protected abstract Stringtype()Retrieve aStringdenoting the type of this Aggregate.protected abstract Longversion()Gets the version of the aggregate.Methods inherited from class org.axonframework.messaging.Scope
describeCurrentScope, endScope, executeWithResult, getCurrentScope, startScope
-
Constructor Details
-
AggregateLifecycle
public AggregateLifecycle()
-
-
Method Details
-
apply
Apply aDomainEventMessagewith given payload and metadata (metadata from interceptors will be combined with the provided metadata). Applying events means they are immediately applied (published) to the aggregate and scheduled for publication to other event handlers. The event is 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 use the returnedApplyMoreinstance.- 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:
-
apply
Apply aDomainEventMessagewith given payload without metadata (though interceptors can also be used to provide metadata). Applying events means they are immediately applied (published) to the aggregate and scheduled for publication to other event handlers. The event is 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 use the returnedApplyMoreinstance.- Parameters:
payload- the payload of the event to apply- Returns:
- a gizmo to apply additional events after the given event has been processed by the entire aggregate
- See Also:
-
createNew
public static <T> Aggregate<T> createNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception Creates a new aggregate instance. In order for new aggregate to be created, aRepositoryshould be available to the current aggregate.Repositoryof an aggregate to be created is exposed to the current aggregate viaRepositoryProvider.- Type Parameters:
T- type of new aggregate to be created- Parameters:
aggregateType- type of new aggregate to be createdfactoryMethod- factory method which creates new aggregate- Returns:
- a new aggregate instance
- Throws:
Exception- thrown if something goes wrong during instantiation of new aggregate
-
isLive
public static boolean isLive()Indicates whether this Aggregate instance is 'live'. Events applied to a 'live' Aggregate represent events that are currently happening, as opposed to events representing historic decisions used to reconstruct the Aggregate's state.- Returns:
trueif the aggregate is 'live',falseif the aggregate is initializing state based on historic events
-
getVersion
Gets the version of the aggregate.- Returns:
- the current version of the aggregate
-
markDeleted
public static void markDeleted()Marks this aggregate as deleted, instructing a repository to remove that aggregate at an appropriate time. Note that different repository implementations may react differently to aggregates marked for deletion. Typically, Event Sourced Repositories will ignore the marking and expect deletion to be provided as part of Event information. -
getInstance
Get the currentAggregateLifecycleinstance for the current thread. If none exists anIllegalStateExceptionis thrown.- Returns:
- the thread's current
AggregateLifecycle
-
getIsLive
protected abstract boolean getIsLive()Indicates whether this Aggregate instance is 'live'. This means events currently applied represent events that are currently happening, as opposed to events representing historic decisions.- Returns:
trueif the aggregate is 'live',falseif the aggregate is initializing state based on historic events
-
version
Gets the version of the aggregate.- Returns:
- the current version of the aggregate
-
doMarkDeleted
protected abstract void doMarkDeleted()Marks this aggregate as deleted. Implementations may react differently to aggregates marked for deletion. Typically, Event Sourced Repositories will ignore the marking and expect deletion to be provided as part of Event information. -
doApply
Apply 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.- 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:
-
doCreateNew
protected abstract <T> Aggregate<T> doCreateNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception Creates a new aggregate instance. In order for new aggregate to be created, aRepositoryshould be available to the current aggregate.Repositoryof an aggregate to be created is exposed to the current aggregate viaRepositoryProvider.- Type Parameters:
T- type of new aggregate to be created- Parameters:
aggregateType- type of new aggregate to be createdfactoryMethod- factory method which creates new aggregate- Returns:
- a new aggregate instance
- Throws:
Exception- thrown if something goes wrong during instantiation of new aggregate
-
execute
Executes the given task. While the task is being executed the current aggregate will be registered with the current thread as the 'current' aggregate.- Parameters:
task- the task to execute on the aggregate
-
describeScope
Description copied from class:ScopeProvide a description of thisScope.- Specified by:
describeScopein classScope- Returns:
- a
ScopeDescriptordescribing thisScope
-
type
Retrieve aStringdenoting the type of this Aggregate.- Returns:
- a
Stringdenoting the type of this Aggregate
-
identifier
Retrieve aObjectdenoting the identifier of this Aggregate.- Returns:
- a
Objectdenoting the identifier of this Aggregate
-