public class StubAggregateLifecycle extends AggregateLifecycle
activate()
) and deactivated (see close()
) at will. Events
applied while it is active are stored and can be retrieved using getAppliedEvents()
or
getAppliedEventPayloads()
.
When using with JUnit, consider using the StubAggregateLifecycleRule
with @Rule
instead, as it is easier and safer to use.
Constructor and Description |
---|
StubAggregateLifecycle() |
Modifier and Type | Method and Description |
---|---|
void |
activate()
Activates this lifecycle instance.
|
void |
close()
Closes this lifecycle instance, restoring to the situation prior to this lifecycle being started.
|
protected <T> ApplyMore |
doApply(T payload,
MetaData metaData)
Apply a
DomainEventMessage with given payload and metadata (metadata from
interceptors will be combined with the provided metadata). |
protected <T> Aggregate<T> |
doCreateNew(Class<T> aggregateType,
Callable<T> factoryMethod)
Creates a new aggregate instance.
|
protected void |
doMarkDeleted()
Marks this aggregate as deleted.
|
List<Object> |
getAppliedEventPayloads()
Returns the payloads of the Events applied while this lifecycle instance was active.
|
List<EventMessage<?>> |
getAppliedEvents()
Returns the list of applied Events for this lifecycle instance.
|
protected boolean |
getIsLive()
Indicates whether this Aggregate instance is 'live'.
|
protected Object |
identifier()
Retrieve a
Object denoting the identifier of this Aggregate. |
boolean |
isMarkedDeleted()
Indicates whether an Aggregate has invoked "markDeleted" while this lifecycle was active.
|
protected String |
type()
Retrieve a
String denoting the type of this Aggregate. |
protected Long |
version()
Gets the version of the aggregate.
|
apply, apply, createNew, describeScope, execute, getInstance, getVersion, isLive, markDeleted
describeCurrentScope, endScope, executeWithResult, getCurrentScope, startScope
public void activate()
close()
is called.public void close()
protected boolean getIsLive()
AggregateLifecycle
getIsLive
in class AggregateLifecycle
true
if the aggregate is 'live', false
if the aggregate is initializing state based on
historic eventsprotected <T> Aggregate<T> doCreateNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception
AggregateLifecycle
Repository
should be
available to the current aggregate. Repository
of an aggregate to be created is exposed to the current
aggregate via RepositoryProvider
.doCreateNew
in class AggregateLifecycle
T
- type of new aggregate to be createdaggregateType
- type of new aggregate to be createdfactoryMethod
- factory method which creates new aggregateException
- thrown if something goes wrong during instantiation of new aggregateprotected String type()
AggregateLifecycle
String
denoting the type of this Aggregate.type
in class AggregateLifecycle
String
denoting the type of this Aggregateprotected Object identifier()
AggregateLifecycle
Object
denoting the identifier of this Aggregate.identifier
in class AggregateLifecycle
Object
denoting the identifier of this Aggregateprotected Long version()
AggregateLifecycle
version
in class AggregateLifecycle
protected void doMarkDeleted()
AggregateLifecycle
doMarkDeleted
in class AggregateLifecycle
protected <T> ApplyMore doApply(T 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 AggregateLifecycle
payload
- the payload of the event to applymetaData
- any meta-data that must be registered with the EventApplyMore
public List<EventMessage<?>> getAppliedEvents()
Note that this list is not reset when activating or deactivating the lifecycle.
public List<Object> getAppliedEventPayloads()
AggregateLifecycle.apply(Object)
method.public boolean isMarkedDeleted()
true
if AggregateLifecycle.markDeleted()
was invoked, otherwise false
Copyright © 2010–2024. All rights reserved.