ServerClusterReconnect

class ServerClusterReconnect(endpoints: List<Tag>, selector: EndpointSelector = RoundRobinEndpointSelector(startIndex = 0))

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

endpoints

Ordered list of server endpoint Tags. Must be non-empty.

selector

Strategy that determines which index to activate on each advanceEndpoint call. Default: deterministic round-robin starting at index 0.

Constructors

Link copied to clipboard
constructor(endpoints: List<Tag>, selector: EndpointSelector = RoundRobinEndpointSelector(startIndex = 0))

Functions

Link copied to clipboard

Advance to the next endpoint as determined by selector.

Link copied to clipboard
suspend fun connect(loom: Loom): Seam

Weave a new Seam against the currentEndpoint using loom.

Link copied to clipboard

The endpoint this helper is currently targeting.

Link copied to clipboard

React to a transport tear by advancing to the next endpoint.