PersistentServerRegistry class

A CRDTServerRegistry that keeps every document it serves on disk.

It holds the live CRDTDocuments and routes to them, the way any registry does. It never reads or writes storage by hand. Each document gets a CRDTDocumentPersistence, which follows CRDTDocument.events and writes down what each event reports. So a change applied here is stored, a snapshot replaces the one before it, and a prune drops exactly the changes it covered — all of it batched, and inside a CRDTDocumentStorage.transaction where the backend has one.

It works on any adapter, because it only ever sees the storage contract:

final registry = PersistentServerRegistry(
  backend: await CRDTHive.open(),
  compactAfter: 500,
);

Documents are opened lazily: a document costs nothing until something asks for it. Getting one back out of memory never happens on its own. Call releaseDocument when a room empties, or pass idleAfter and let the registry do it. With neither, a server holds every document it has ever been asked for.

Call close on shutdown. It flushes every open document.

Implemented types
Mixed-in types

Constructors

PersistentServerRegistry({required CRDTStorageBackend backend, ServerDocumentCatalog? catalog, Duration writeDelay = const Duration(milliseconds: 250), int? compactAfter, Duration? idleAfter, void onError(Object error, StackTrace stack)?})
Creates a registry that stores its documents in backend.

Properties

backend → CRDTStorageBackend
Where this registry keeps its documents.
no setter
catalog ServerDocumentCatalog
The catalog this registry keeps its document ids in.
no setter
documentCount Future<int>
Get the number of documents registered
no setteroverride
documentIds Future<Set<String>>
Get all document IDs
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
snapshots Stream<ServerSnapshot>
The snapshot each document takes, as it takes it.
no setter

Methods

addDocument(String documentId, {PeerId? author}) Future<void>
Register a document
override
afterSnapshot(String documentId, Snapshot snapshot) Future<void>
Waits for the snapshot and the prune it caused to reach the disk.
override
applyChange(String documentId, Change change) Future<bool>
Applies change to documentId and returns whether it was new.
inherited
close() Future<void>
Flushes and closes every open document.
override
createSnapshot(String documentId) Future<Snapshot>
Snapshots documentId and hands the snapshot to afterSnapshot.
inherited
getDocument(String documentId) Future<CRDTDocument?>
Get a store for an existing document
override
getLatestSnapshot(String documentId) Future<Snapshot?>
The newest snapshot stored for documentId.
override
hasDocument(String documentId) Future<bool>
Check if a document exists
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
releaseDocument(String documentId) Future<void>
Writes what documentId is holding, closes it, and lets go of it.
removeDocument(String documentId) Future<void>
Forgets documentId: flushes it, closes it, and drops it from the catalog.
override
requireDocument(String documentId) Future<CRDTDocument>
The document documentId holds, or throws ArgumentError when this registry does not serve it.
inherited
toString() String
A string representation of this object.
inherited

Operators

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