EphemeralMapTracker

class EphemeralMapTracker<V>(val ttlMs: Long, clock: () -> Long = defaultClock())

A stateful wrapper around EphemeralMap that stamps local receive times and drives TTL eviction.

Responsibilities

  • Maintains a mutable EphemeralMap state by merging inbound EphemeralMap updates via received.

  • Stamps a local receive time (via clock) whenever a replica's entry advances to a higher clock — i.e. only real updates reset the TTL, not stale re-deliveries.

  • Surfaces live: the set of entries not yet expired and not departed.

Clock contract

clock is a () -> Long that returns the current local monotonic time in milliseconds. The production default is kotlin.time.TimeSource.Monotonic. Tests inject a controlled counter so eviction can be driven deterministically without wall-clock dependencies.

Parameters

ttlMs

expiry window in milliseconds. An entry is considered expired when now - receiveTime >= ttlMs. The boundary is exclusive: exactly at ttlMs ms the entry is expired.

clock

injectable monotonic time source (milliseconds).

Type Parameters

V

the presence value type.

Constructors

Link copied to clipboard
constructor(ttlMs: Long, clock: () -> Long = defaultClock())

Properties

Link copied to clipboard
val ttlMs: Long

Functions

Link copied to clipboard
fun live(): Map<ReplicaId, V>

Returns the current set of live entries: non-departed, non-expired replicas mapped to their values.

Link copied to clipboard
fun received(update: EphemeralMap<V>)

Merge an inbound update into the local state.

Link copied to clipboard

The current merged CRDT state (all entries, including departed/stale).