kumulant

SojournStat

class SojournStat(val states: List<Long>, val concurrency: Concurrency = Concurrency.None) : DiscreteStat<SojournResult> (source)

Tracks total time spent in each member of a declared categorical state alphabet, the number of transitions into each state, and the dwell time of the current state. Update values not in states raise IllegalArgumentException.

Use cases: uptime / availability breakdowns by state, dwell-time accounting, transition counters.

Memory: O(states); three arrays of length states.size plus a handful of cells.

Update: O(states) on transitions for the Long-to-index lookup (linear scan over the declared alphabet); O(1) when the state does not change.

Concurrency: Coupled current-state / enter-timestamp / per-state totals (category 3). The internal lock keeps the multi-cell update consistent.

Constructors

SojournStat

constructor(states: List<Long>, concurrency: Concurrency = Concurrency.None)(source)

Properties

concurrency

open override val concurrency: Concurrency(source)

Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.

states

Declared state alphabet; must be non-empty and contain no duplicates.

Functions

create

open override fun create(concurrency: Concurrency? = null): SojournStat(source)

Create an independent accumulator at the configured baseline. A null concurrency preserves this accumulator's mode; a non-null value overrides it. Modality subtypes narrow the return type to preserve the input shape.

merge

open override fun merge(values: SojournResult, timestampNanos: Long = currentTimeNanos())(source)

Fold a compatible snapshot values into this accumulator at timestampNanos. Implementations document whether the combine is exact or approximate and which state the snapshot omits. The source accumulator is unaffected.

Time-dependent statistics, such as windows, place the snapshot at timestampNanos, which must share the clock the caller uses for updates and reads. Time-independent statistics ignore it.

read

open override fun read(timestampNanos: Long = currentTimeNanos()): SojournResult(source)

Return the current result evaluated at timestampNanos. Time-independent statistics ignore the timestamp. Reading does not add an observation.

Snapshot consistency depends on the implementation's synchronisation. Locks protect coupled state under Concurrency.Strict and Concurrency.HighWrite; independently updated cells and JVM striped adders can still yield a best-effort snapshot. Concurrency.Relaxed permits drift across coupled cells.

reset

open override fun reset()(source)

Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.

validateMerge

open override fun validateMerge(values: SojournResult)(source)

Validate values for merge without changing accumulator state. Containers validate every child before merging any of them. Successful validation checks compatibility; it does not make a concurrent merge transactional.

Link copied to clipboard
open fun update(value: Long, weight: Double = 1.0)

Record value with weight at the current monotonic time.

open override fun update(value: Long, timestampNanos: Long, weight: Double = 1.0)

Record value with weight at timestampNanos.

update

open override fun update(value: Long, timestampNanos: Long, weight: Double = 1.0)(source)

Record value with weight at timestampNanos.