InMemoryLoom

class InMemoryLoom(policy: DeliveryPolicy = DeliveryPolicy.Reliable) : Loom

In-memory implementation of Loom for use in tests and integration harnesses. All Seam instances produced by the same factory instance share a single in-memory mesh.

One instance is exactly one flat mesh — hence one concurrently hosted room. A single InMemoryLoom has no notion of separate sessions: every seam it weaves (whether via host/Rendezvous.New or join/Rendezvous.Existing) joins the same peer set and receives every broadcast on it. So the correct shape is one host plus any number of joins — that is the whole mesh.

Hosting a second, concurrent room on one instance (a second Rendezvous.New while the first host seam is still live) is a misuse: the two "rooms" would silently cross-admit each other's members over the shared mesh rather than being isolated. To make that loud rather than silently corrupt, a second concurrent Rendezvous.New throws IllegalStateException. For multi-room tests, use one InMemoryLoom per room, or the InMemoryRoomFabric helper in :kuilt-test.

Re-hosting after the prior host tears is allowed. Once the hosting seam is closed/removed, a fresh Rendezvous.New is permitted again — this models a real fabric's re-host-after-drop and keeps client-side resume (MuxClientLoom re-weaves its base after a tear) and dynamic ply re-attach (CompositeLoom re-weaves a detached ply) working over the in-memory bedrock. The guard rejects two live hosts, never a sequential re-weave. Rendezvous.Existing (joiners) stays unlimited and never touches the guard.

Thread-safe: the shared mesh state is protected by a Mutex. Frame delivery is bounded and backpressured via one Spool per link, with overflow behaviour chosen by DeliveryPolicy.

The suspending deliver call happens outside the factory mutex — sequence numbers are assigned under the lock, then delivery is performed after releasing it, so a SUSPEND-policy backpressure suspension never holds the mutex.

Not a production transport — no discovery, no network, no serialization. Intended to be the test bedrock for :session-protocol and every layer above it.

Constructors

Link copied to clipboard
constructor(policy: DeliveryPolicy = DeliveryPolicy.Reliable)

Properties

Link copied to clipboard
val peers: StateFlow<Set<PeerId>>

Functions

Link copied to clipboard

Whether this fabric can be attempted now — the availability half of capability. Derived; do not override.

Link copied to clipboard

This fabric's role(s) and whether it can be attempted now. The single capability primitive — override this, not availability. Default: a roleless FabricAvailability.Available.

Link copied to clipboard
open suspend fun host(pattern: Pattern): Seam

Host / start a new session.

Link copied to clipboard
open suspend fun join(tag: Tag): Seam

Join an existing session. The advertisement carries enough info to reach the existing peer set.

Link copied to clipboard
open suspend override fun weave(rendezvous: Rendezvous): Seam

Establish a Seam according to rendezvous — either host a new session or join an existing one.