stateAt

suspend fun <S : Any> stateAt(model: AggregateModel<S>, ref: AggregateRef, version: Int, snapshot: SnapshotRecord? = null, maxReplay: Int = options.maxReplay): CachedState?

The committed state of ref at version, read-only (the state a subscription hands over when the commit's shared state is gone, on a replay or after an ownership change): snapshot evolved with the log's streams after it up to version when it fits, as on a cache miss, else the log replayed up to version. A snapshot past version, of another aggregate or not fitting is passed over. The state cache is not touched.

The log is folded as it is read, never held whole, and at most maxReplay streams are folded: a read that needs more, counted from the snapshot when it fits, else from version 1, is refused before it reads the log.

Return

the state at version with the metadata the kernel keeps beside it (scope, deleted mark, schedules); null when the log does not hold version.

Throws

when the state at version is more than maxReplay streams away.


suspend fun <S : Any> stateAt(model: AggregateModel<S>, ref: AggregateRef, version: Int, base: CachedState): CachedState?

The committed state of ref at version, evolved from base, its state at an earlier version that the caller hands over to be evolved (it may be mutated: a copy, never a live instance), with the log's streams after it up to version (a subscription behind the snapshot evolves the state it read for the previous commit, instead of replaying the log from version 1). The state cache is not touched.

Return

the state at version with the metadata the kernel keeps beside it; null when the log does not hold every version after base's up to version.


suspend fun <S : Any> stateAt(model: AggregateModel<S>, ref: AggregateRef, at: Instant, snapshot: SnapshotRecord? = null, maxReplay: Int = options.maxReplay): CachedState?

The committed state of ref as of at, read-only: the state after the last stream committed at or before at by its commit time. Commit times are epoch milliseconds, so at counts to its millisecond. The log is read in version order and the first stream committed after at ends it: commit times are taken to rise with the versions, which only a clock stepping back between two owners of the aggregate breaks, and only by that step.

snapshot serves as for a version (see the other stateAt) when its last stream committed at or before at: it is evolved with the tail up to at, so the log is not replayed from version 1. A snapshot committed after at, of another aggregate or not fitting is passed over. Every event is read as the model's current schema, upgraded from the revision it was written in. The state cache is not touched.

The log is folded as it is read, never held whole, and at most maxReplay streams are folded: the read is refused as soon as it would fold one more.

Return

the state with the metadata the kernel keeps beside it (scope, deleted mark, schedules); null when no stream of ref had committed by at.

Throws

when the state as of at is more than maxReplay streams away.