Class ReturnChannelMap

All Implemented Interfaces:
Serializable

public class ReturnChannelMap extends ServerSideFeature
Server-side node feature that keeps track of the return channels registered for a state node.

Return channels are only tracked on the server. The client doesn't need to know which channels are registered - it only passes the channel id back to the server. The server checks that the received channel id is (still) valid and logs a warning if it isn't.

For internal use only. May be renamed or removed in a future release.

Since:
2.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • ReturnChannelMap

      public ReturnChannelMap(StateNode node)
      Creates a new return channel map for the given state node.
      Parameters:
      node - the owning state node, not null
  • Method Details

    • registerChannel

      public ReturnChannelRegistration registerChannel(SerializableConsumer<elemental.json.JsonArray> handler)
      Registers a new channel based on a callback that receives the provided arguments when a message is passed to the channel.

      The returned registration can be passed to the client as a parameter to various executeJavaScript methods. The client side representation of the registration will be a function that will send a message to the provided handler.

      Parameters:
      handler - the argument handler, not null
      Returns:
      a return channel registration
    • registerChannel

      public ReturnChannelRegistration registerChannel(SerializableBiConsumer<elemental.json.JsonArray,ReturnChannelRegistration> handler)
      Registers a new channel based on a callback that receives the provided arguments and the channel registration when a message is passed to the channel. The purpose of passing the registration to the handler is to allow the channel to unregister itself when it receives a message.

      The returned registration can be passed to the client as a parameter to various executeJavaScript methods. The client side representation of the registration will be a function that will send a message to the provided handler.

      Parameters:
      handler - the argument and registration handler, not null
      Returns:
      a return channel registration
    • get

      public ReturnChannelRegistration get(int channelId)
      Gets the return channel registration registered with the provided id, or null if no channel is registered with that id.
      Parameters:
      channelId - the channel id to look for
      Returns:
      a return channel registration, or null if no registration exists for the given id
    • hasChannels

      public boolean hasChannels()
      Return if map contains any registered channels.
      Returns:
      true if registered channels exist.