Class DefaultSnapshotStore

java.lang.Object
io.fluxcapacitor.javaclient.persisting.eventsourcing.DefaultSnapshotStore
All Implemented Interfaces:
SnapshotStore

public class DefaultSnapshotStore extends Object implements SnapshotStore
Default implementation of the SnapshotStore interface, responsible for managing snapshots of aggregate roots in an event-sourced system.

This implementation uses a key-value store (KeyValueClient) to store snapshots, a Serializer to handle serialization and deserialization of snapshots, and an EventStore for managing the associated event data.

If deserialization fails, a warning is logged, the snapshot is deleted, and the aggregate is reconstructed from its event history.

  • Constructor Details

    • DefaultSnapshotStore

      public DefaultSnapshotStore()
  • Method Details

    • storeSnapshot

      public <T> CompletableFuture<Void> storeSnapshot(Entity<T> snapshot)
      Description copied from interface: SnapshotStore
      Stores a new snapshot for the given aggregate entity.

      The snapshot typically contains the latest known state and metadata such as the aggregate ID and sequence number. Storing a snapshot will overwrite any existing snapshot for the same aggregate ID.

      Specified by:
      storeSnapshot in interface SnapshotStore
      Type Parameters:
      T - The aggregate root type.
      Parameters:
      snapshot - The aggregate entity to be stored as a snapshot.
      Returns:
      A CompletableFuture indicating whether the operation completed successfully.
    • getSnapshot

      public <T> Optional<Entity<T>> getSnapshot(Object aggregateId)
      Description copied from interface: SnapshotStore
      Retrieves the most recent snapshot for a given aggregate ID, if available.
      Specified by:
      getSnapshot in interface SnapshotStore
      Type Parameters:
      T - The expected type of the aggregate.
      Parameters:
      aggregateId - The ID of the aggregate for which to retrieve a snapshot.
      Returns:
      An Optional containing the aggregate snapshot if present, otherwise empty.
    • deleteSnapshot

      public CompletableFuture<Void> deleteSnapshot(Object aggregateId)
      Description copied from interface: SnapshotStore
      Deletes the snapshot for the specified aggregate ID.
      Specified by:
      deleteSnapshot in interface SnapshotStore
      Parameters:
      aggregateId - The ID of the aggregate whose snapshot should be deleted.
      Returns:
      A CompletableFuture indicating completion of the deletion operation.
    • snapshotKey

      protected String snapshotKey(Object aggregateId)