PersistentServerRegistry constructor
- 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.
backend is what an adapter opens: CRDTHive.open(), CRDTDrift.open()
or CRDTSqlite.open(). It is asked for a document's storages the first
time that document is needed,
and for the identity the server writes it under — so a restarted server
is the same author it was before, instead of growing every document's
version vector by an entry that never leaves.
catalog is what answers documentIds, hasDocument and
documentCount. It defaults to a BackendDocumentCatalog over
backend, which is what makes the server find its documents again after
a restart. Pass an InMemoryServerDocumentCatalog for a server that
should start empty and fill up as clients name their documents.
writeDelay is how long a change waits for the ones after it, so a burst
of edits is one write instead of twenty. It leaves a window where a change
is acknowledged to a client but not yet on disk. That is safe: a client
reconciles at the next handshake and re-sends whatever the server no
longer has. Pass Duration.zero to make the window as small as it gets.
compactAfter snapshots and prunes a document once its store holds more
than that many changes. Leave it null to keep the whole log.
idleAfter releases a document that nothing has asked for in that long,
the way releaseDocument does. Leave it null and a document stays open
until releaseDocument or close is called. See releaseDocument for
the one race it has, and why the explicit call does not.
onError is called when a write fails. Without it a failed write is
silent; what it carried stays queued and the next flush tries again. It
also reports a release that failed to write what it was holding.
Implementation
PersistentServerRegistry({
required CRDTStorageBackend backend,
ServerDocumentCatalog? catalog,
Duration writeDelay = const Duration(milliseconds: 250),
int? compactAfter,
Duration? idleAfter,
void Function(Object error, StackTrace stack)? onError,
}) : _backend = backend,
_catalog = catalog ?? BackendDocumentCatalog(backend),
_writeDelay = writeDelay,
_compactAfter = compactAfter,
_idleAfter = idleAfter,
_onError = onError;