com.vaadin.collaborationengine.Backend Maven / Gradle / Ivy
/*
* Copyright (C) 2021 Vaadin Ltd
*
* This program is available under Commercial Vaadin Runtime License 1.0
* (CVRLv1).
*
* For the full License, see http://vaadin.com/license/cvrl-1
*/
package com.vaadin.collaborationengine;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.vaadin.flow.shared.Registration;
/**
* The interface between a cluster backend and Collaboration Engine.
*
* @author Vaadin Ltd
*/
public interface Backend {
/**
* A strictly ordered log of submitted events.
*/
interface EventLog {
/**
* Submits an event through the backend to all subscribers. The tracking
* id needs to be delivered to active subscribers but it is not
* necessary to preserve it for replaying old events to new subscribers.
*
* @param trackingId
* the tracking id of this event, not null
* @param eventPayload
* the JSON object representing the event, not
* null
*/
void submitEvent(UUID trackingId, ObjectNode eventPayload);
/**
* Adds a subscriber to receive all past and future events for this
* event log. A newly added subscriber should initially receive all
* previous events in the log based on their original order so that it
* can catch up with the latest state. New events should be delivered
* (in order) only after all previous events have been delivered. It is
* not allowed to invoke the consumer again until the previous
* invocation has returned.
*
* @param eventConsumer
* a consumer that should receive all events, not
* null
* @return a registration to remove the event consumer, not
* null
*/
Registration subscribe(BiConsumer eventConsumer);
}
/**
* 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 until
* {@link EventLog#subscribe(Consumer)} 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.
*
* @param logId
* the id of the event log to open, not null
* @return an object representing the event log, not null
*/
EventLog openEventLog(String logId);
}