com.vaadin.collaborationengine.
Class ComponentConnectionContext
- java.lang.Object
-
- com.vaadin.collaborationengine.ComponentConnectionContext
-
All Implemented Interfaces:
public class ComponentConnectionContext extends Object implements ConnectionContext
A connection context based on the attach state of a set of component instances. The context is considered active whenever at least one tracked component is attached. All attached components must belong to the same UI instance, and this UI instance is used to dispatch actions using
UI.access(Command)
.Author:
Vaadin Ltd
-
-
Constructor Summary
Constructors Constructor and Description ComponentConnectionContext()
Creates an empty component connection context.
ComponentConnectionContext(Component component)
Creates a new component connection context which is initially using a single component.
-
Method Summary
All Methods Modifier and Type Method and Description void
addComponent(Component component)
Adds a component instance to track for this context.
<T> CompletableFuture<T>
createCompletableFuture()
Gets a completable future that needs to be resolved within the current context.
void
dispatchAction(Command action)
Executes the given action by holding the session lock.
void
removeComponent(Component component)
Stops tracking a component for this context.
Registration
setActivationHandler(ActivationHandler activationHandler)
Sets an instance of
ActivationHandler
to the current context.
-
-
-
Constructor Detail
-
ComponentConnectionContext
public ComponentConnectionContext()
Creates an empty component connection context.
-
ComponentConnectionContext
public ComponentConnectionContext(Component component)
Creates a new component connection context which is initially using a single component.
Parameters:
component
- the component to use, notnull
-
-
Method Detail
-
addComponent
public void addComponent(Component component)
Adds a component instance to track for this context. Calling this method again with a component that is already tracked has no effect.
Parameters:
component
- the component to track, notnull
See Also:
-
removeComponent
public void removeComponent(Component component)
Stops tracking a component for this context. Calling this method for a component that isn't tracked has no effect.
Parameters:
component
- the component to stop tracking, notnull
See Also:
-
setActivationHandler
public Registration setActivationHandler(ActivationHandler activationHandler)
Description copied from interface:
ConnectionContext
Sets an instance of
ActivationHandler
to the current context. This method should include logic for updating the activation status.Specified by:
setActivationHandler
in interfaceConnectionContext
Parameters:
activationHandler
- the handler for activation changesReturns:
the registration for any logic that needs to be cleaned up if the connection is closed permanently, or
null
if there is nothing to clean up
-
dispatchAction
public void dispatchAction(Command action)
Executes the given action by holding the session lock. This is done by using
UI.access(Command)
on the UI that the component(s) associated with this context belong to. This ensures that any UI changes are pushed to the client in real-time ifPush
is enabled.If this context is not active (none of the components are attached to a UI), the action is postponed until the connection becomes active.
Specified by:
dispatchAction
in interfaceConnectionContext
Parameters:
action
- the action to dispatch
-
createCompletableFuture
public <T> CompletableFuture<T> createCompletableFuture()
Description copied from interface:
ConnectionContext
Gets a completable future that needs to be resolved within the current context.
Specified by:
createCompletableFuture
in interfaceConnectionContext
Returns:
the
CompletableFuture
to be resolved
-
-