Class StoreBackedSnapshotter<I,E>
java.lang.Object
org.axonframework.eventsourcing.snapshot.store.StoreBackedSnapshotter<I,E>
- Type Parameters:
I- the type of the entity identifierE- the type of the entity being snapshot
- All Implemented Interfaces:
Snapshotter<I,E>
A
Snapshotter implementation that persists snapshots to a SnapshotStore.
This snapshotter tracks snapshots of event-sourced entities and decides when to persist them
based on signals received during entity evolution. It uses an EvolutionResult and a
SnapshotPolicy to determine whether a snapshot should be created after sourcing is complete.
Behavior:
- Loads the latest snapshot from the
SnapshotStorewhen an entity is loaded. - Stores new snapshots asynchronously when either the user requested a snapshot
or the
SnapshotPolicyindicates a snapshot is needed. - Logs any snapshotting failures without blocking or affecting entity evolution.
Thread-safety: This class is safe to use concurrently for multiple entities.
Usage notes:
- Snapshots are an optimization. If snapshot storage fails, the entity will still be fully evolved from its events.
- Since:
- 5.1.0
- Author:
- John Hendrikx
-
Constructor Summary
ConstructorsConstructorDescriptionStoreBackedSnapshotter(SnapshotStore store, MessageType type, Converter converter, Class<E> entityType) Creates a new instance. -
Method Summary
-
Constructor Details
-
StoreBackedSnapshotter
public StoreBackedSnapshotter(SnapshotStore store, MessageType type, Converter converter, Class<E> entityType) Creates a new instance.- Parameters:
store- aSnapshotStoreused to store snapshots, cannot benulltype- a versioned type to distinguish the snapshot in the store, cannot benullconverter- aConverterused to deserialize snapshots, cannot benullentityType- the entity type, cannot benull- Throws:
NullPointerException- when any argument isnull
-
-
Method Details
-
load
Description copied from interface:SnapshotterAsynchronously retrieves the snapshot for the givenidentifier, if one exists.The returned
CompletableFuturecompletes with the snapshot, ornullif none exists or the snapshot cannot be used. It may complete exceptionally if snapshot retrieval fails.- Specified by:
loadin interfaceSnapshotter<I,E> - Parameters:
identifier- the identifier of the entity, cannot benull- Returns:
- a
CompletableFuturethat completes with the entity's snapshot ornull
-
store
Description copied from interface:SnapshotterStores the given entity as a snapshot asynchronously.- Specified by:
storein interfaceSnapshotter<I,E> - Parameters:
identifier- the identifier of the entity, cannot benullentity- the entity state, cannot benullposition- the position in the event stream for this entity state, cannot benull
-