Class StoreBackedSnapshotter<I,E>

java.lang.Object
org.axonframework.eventsourcing.snapshot.store.StoreBackedSnapshotter<I,E>
Type Parameters:
I - the type of the entity identifier
E - the type of the entity being snapshot
All Implemented Interfaces:
Snapshotter<I,E>

@Internal public class StoreBackedSnapshotter<I,E> extends Object implements 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 SnapshotStore when an entity is loaded.
  • Stores new snapshots asynchronously when either the user requested a snapshot or the SnapshotPolicy indicates 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 Details

    • StoreBackedSnapshotter

      public StoreBackedSnapshotter(SnapshotStore store, MessageType type, Converter converter, Class<E> entityType)
      Creates a new instance.
      Parameters:
      store - a SnapshotStore used to store snapshots, cannot be null
      type - a versioned type to distinguish the snapshot in the store, cannot be null
      converter - a Converter used to deserialize snapshots, cannot be null
      entityType - the entity type, cannot be null
      Throws:
      NullPointerException - when any argument is null
  • Method Details

    • load

      public CompletableFuture<Snapshot> load(I identifier)
      Description copied from interface: Snapshotter
      Asynchronously retrieves the snapshot for the given identifier, if one exists.

      The returned CompletableFuture completes with the snapshot, or null if none exists or the snapshot cannot be used. It may complete exceptionally if snapshot retrieval fails.

      Specified by:
      load in interface Snapshotter<I,E>
      Parameters:
      identifier - the identifier of the entity, cannot be null
      Returns:
      a CompletableFuture that completes with the entity's snapshot or null
    • store

      public void store(I identifier, E entity, Position position)
      Description copied from interface: Snapshotter
      Stores the given entity as a snapshot asynchronously.
      Specified by:
      store in interface Snapshotter<I,E>
      Parameters:
      identifier - the identifier of the entity, cannot be null
      entity - the entity state, cannot be null
      position - the position in the event stream for this entity state, cannot be null