Class MessageManager

All Implemented Interfaces:
Serializable

public class MessageManager extends AbstractCollaborationManager
Manager to handle messages sent to a topic. It allows submitting messages to a topic and set a handler to react when a new message has been submitted.
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • MessageManager

      public MessageManager(Component component, UserInfo localUser, String topicId)
      Creates a new manager for the given component.
      Parameters:
      component - the component which holds UI access, not null
      localUser - the information of the local user, not null
      topicId - the id of the topic to connect to, not null
    • MessageManager

      public MessageManager(Component component, UserInfo localUser, String topicId, CollaborationMessagePersister persister)
      Creates a new persisting manager for the given component.
      Parameters:
      component - the component which holds UI access, not null
      localUser - the information of the local user, not null
      topicId - the id of the topic to connect to, not null
      persister - the persister to read/write messages to an external source
    • MessageManager

      @Deprecated(since="6.1", forRemoval=true) public MessageManager(ConnectionContext context, UserInfo localUser, String topicId, CollaborationEngine collaborationEngine)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This constructor is not compatible with serialization
      Creates a new manager for the given connection context.
      Parameters:
      context - the context that manages connection status, not null
      localUser - the information of the local user, not null
      topicId - the id of the topic to connect to, not null
      collaborationEngine - the collaboration engine instance to use, not null
    • MessageManager

      public MessageManager(ConnectionContext context, UserInfo localUser, String topicId, SerializableSupplier<CollaborationEngine> ceSupplier)
      Creates a new manager for the given connection context.
      Parameters:
      context - the context that manages connection status, not null
      localUser - the information of the local user, not null
      topicId - the id of the topic to connect to, not null
      ceSupplier - the collaboration engine instance to use, not null
    • MessageManager

      @Deprecated(since="6.1", forRemoval=true) public MessageManager(ConnectionContext context, UserInfo localUser, String topicId, CollaborationMessagePersister persister, CollaborationEngine collaborationEngine)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This constructor is not compatible with serialization
      Creates a new persisting manager for the given connection context.
      Parameters:
      context - the context that manages connection status, not null
      localUser - the information of the local user, not null
      topicId - the id of the topic to connect to, not null
      persister - the persister to read/write messages to an external source
      collaborationEngine - the collaboration engine instance to use, not null
    • MessageManager

      public MessageManager(ConnectionContext context, UserInfo localUser, String topicId, CollaborationMessagePersister persister, SerializableSupplier<CollaborationEngine> ceSupplier)
      Creates a new persisting manager for the given connection context.
      Parameters:
      context - the context that manages connection status, not null
      localUser - the information of the local user, not null
      topicId - the id of the topic to connect to, not null
      persister - the persister to read/write messages to an external source
      ceSupplier - the collaboration engine instance to use, not null
  • Method Details

    • setMessageHandler

      public void setMessageHandler(MessageHandler handler)
      Sets a handler which will be invoked for all messages already in the topic and when a new message is submitted.

      The handler accepts a MessageHandler.MessageContext as a parameter which contains a reference to the sent message.

      Parameters:
      handler - the message handler, or null to remove an existing handler
    • submit

      public CompletableFuture<Void> submit(String text)
      Submits a message to the topic as the current local user.
      Parameters:
      text - the text of the message, not null
      Returns:
      a future which will complete when the message has been added to the topic, not null
    • submit

      public CompletableFuture<Void> submit(CollaborationMessage message)
      Submits a message to the topic.
      Parameters:
      message - the message, not null
      Returns:
      a future which will complete when the message has been added to the topic, not null