HeartbeatPartitionDetector

class HeartbeatPartitionDetector(link: Seam, peerId: PeerId, config: HeartbeatConfig = HeartbeatConfig(), clock: () -> Instant) : PartitionDetector

Application-level heartbeat-based implementation of PartitionDetector.

Runs a ping loop on link, emitting PartitionEvents as the peer transitions through the Healthy → Unresponsive → Lost state machine.

State machine (per peer):

Healthy ──(no frame for config.timeout)──────────────► Unresponsive
Healthy ──(onBackpressure called)────────────────────► Unresponsive(Backpressure)
Healthy ──(link closes)──────────────────────────────► Unresponsive(TransportClosed)
Unresponsive ──(frame observed)──────────────────────► Healthy (PeerRecovered emitted)
Unresponsive ──(reconnectWindow elapsed)─────────────► Lost (PeerLost emitted; stops)

Heartbeat frame format: Ping frames carry the prefix kuilt.heartbeat.ping; pong frames carry kuilt.heartbeat.pong. Both are consumed internally and never forwarded to the application's Seam.incoming subscription. Applications must not emit frames with these prefixes.

Clock injection: clock is never kotlin.time.Clock.System — it is injected by the caller so tests can use a fixed value and runTest virtual time controls all delays.

Parameters

link

The Seam to the monitored peer.

peerId

The remote peer's PeerId.

config

Timing parameters.

clock

Provides the current Instant; inject a fixed value in tests.

Constructors

Link copied to clipboard
constructor(link: Seam, peerId: PeerId, config: HeartbeatConfig = HeartbeatConfig(), clock: () -> Instant)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val events: Flow<PartitionEvent>

Stream of reachability events for the monitored peer.

Link copied to clipboard

When the monitored peer was last heard from: the instant of the latest inbound frame of any kind, ping, pong or application, or of start if nothing has arrived since. null before start.

Functions

Link copied to clipboard
open override fun observedPeer(peerId: PeerId)

Record that a frame arrived from the monitored peer.

Link copied to clipboard
open override fun onBackpressure(peerId: PeerId)

Signal that the per-peer outbound buffer has exceeded its ceiling.

Link copied to clipboard
open override fun start(scope: CoroutineScope)

Start the heartbeat loop, scoped to scope.

Link copied to clipboard
open suspend override fun stop()

Stop the heartbeat loop and complete the events flow.