KernelStateReads

class KernelStateReads(registry: ModelRegistry, contexts: Map<String, KernelStateReads.ContextReads>, gate: ReplayGate = ReplayGate.OPEN, maxReplay: Int = DEFAULT_MAX_REPLAY, minVersionWait: Duration = DEFAULT_MIN_VERSION_WAIT) : StateReads

StateReads of the contexts a node serves: the latest state is the snapshot (SnapshotStore, the default read model), else, while an aggregate has none, its log replayed by the context's Kernel from version 1 (Kernel.stateAt, as the write side loads a state without a snapshot) under gate; a state at a version or a time, and a trace, are the log replayed (Kernel.stateAt, Kernel.trace) from the snapshot when it comes before what is asked, else from version 1, under gate too. Every replay but committed's folds the log as it reads it and at most maxReplay streams of it: a read that needs more is refused with StateReplayLimitException.

A snapshot's declared access attributes, which a read is admitted on, are what its state derives now under the model, as a replayed state's are, when the kernel reads it back as it would to source a command; any other keeps those it stored.

A snapshot behind the log's head is the latest state as it is: the snapshot is the read model, which the default wait (SNAPSHOT) has caught up before a command's answer. A read that asks for a minimum version (latest of a version) catches a lagging snapshot up with the log instead, under gate and maxReplay too, and waits at most minVersionWait for a version not committed yet; caughtUp catches it up once, and does not wait. An aggregate whose model registry does not know, or whose context has no ContextReads, is not found, and so is one with no commit. States are trees of Wow's JSON, so a decimal keeps its digits and its scale.

Constructors

Link copied to clipboard
constructor(registry: ModelRegistry, contexts: Map<String, KernelStateReads.ContextReads>, gate: ReplayGate = ReplayGate.OPEN, maxReplay: Int = DEFAULT_MAX_REPLAY, minVersionWait: Duration = DEFAULT_MIN_VERSION_WAIT)

Types

Link copied to clipboard
Link copied to clipboard
class ContextReads(val kernel: Kernel, val snapshots: SnapshotStore)

What KernelStateReads reads a context from: its kernel and its snapshot store.

Functions

Link copied to clipboard
open suspend override fun at(ref: AggregateRef, instant: Instant): Snapshot<JsonNode>?

The committed state of ref as of instant: after the last commit at or before it by commit time; null when none had committed by then. Replayed as at a version is.

open suspend override fun at(ref: AggregateRef, version: Int): Snapshot<JsonNode>?

The committed state of ref at version, or null when the log does not hold that version. Its replay runs under the node's ReplayGate and folds a bounded number of streams: past the bound, it throws StateReplayLimitException.

Link copied to clipboard
open suspend override fun caughtUp(ref: AggregateRef): Snapshot<JsonNode>?

The latest state of ref caught up with its log once, without waiting: the log replayed to its head under the node's ReplayGate, from its snapshot when the snapshot fits the model and from version 1 when it does not (of another state revision or schema, not decodable, or past the log), at most as many streams as at a version replays (past them it throws StateReplayLimitException). Null when ref has no snapshot to catch up from (its latest state is then its log already, latest), when its log holds none of its streams, or when no commit of it is known.

Link copied to clipboard
open suspend override fun latest(ref: AggregateRef): Snapshot<JsonNode>?

The latest state of ref: the one the read model holds, else, before its first snapshot is written (or with its snapshots off), the state its log holds; null when no commit of ref is known. A read that replays the log runs under the node's ReplayGate (its log store's query bulkhead).

open suspend override fun latest(ref: AggregateRef, minVersion: Int): Snapshot<JsonNode>?

The latest state of ref at version minVersion or later (read your writes): its snapshot when it has reached minVersion, else its log replayed to its head as caughtUp replays it, and from version 1 without a snapshot; and while the log too is below minVersion (the command has not committed yet), read again until a bounded wait runs out. It answers the state it read last: one below minVersion when the wait ran out, which the entry checks its caller on before it says so; null when no commit of ref is known.

Link copied to clipboard
open suspend override fun trace(ref: AggregateRef, fromVersion: Int, toVersion: Int, limit: Int): List<CommitView>

The commits of ref from version fromVersion up to toVersion, at most limit, in version order, each with its events and the state after it; empty when the log holds none of those versions. Replayed as at a version is, the state before fromVersion included.