Interface ConnectionContext

All Superinterfaces:
Serializable
All Known Implementing Classes:
ComponentConnectionContext, SystemConnectionContext

public interface ConnectionContext extends Serializable
The context in which a topic connection is active. This makes it possible for a connection to become deactivate when it is no longer needed and activate it again if the context status changes. The context does also handle synchronization of date change notifications delivered to application code.

ComponentConnectionContext is used internally by all high-level components such as CollaborationAvatarGroup and by shorthand methods such as CollaborationEngine.openTopicConnection(com.vaadin.flow.component.Component, String, UserInfo, com.vaadin.flow.function.SerializableFunction) that take a component instance as the context. This implementation activates the topic connection whenever the target component is attached and deactivates it when the component is detached. UI.access(com.vaadin.flow.server.Command) is used for synchronization.

SystemConnectionContext is intended for application logic that integrates with external services that are not directly related to UI components. This context implementation is immediately active and remains active until the application is shut down (based on VaadinService.addServiceDestroyListener(com.vaadin.flow.server.ServiceDestroyListener). Each use site (for instance each individual topic connection) gets its own synchronization to ensure events are delivered in the expected order, but still avoiding contention between other use sites.

Since:
1.0
Author:
Vaadin Ltd
  • Method Details

    • init

      Registration init(ActivationHandler activationHandler, Executor executor)
      Initializes the connection context with a ActivationHandler and an Executor.

      The method Consumer.accept(Object) from the provided ActivationHandler should be called with an ActionDispatcher when this ConnectionContext is activated. When this ConnectionContext is deactivated, it should call Consumer.accept(Object) with a null parameter.

      The ActionDispatcher should ensure synchronization within the context of this ConnectionContext.

      Parameters:
      activationHandler - the handler for activation changes
      executor - executor that should be used by the handler to execute background tasks. Not null
      Returns:
      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