ServerClusterReconnect
Reconnect helper for a joiner that faces a static cluster of server endpoints.
Connects to one endpoint at a time. On transport tear, advances to the next endpoint per the selector (default: deterministic round-robin). Only the server that admitted the joiner holds a seat for its device key, so joining a different endpoint is a fresh admission there.
Usage
val reconnect = ServerClusterReconnect(
endpoints = listOf(tag0, tag1, tag2),
)
// Initial connection:
val seam = reconnect.connect(loom)
// On transport tear:
reconnect.onTransportTear()
val newSeam = reconnect.connect(loom)Thread safety
All mutable state is guarded by an atomicfu reentrantLock. Suspend calls (connect) are issued outside the locked section to comply with the lock-discipline rule: no suspending code inside a locked region.
This helper is caller-orchestrated: it tracks the current endpoint, and connect delegates straight to Loom.join on the calling coroutine. It launches no background work, so it owns no kotlinx.coroutines.CoroutineScope. If a future iteration makes it manage the connect → tear → reconnect loop itself, a required scope parameter is reintroduced then (and actually used).
Parameters
Ordered list of server endpoint Tags. Must be non-empty.
Strategy that determines which index to activate on each advanceEndpoint call. Default: deterministic round-robin starting at index 0.
Constructors
Functions
Advance to the next endpoint as determined by selector.
The endpoint this helper is currently targeting.
React to a transport tear by advancing to the next endpoint.