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). On reconnect, the caller presents the pendingToken — which survives endpoint changes because it is keyed on RoomId, not on any specific server identity.
Usage
val reconnect = ServerClusterReconnect(
endpoints = listOf(tag0, tag1, tag2),
)
// Initial connection:
val seam = reconnect.connect(loom)
// ... admit handshake; on success, register the token:
reconnect.setToken(room.resumeToken!!)
// On transport tear:
reconnect.onTransportTear()
val newSeam = reconnect.connect(loom)
// Present the token for resume on the new endpoint:
room.resume(reconnect.pendingToken()!!)
// On success, clear the token (it has been consumed):
reconnect.clearToken()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 the pending ResumeToken, 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.
Clear the pending token after a successful resume.
The endpoint this helper is currently targeting.
React to a transport tear by advancing to the next endpoint.
Returns the ResumeToken set by setToken, or null if none is registered.
Register a ResumeToken acquired after a successful admit handshake.