ManagedRaftTransport

class ManagedRaftTransport(scope: CoroutineScope, val selfId: NodeId) : RaftTransport

A RaftTransport whose backing Seam can be replaced on transport tear without recreating the us.tractat.kuilt.raft.RaftNode.

The RaftNode keeps its identity and state across reconnects; only the underlying Seam is swapped when the entry server changes. This is the core primitive that makes us.tractat.kuilt.cluster.clusterClient possible.

Lifecycle

  1. Construct with the node's stable NodeId. The transport starts with no backing Seam — peers is empty and sendTo drops frames silently until swapSeam is first called.

  2. Pass this transport to scope.raftNode(...) — the RaftNode lifetime is bound to scope; this transport outlives individual Seam instances.

  3. Call swapSeam with the first (and each subsequent) Seam — the RaftNode begins or resumes operation.

  4. On transport tear: call swapSeam again with the freshly-joined Seam.

Thread safety

The current SeamRaftTransport pointer is guarded by an atomicfu reentrant lock. incoming is a hot MutableSharedFlow relayed from each seam's incoming flow; each swap launches a new relay coroutine in scope and cancels the previous one. The lock is never held across a suspend call.

Reachable peers across the swap

peers is a MutableStateFlow updated to reflect the newly installed seam's peer set on each swapSeam. Between a tear and a swap, peers holds the last known set (possibly stale).

Parameters

scope

The CoroutineScope for relay coroutines. Must outlive all swapSeam calls.

selfId

This node's stable NodeId — does not change across reconnects.

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope, selfId: NodeId)

Properties

Link copied to clipboard
open override val incoming: Flow<RaftEnvelope>
Link copied to clipboard
open val maxPayloadBytes: Int?
Link copied to clipboard
open override val peers: StateFlow<Set<NodeId>>
Link copied to clipboard
open override val selfId: NodeId

Functions

Link copied to clipboard
open suspend override fun sendTo(peer: NodeId, message: ByteArray)
Link copied to clipboard
fun swapSeam(newSeam: Seam)

Replace the backing Seam with newSeam.