Class AbstractClientSession

java.lang.Object
org.cometd.common.AbstractClientSession
All Implemented Interfaces:
ClientSession, Session, org.eclipse.jetty.util.component.Dumpable
Direct Known Subclasses:
BayeuxClient, LocalSessionImpl

public abstract class AbstractClientSession extends Object implements ClientSession, org.eclipse.jetty.util.component.Dumpable

Partial implementation of ClientSession.

It handles extensions and batching, and provides utility methods to be used by subclasses.

  • Constructor Details Link icon

    • AbstractClientSession Link icon

      protected AbstractClientSession()
  • Method Details Link icon

    • newMessageId Link icon

      protected String newMessageId()
    • addExtension Link icon

      public void addExtension(ClientSession.Extension extension)
      Description copied from interface: ClientSession
      Adds an extension to this session.
      Specified by:
      addExtension in interface ClientSession
      Parameters:
      extension - the extension to add
      See Also:
    • removeExtension Link icon

      public void removeExtension(ClientSession.Extension extension)
      Description copied from interface: ClientSession
      Removes an extension from this session.
      Specified by:
      removeExtension in interface ClientSession
      Parameters:
      extension - the extension to remove
      See Also:
    • getExtensions Link icon

      public List<ClientSession.Extension> getExtensions()
      Specified by:
      getExtensions in interface ClientSession
      Returns:
      an immutable list of extensions present in this ClientSession instance
      See Also:
    • extendOutgoing Link icon

      protected void extendOutgoing(Message.Mutable message, Promise<Boolean> promise)
    • extendIncoming Link icon

      protected void extendIncoming(Message.Mutable message, Promise<Boolean> promise)
    • newChannelId Link icon

      protected abstract ChannelId newChannelId(String channelId)
    • newChannel Link icon

      protected abstract AbstractClientSession.AbstractSessionChannel newChannel(ChannelId channelId)
    • getChannel Link icon

      public ClientSessionChannel getChannel(String channelName)
      Description copied from interface: ClientSession

      Returns a client side channel scoped by this session.

      The channel name may be for a specific channel (e.g. "/foo/bar") or for a wild channel (e.g. "/meta/**" or "/foo/*").

      This method will always return a channel, even if the the channel has not been created on the server side. The server side channel is only involved once a publish or subscribe method is called on the channel returned by this method.

      Typical usage examples are:

           clientSession.getChannel("/foo/bar").subscribe(mySubscriptionListener);
           clientSession.getChannel("/foo/bar").publish("Hello");
           clientSession.getChannel("/meta/*").addListener(myMetaChannelListener);
       
      Specified by:
      getChannel in interface ClientSession
      Parameters:
      channelName - specific or wild channel name.
      Returns:
      a channel scoped by this session.
    • getChannel Link icon

      public ClientSessionChannel getChannel(ChannelId channelId)
    • getChannels Link icon

    • startBatch Link icon

      public void startBatch()
      Description copied from interface: Session

      Starts a batch, to be ended with Session.endBatch().

      The Session.batch(Runnable) method should be preferred since it automatically starts and ends a batch without relying on a try/finally block.

      This method is to be used in the cases where the use of Session.batch(Runnable) is not possible or would make the code more complex.

      Specified by:
      startBatch in interface Session
      See Also:
    • sendBatch Link icon

      protected abstract void sendBatch()
    • endBatch Link icon

      public boolean endBatch()
      Description copied from interface: Session

      Ends a batch started with Session.startBatch().

      Specified by:
      endBatch in interface Session
      Returns:
      true if the batch ended and there were messages to send.
      See Also:
    • batch Link icon

      public void batch(Runnable batch)
      Description copied from interface: Session

      Executes the given command in a batch so that any Bayeux message sent by the command (via the Bayeux API) is queued up until the end of the command and then all messages are sent at once.

      Specified by:
      batch in interface Session
      Parameters:
      batch - the Runnable to run as a batch
    • isBatching Link icon

      protected boolean isBatching()
    • getAttribute Link icon

      public Object getAttribute(String name)
      Description copied from interface: Session

      Retrieves the value of named session attribute.

      Specified by:
      getAttribute in interface Session
      Parameters:
      name - the name of the attribute
      Returns:
      the attribute value or null if the attribute is not present
    • getAttributeNames Link icon

      public Set<String> getAttributeNames()
      Specified by:
      getAttributeNames in interface Session
      Returns:
      the session attribute names.
    • removeAttribute Link icon

      public Object removeAttribute(String name)
      Description copied from interface: Session

      Removes a named session attribute.

      Specified by:
      removeAttribute in interface Session
      Parameters:
      name - the name of the attribute
      Returns:
      the value of the attribute
    • setAttribute Link icon

      public void setAttribute(String name, Object value)
      Description copied from interface: Session

      Sets a named session attribute value.

      Session attributes are convenience data that allows arbitrary application data to be associated with a session.

      Specified by:
      setAttribute in interface Session
      Parameters:
      name - the attribute name
      value - the attribute value
    • remoteCall Link icon

      public void remoteCall(String target, Object data, ClientSession.MessageListener callback)
      Description copied from interface: ClientSession

      Performs a remote call to the server, to the specified target, and with the given data as payload.

      The remote call response will be delivered via the callback parameter.

      Typical usage:

       clientSession.remoteCall("getOnlineStatus", userId, new MessageListener()
       {
           @Override
           public void onMessage(Message message)
           {
               if (message.isSuccessful())
               {
                   String status = (String)message.getData();
                   // Update UI with online status.
               }
               else
               {
                   // Remote call failed.
               }
           }
       });
       
      Specified by:
      remoteCall in interface ClientSession
      Parameters:
      target - the remote call target
      data - the remote call parameters
      callback - the listener that receives the remote call response
    • send Link icon

      protected abstract void send(Message.Mutable message)
    • newMessage Link icon

      protected Message.Mutable newMessage()
    • resetSubscriptions Link icon

      protected void resetSubscriptions()
    • receive Link icon

      public void receive(Message.Mutable message, Promise<Void> promise)

      Receives a message (from the server) and process it.

      Processing the message involves calling the receive extensions and the channel listeners.

      Parameters:
      message - the message received.
      promise - the promise notified of the receive processing
    • notifyListeners Link icon

      protected void notifyListeners(Message.Mutable message)
    • notifyCallback Link icon

      protected void notifyCallback(ClientSession.MessageListener callback, Message.Mutable message)
    • registerCallback Link icon

      protected void registerCallback(String messageId, ClientSession.MessageListener callback)
    • unregisterCallback Link icon

      protected ClientSession.MessageListener unregisterCallback(String messageId)
    • registerSubscriber Link icon

      protected void registerSubscriber(String messageId, ClientSessionChannel.MessageListener subscriber)
    • unregisterSubscriber Link icon

      protected ClientSessionChannel.MessageListener unregisterSubscriber(String messageId)
    • dump Link icon

      public void dump(Appendable out, String indent) throws IOException
      Specified by:
      dump in interface org.eclipse.jetty.util.component.Dumpable
      Throws:
      IOException