SnapshotMaintainer

class SnapshotMaintainer<STATE : AggregateState, EVENT, CHECKPOINT : Checkpoint>(aggregate: AggregateStateDefinition<STATE, EVENT>, eventStore: AggregateEventStoreRead<EVENT>, snapshotStore: SnapshotStore<STATE>, definition: SnapshotDefinition<STATE, *>, maxCachedAggregates: Int, clock: Clock = Clock.System) : EventSubscriber<EVENT, CHECKPOINT> (source)

Checkpointed asynchronous projection that derives snapshots from committed events.

Duplicate delivery is ignored by physical aggregate version. A gap is rebuilt from the latest compatible snapshot plus authoritative event history. A failed write fails the batch, keeping the runner checkpoint behind so the selected snapshot version is retried.

Constructors

Link copied to clipboard
constructor(aggregate: AggregateStateDefinition<STATE, EVENT>, eventStore: AggregateEventStoreRead<EVENT>, snapshotStore: SnapshotStore<STATE>, definition: SnapshotDefinition<STATE, *>, maxCachedAggregates: Int, clock: Clock = Clock.System)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open suspend fun onCaughtUp()

Transitions to caught-up after the source is live and queued batches have been handled and checkpointed. This is consumer readiness, not an upstream effective-time watermark.

Link copied to clipboard
open suspend override fun onEvents(events: SubscriptionBatch<EVENT, CHECKPOINT>)

Handles one ordered event batch. This must be replay-safe because duplicates are possible.

Link copied to clipboard
open suspend fun onFellBehind()

Leaves previously caught-up state before handling a new batch, or when the source is no longer live or the session ends. Repeated batches/status changes while behind do not repeat this callback.

Link copied to clipboard
open suspend fun onStarted(checkpoint: CHECKPOINT?, scope: CoroutineScope)

Starts an owned processing session before source delivery. checkpoint is its resume cut; initialization must complete before returning. Launch background work in scope, which is cancelled and joined before onStopped and ownership release. Each session starts uncaught-up.

Link copied to clipboard
open suspend fun onStopped()

Ends the session after delivery and owned work have stopped, before ownership release. Called once for each invocation of onStarted, even if it fails or is cancelled; cleanup runs in a non-cancellable context.