Package com.vaadin.collaborationengine
Class Backend
java.lang.Object
com.vaadin.collaborationengine.Backend
- Direct Known Subclasses:
LocalBackend
The interface between a cluster backend and Collaboration Engine.
- Author:
- Vaadin Ltd
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This exception is thrown by the {@link EventLog::subscribe()} method if the providedUUID
does not exist in the log.static interface
A strictly ordered log of submitted events.static class
TheSnapshot
class is used to submit and retrieve a snapshot payload using the {@link Backend::replaceSnapshot()} and {@link Backend::loadLatestSnapshot()} methods. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Registration
addMembershipListener
(MembershipListener membershipListener) Adds a listener of membership events.final CollaborationEngine
Gets theCollaborationEngine
used by this backend.abstract UUID
Gets the unique identifier of this backend node.abstract CompletableFuture<Backend.Snapshot>
loadLatestSnapshot
(String name) Loads the latest snapshot of data identified by the given name.abstract Backend.EventLog
openEventLog
(String logId) Opens an event log with the given id.abstract CompletableFuture<Void>
replaceSnapshot
(String name, UUID expectedId, UUID newId, String payload) Submits a snapshot payload of data identified by the given name.final void
setCollaborationEngine
(CollaborationEngine collaborationEngine) Sets theCollaborationEngine
instance for this backend.
-
Constructor Details
-
Backend
public Backend()
-
-
Method Details
-
getCollaborationEngine
Gets theCollaborationEngine
used by this backend.- Returns:
- the
CollaborationEngine
instance, ornull
if not set
-
setCollaborationEngine
Sets theCollaborationEngine
instance for this backend.- Parameters:
collaborationEngine
- theCollaborationEngine
instance, notnull
-
openEventLog
Opens an event log with the given id. The returned object can be used to capture any common state related to this particular event log. An actual underlying connection is not needed untilBackend.EventLog.subscribe(UUID, BiConsumer)
} is invoked, but it is still recommended to make this method fail fast in case it would not be possible to open an actual underlying connection later.- Parameters:
logId
- the id of the event log to open, notnull
- Returns:
- an object representing the event log, not
null
-
addMembershipListener
Adds a listener of membership events. The listener will be notified of events dispatched when a node joins or leaves the backend.- Parameters:
membershipListener
- the listener, notnull
- Returns:
- a registration that can be used to remove the listener, not
null
-
getNodeId
Gets the unique identifier of this backend node.- Returns:
- the node id, not
null
-
loadLatestSnapshot
Loads the latest snapshot of data identified by the given name. To submit a snapshot seereplaceSnapshot(String, UUID, UUID, String)
.- Parameters:
name
- the name identifying the data, notnull
- Returns:
- a completable future resolved with the UUID and snapshot, not
null
-
replaceSnapshot
public abstract CompletableFuture<Void> replaceSnapshot(String name, UUID expectedId, UUID newId, String payload) Submits a snapshot payload of data identified by the given name. The latest submitted snapshot for that name can be loaded withloadLatestSnapshot(String)
.- Parameters:
name
- the name identifying the date, notnull
expectedId
- the unique ID of the expected current snapshotnewId
- the unique ID that the new snapshot will be stored with, notnull
payload
- the snapshot payload, notnull
- Returns:
- a completable future that will be resolved when the operation
completes, not
null
-