com.vaadin.collaborationengine.
Class CollaborationEngine
CollaborationEngine is an API for creating collaborative experiences in
Vaadin applications. It's used by sending and subscribing to changes between
collaborators via collaboration topics
.
Use getInstance()
to get a reference to the singleton object in
cases where Vaadin's thread locals are defined (such as in UI code invoked by
the framework). In other circumstances, an instance can be found as an
attribute in the runtime context (typically ServletContext
) using the
fully qualified class name of this class as the attribute name. That instance
will only be available after explicitly calling
configure(VaadinService, CollaborationEngineConfiguration)
during
startup or calling getInstance()
at least once.
Since:
1.0
Author:
Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionstatic CollaborationEngine
configure
(VaadinService vaadinService, CollaborationEngineConfiguration configuration) Sets the configuration for the Collaboration Engine associated with the given Vaadin service.
static CollaborationEngine
Gets the
CollaborationEngine
instance from the currentVaadinService
.static CollaborationEngine
getInstance
(VaadinService vaadinService) Gets the
CollaborationEngine
instance from the providedVaadinService
.Gets a system connection context for this collaboration engine instance.
int
getUserColorIndex
(UserInfo userInfo) Gets the color index of a user if different to -1, or let Collaboration Engine provide one.
openTopicConnection
(ConnectionContext context, String topicId, UserInfo localUser, SerializableFunction<TopicConnection, Registration> connectionActivationCallback) Opens a connection to the collaboration topic with the provided id based on a generic context definition.
openTopicConnection
(Component component, String topicId, UserInfo localUser, SerializableFunction<TopicConnection, Registration> connectionActivationCallback) Opens a connection to the collaboration topic with the provided id based on a component instance.
void
requestAccess
(ConnectionContext context, UserInfo user, Consumer<AccessResponse> requestCallback) Deprecated, for removal: This API element is subject to removal in a future version.
void
requestAccess
(UserInfo user, Consumer<AccessResponse> requestCallback) Deprecated, for removal: This API element is subject to removal in a future version.
this method is deprecated and now the callback always receives a response that resolves totrue
-
Method Details
-
getInstance
Gets the
CollaborationEngine
instance from the currentVaadinService
.Situations without a current
VaadinService
can also find the corresponding instance by looking it up from the runtime context (such asServletContext
) usingCollaborationEngine.class.getName()
as the attribute name. That instance will only be available after explicitly callingconfigure(VaadinService, CollaborationEngineConfiguration)
during startup or callinggetInstance()
at least once.Returns:
the
CollaborationEngine
instanceSince:
1.0
-
getInstance
Gets the
CollaborationEngine
instance from the providedVaadinService
.Returns:
the
CollaborationEngine
instanceSince:
3.0
-
configure
public static CollaborationEngine configure(VaadinService vaadinService, CollaborationEngineConfiguration configuration) Sets the configuration for the Collaboration Engine associated with the given Vaadin service. This configuration is required when running in production mode. It can be set only once.
You should register a
VaadinServiceInitListener
where you call this method with the service returned byServiceInitEvent.getSource()
.Parameters:
vaadinService
- the Vaadin service for which to configure the Collaboration Engineconfiguration
- the configuration to provide for the Collaboration EngineReturns:
the configured Collaboration Engine instance
Since:
3.0
-
openTopicConnection
public TopicConnectionRegistration openTopicConnection(Component component, String topicId, UserInfo localUser, SerializableFunction<TopicConnection, Registration> connectionActivationCallback) Opens a connection to the collaboration topic with the provided id based on a component instance. If the topic with the provided id does not exist yet, it's created on demand.
Parameters:
component
- the component which hold UI access, notnull
topicId
- the id of the topic to connect to, notnull
localUser
- the user who is related to the topic connection, aSystemUserInfo
can be used for non-interaction threads. Notnull
.connectionActivationCallback
- the callback to be executed when a connection is activated, notnull
Returns:
the handle that can be used for configuring or closing the connection
Since:
1.0
-
openTopicConnection
public TopicConnectionRegistration openTopicConnection(ConnectionContext context, String topicId, UserInfo localUser, SerializableFunction<TopicConnection, Registration> connectionActivationCallback) Opens a connection to the collaboration topic with the provided id based on a generic context definition. If the topic with the provided id does not exist yet, it's created on demand.
Parameters:
context
- context for the connectiontopicId
- the id of the topic to connect to, notnull
localUser
- the user who is related to the topic connection, aSystemUserInfo
can be used for non-interaction threads. Notnull
.connectionActivationCallback
- the callback to be executed when a connection is activated, notnull
Returns:
the handle that can be used for configuring or closing the connection
Since:
1.0
-
requestAccess
@Deprecated(since="6.3", forRemoval=true) public void requestAccess(UserInfo user, Consumer<AccessResponse> requestCallback) Deprecated, for removal: This API element is subject to removal in a future version.this method is deprecated and now the callback always receives a response that resolves totrue
Requests access for a user to Collaboration Engine. The provided callback will be invoked with a response that tells whether the access is granted.
This method is deprecated and the provided callback always receives a response that resolves to
true
. This means it is not more necessary to use this method since access is now always granted.The current
UI
is accessed to run the callback, which means that UI updates in the callback are pushed to the client in real-time. Because of depending on the current UI, the method can be called only in the request processing thread, or it will throw.Parameters:
user
- the user requesting accessrequestCallback
- the callback to accept the responseSince:
3.0
-
requestAccess
@Deprecated(since="6.3", forRemoval=true) public void requestAccess(ConnectionContext context, UserInfo user, Consumer<AccessResponse> requestCallback) Deprecated, for removal: This API element is subject to removal in a future version.this method is deprecated and now the callback always receives a response that resolves totrue
Requests access for a user to Collaboration Engine. The provided callback will be invoked with a response that tells whether the access is granted.
This method is deprecated and the provided callback always receives a response that resolves to
true
. This means it is not more necessary to use this method since access is now always granted.Parameters:
context
- context for the connectionuser
- the user requesting accessrequestCallback
- the callback to accept the responseSince:
3.0
-
getUserColorIndex
Gets the color index of a user if different to -1, or let Collaboration Engine provide one. If the color index for a user id does not exist yet, it's created on demand based on the user id.
Parameters:
userInfo
- user infoReturns:
the color index
Since:
3.1
-
getSystemContext
Gets a system connection context for this collaboration engine instance. The system connection context can be used when Collaboration Engine is used in situations that aren't directly associated with a UI, such as from a background thread or when integrating with external services.
Returns:
a system connection context instance, not
null
-
true