DocumentSessionHost class

CRDT-aware session host: the server half of the document sync protocol, with no transport of its own.

It keeps the CRDTServerRegistry, turns accepted connections into DocumentClientSessions, rebroadcasts applied changes, and takes an aligned snapshot once every subscribed client has confirmed the server's state.

Once running, it also sends each snapshot a document of the registry takes to the clients of that document.

Feed it connections with SessionHostServer.acceptConnection. For a host that owns its own dart:io socket, use WebSocketServer instead.

Inheritance
Implementers

Constructors

DocumentSessionHost({required CRDTServerRegistry serverRegistry, Compressor? compressor, MessageCodec<Message>? messageCodec, int? maxBufferSize, List<ServerSyncPlugin>? plugins})
CRDT-aware session host: the server half of the document sync protocol, with no transport of its own.

Properties

compressor → Compressor
Compressor handed to every session this host creates.
finalinherited
debugLabel → String
Name of the concrete host, used in diagnostics.
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
isRunning → bool
Whether this host accepts sessions and does its background work.
no setterinherited
maxBufferSize → int?
Maximum outbound buffer size per client session (bytes).
finalinherited
messageCodec → MessageCodec<Message>?
Message codec handed to every session this host creates.
finalinherited
ownsTransport → bool
Whether this host owns the transport it serves on.
no setterinherited
plugins → List<ServerSyncPlugin>
The server plugins
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serverEvents → Stream<ServerEvent>
Server events stream
no setterinherited
serverRegistry → CRDTServerRegistry
The registry holding the documents this host serves.
no setter
sessions → Map<String, DocumentClientSession>
Active sessions, by id.
no setterinherited
startedMessage → String
Message of the ServerEventType.started event.
no setterinherited
state → SessionHostState
Where this host is in its lifecycle.
no setterinherited
stoppedMessage → String
Message of the ServerEventType.stopped event.
no setterinherited

Methods

acceptConnection(TransportConnection connection, {String? sessionId}) → DocumentClientSession?
Register connection as a new session and return it.
inherited
addServerEvent(ServerEvent event) → void
Emit a ServerEvent on serverEvents.
inherited
broadcastMessage(Message message, {List<String>? excludeClientIds}) → Future<void>
Broadcast a message to all subscribed clients
inherited
closeAllSessions() → Future<void>
Gracefully close every session.
inherited
createSession({required String id, required TransportConnection connection}) → DocumentClientSession
Create the session for a newly accepted connection.
override
dispose() → Future<void>
Dispose the server
inherited
handleSessionClosed(String sessionId) → void
Drop a session whose event stream ended.
inherited
handleSessionError(String sessionId, dynamic error) → void
Report an error on a session's event stream.
inherited
handleSessionEvent(SessionEvent event) → FutureOr<void>
Handle a SessionEvent from one of this host's sessions.
override
handleSessionEventDisconnected(SessionEventGeneric event) → void
Report a disconnect and drop the session.
inherited
handleSessionEventError(SessionEventGeneric event) → void
Report a session-level error.
inherited
handleSessionEventPingReceived(SessionEventGeneric event) → Future<void>
Report a ping from a client.
override
maybeTakeAlignedSnapshot(String documentId) → Future<void>
Take a snapshot (and prune the confirmed history) when every client subscribed to documentId has confirmed at least the server's current state.
maybeTakeAlignedSnapshotForSession(String sessionId) → Future<void>
Run the snapshot coordinator for every document sessionId is subscribed to.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onDispose() → Future<void>
Release what this host holds beyond its sessions and plugins.
override
onRunning() → void
Runs each time this host becomes isRunning: on start, or on the first acceptConnection of a host that does not own its transport.
override
onStart() → Future<void>
Bring up the transport this host owns. Only called when ownsTransport.
inherited
onStarted() → Future<void>
Start serving requests. Only called when ownsTransport.
inherited
onStop() → Future<void>
Tear down the transport this host owns. Only called when ownsTransport.
inherited
sendMessageToClient(String clientId, Message message) → Future<void>
Send a message to a specific client
inherited
sessionById(String id) → DocumentClientSession?
The session with id, if this host still holds it.
inherited
start() → Future<bool>
Start the server
inherited
startFailureMessage(Object error) → String
Message of the ServerEventType.error event reported when start fails.
inherited
stop() → Future<void>
Stop the server
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited