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) 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) 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
-
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
-
source
Description copied from interface:EventStorageEngineCreates a finiteMessageStreamofeventsmatching the givencondition.The final entry of the stream always contains a
ConsistencyMarkerin theMessageStream.Entry's resources, paired with aTerminalEventMessage. ThisConsistencyMarkershould be used to construct theAppendConditionwhenappending events.The
conditiondictates the sequence to load based on theEventsCondition.criteria(). Additionally, an optionalSourcingCondition.strategy()may be provided.The returned stream is finite, i.e. it should not block to wait for further events if the end of the event stream of the aggregate is reached.
- Specified by:
sourcein interfaceEventStorageEngine- Parameters:
condition- TheSourcingConditiondictating thestreamofeventsto source.- 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.
-