Class SnapshotCapableEventStorageEngine
- All Implemented Interfaces:
DescribableComponent,EventStorageEngine
EventStorageEngine that adds support for the SourcingStrategy.Snapshot sourcing
strategy for stores that do not support this strategy natively.
When the given SourcingCondition carries a SourcingStrategy.Snapshot strategy, this decorator
loads the latest snapshot from the given SnapshotStore and prepends it as a synthetic leading message to
the event stream, followed by the events that occurred after the snapshot's position. If no snapshot is found, or
if loading fails, it falls back to full event sourcing from the beginning.
All other sourcing strategies, as well as all append and streaming operations, are delegated directly to the wrapped engine.
- Since:
- 5.1.0
- Author:
- John Hendrikx
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.axonframework.eventsourcing.eventstore.EventStorageEngine
EventStorageEngine.AppendTransaction<R> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe decoration order used when registering this wrapper as a decorator forEventStorageEnginecomponents. -
Constructor Summary
ConstructorsConstructorDescriptionSnapshotCapableEventStorageEngine(EventStorageEngine delegate, SnapshotStore snapshotStore) Constructs aSnapshotCapableEventStorageEnginewrapping the givendelegateengine with snapshot loading capability backed by the givensnapshotStore. -
Method Summary
Modifier and TypeMethodDescriptionappendEvents(AppendCondition condition, @Nullable ProcessingContext context, List<TaggedEventMessage<?>> events) static EventStorageEnginedecorate(EventStorageEngine engine, SnapshotStore snapshotStore) Returns anEventStorageEnginethat supports theSourcingStrategy.Snapshotsourcing strategy, given theengineto source events from and thesnapshotStoreholding its snapshots.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.Creates aTrackingTokenthat is at the first position of an event stream.Creates aTrackingTokenthat is at the latest position of an event stream.source(SourcingCondition condition, @Nullable ProcessingContext context) Creates a finiteMessageStreamofeventsmatching the givencondition, carrying along the activeProcessingContext.stream(StreamingCondition condition) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.eventsourcing.eventstore.EventStorageEngine
appendEvents, source
-
Field Details
-
DECORATION_ORDER
public static final int DECORATION_ORDERThe decoration order used when registering this wrapper as a decorator forEventStorageEnginecomponents.- See Also:
-
-
Constructor Details
-
SnapshotCapableEventStorageEngine
Constructs aSnapshotCapableEventStorageEnginewrapping the givendelegateengine with snapshot loading capability backed by the givensnapshotStore.- Parameters:
delegate- theEventStorageEngineto delegate non-snapshot operations to, cannot benullsnapshotStore- theSnapshotStoreused to load snapshots, cannot benull
-
-
Method Details
-
decorate
Returns anEventStorageEnginethat supports theSourcingStrategy.Snapshotsourcing strategy, given theengineto source events from and thesnapshotStoreholding its snapshots.The given
engineis returned as is when it is the givensnapshotStoreitself. Such an engine resolves the snapshot within its ownsourcecall, serving the snapshot and the events following it in a single round trip. Decorating it would resolve the snapshot separately and pass anabsolute strategyinward, disabling that optimization.An
enginethat is already decorated is returned as is too, so composing twice is harmless. It keeps resolving snapshots from the store it was decorated with, and the givensnapshotStoreis ignored for it. Decorating again would put the given store in front of that one instead of adding anything.Any other
engineis decorated, resolving the snapshot from thesnapshotStorebefore sourcing the events that follow it.- Parameters:
engine- the engine to source events fromsnapshotStore- the store holding the snapshots of the givenengine- Returns:
- an event storage engine supporting the snapshot sourcing strategy
- Throws:
NullPointerException- if the givenengineorsnapshotStoreisnull- Since:
- 5.3.0
-
source
public MessageStream<EventMessage> source(SourcingCondition condition, @Nullable ProcessingContext context) Description copied from interface:EventStorageEngineCreates a finiteMessageStreamofeventsmatching the givencondition, carrying along the activeProcessingContext.Behaves identically to
EventStorageEngine.source(SourcingCondition); thecontextis passed to decorators (for example snapshot-loading and tracing decorators) that need to correlate the sourcing operation with the surrounding unit of work.- Specified by:
sourcein interfaceEventStorageEngine- Parameters:
condition- theSourcingConditiondictating thestreamofeventsto sourcecontext- theProcessingContextactive while sourcing; may benull- Returns:
- a finite
MessageStreamofeventsmatching the givencondition
-
appendEvents
public CompletableFuture<EventStorageEngine.AppendTransaction<?>> appendEvents(AppendCondition condition, @Nullable ProcessingContext context, List<TaggedEventMessage<?>> events) Description copied from interface:EventStorageEngineAppends aListofeventsto the underlying storage solution.Events will be appended in the order that they are offered in, validating the given
conditionbefore being stored. Note that all events should have a unique event identifier.Tagspaired with theeventswill be stored as well.Implementations may be able to detect conflicts during the append stage. In such case, the returned completable future will complete exceptionally, indicating such conflict. Other implementations may delay such checks until the
EventStorageEngine.AppendTransaction.commit()is called.Called during the
PREPARE_COMMITphase.- Specified by:
appendEventsin interfaceEventStorageEngine- Parameters:
condition- The condition describing the transactional requirements for the append transactioncontext- The currentProcessingContext, if any.events- TheListofeventsto append to the underlying storage solution.- Returns:
- A
transactioninstance that can be committed or rolled back.
-
stream
Description copied from interface:EventStorageEngineCreates an infiniteMessageStreamofeventsmatching the givencondition.The
conditionmay dictate theStreamingCondition.position()to start streaming from, as well as definefilter criteriafor the returnedMessageStream.- Specified by:
streamin interfaceEventStorageEngine- Parameters:
condition- TheStreamingConditiondictating theStreamingCondition.position()to start streaming from, as well as thefilter criteriaused for the returnedMessageStream.- Returns:
- An infinite
MessageStreamofeventsmatching the givencondition.
-
firstToken
Description copied from interface:EventStorageEngineCreates aTrackingTokenthat is at the first position of an event stream.In other words, a token that tracks events from the beginning of time.
- Specified by:
firstTokenin interfaceEventStorageEngine- Returns:
- A
CompletableFutureof aTrackingTokenat the first position of an event stream.
-
latestToken
Description copied from interface:EventStorageEngineCreates aTrackingTokenthat is at the latest position of an event stream.In other words, a token that tracks all new events from this point forward.
- Specified by:
latestTokenin interfaceEventStorageEngine- Returns:
- A
CompletableFutureof aTrackingTokenat the latest position of an event stream.
-
tokenAt
Description copied from interface:EventStorageEngineCreates aTrackingTokenthat tracks alleventsafter the givenat.If there is an event exactly at the given
at, it will be tracked too.- Specified by:
tokenAtin interfaceEventStorageEngine- Parameters:
at- TheInstantdetermining how theTrackingTokenshould be created. A tracking token should point to very first event before thisInstant.- Returns:
- A
CompletableFutureof aTrackingTokenat the givenat, if there aren't events matching this criterianullis returned
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-