Class ServerSessionImpl

java.lang.Object
org.cometd.server.ServerSessionImpl
All Implemented Interfaces:
ServerSession, Session, org.eclipse.jetty.util.component.Dumpable

public class ServerSessionImpl extends Object implements ServerSession, org.eclipse.jetty.util.component.Dumpable
  • Constructor Details Link icon

  • Method Details Link icon

    • getBayeuxServer Link icon

      public BayeuxServerImpl getBayeuxServer()
    • getUserAgent Link icon

      public String getUserAgent()
      Specified by:
      getUserAgent in interface ServerSession
      Returns:
      the remote user agent
    • setUserAgent Link icon

      public void setUserAgent(String userAgent)
      Parameters:
      userAgent - the remote user agent
    • getBrowserId Link icon

      public String getBrowserId()
      Returns:
      the remote client identifier
    • setBrowserId Link icon

      public void setBrowserId(String browserId)

      Sets a remote client identifier, typically a browser.

      Parameters:
      browserId - the remote client identifier
    • sweep Link icon

      protected boolean sweep(long now)
    • getSubscriptions Link icon

      public Set<ServerChannel> getSubscriptions()
      Specified by:
      getSubscriptions in interface ServerSession
      Returns:
      the set of channels to which this session is subscribed to
    • addExtension Link icon

      public void addExtension(ServerSession.Extension extension)
      Description copied from interface: ServerSession

      Adds the given extension to this session.

      Specified by:
      addExtension in interface ServerSession
      Parameters:
      extension - the extension to add
      See Also:
    • removeExtension Link icon

      public void removeExtension(ServerSession.Extension extension)
      Description copied from interface: ServerSession

      Removes the given extension from this session.

      Specified by:
      removeExtension in interface ServerSession
      Parameters:
      extension - the extension to remove
      See Also:
    • getExtensions Link icon

      public List<ServerSession.Extension> getExtensions()
      Specified by:
      getExtensions in interface ServerSession
      Returns:
      an immutable list of extensions present in this ServerSession instance
      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
    • deliver Link icon

      public void deliver(Session sender, ServerMessage.Mutable message, Promise<Boolean> promise)
      Description copied from interface: ServerSession

      Delivers the given message to this session.

      This is different from ServerChannel.publish(Session, ServerMessage.Mutable, Promise) as the message is delivered only to this session and not to all subscribers of the channel.

      The message should still have a channel id specified, so that the ClientSession may identify the listeners the message should be delivered to.

      Specified by:
      deliver in interface ServerSession
      Parameters:
      sender - the session delivering the message
      message - the message to deliver
      promise - the promise to notify with the result of the deliver
      See Also:
    • deliver Link icon

      public void deliver(Session sender, String channelId, Object data, Promise<Boolean> promise)
      Description copied from interface: ServerSession

      Delivers the given information to this session.

      Specified by:
      deliver in interface ServerSession
      Parameters:
      sender - the session delivering the message
      channelId - the channel of the message
      data - the data of the message
      promise - the promise to notify with the result of the deliver
      See Also:
    • deliver1 Link icon

      protected void deliver1(ServerSession sender, ServerMessage.Mutable mutable, Promise<Boolean> promise)
    • extendOutgoing Link icon

      protected void extendOutgoing(ServerSession sender, ServerMessage.Mutable message, Promise<ServerMessage.Mutable> promise)
    • handshake Link icon

      public boolean handshake(ServerMessage.Mutable message)
    • connected Link icon

      public boolean connected()
    • disconnect Link icon

      public void disconnect()
      Description copied from interface: Session
      Disconnects this session, ending the link between the client and the server peers.
      Specified by:
      disconnect in interface Session
      See Also:
    • 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:
    • 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:
    • getLocalSession Link icon

      public LocalSession getLocalSession()
      Specified by:
      getLocalSession in interface ServerSession
      Returns:
      the LocalSession associated with this session, or null if this is a session representing a remote client.
    • isLocalSession Link icon

      public boolean isLocalSession()
      Specified by:
      isLocalSession in interface ServerSession
      Returns:
      whether this is a session for a local client on server-side
    • addListener Link icon

      public void addListener(ServerSession.ServerSessionListener listener)
      Description copied from interface: ServerSession

      Adds the given listener to this session.

      Specified by:
      addListener in interface ServerSession
      Parameters:
      listener - the listener to add
      See Also:
    • getId Link icon

      public String getId()
      Description copied from interface: Session

      The clientId of the session.

      This would more correctly be called a "sessionId", but for backwards compatibility with the Bayeux protocol, it is a field called "clientId" that identifies a session.

      Specified by:
      getId in interface Session
      Returns:
      the id of this session
    • getLock Link icon

      public Lock getLock()
    • getQueue Link icon

      public Queue<ServerMessage> getQueue()
    • hasNonLazyMessages Link icon

      public boolean hasNonLazyMessages()
    • addMessage Link icon

      protected void addMessage(ServerMessage message)
    • takeQueue Link icon

      public List<ServerMessage> takeQueue(List<ServerMessage.Mutable> replies)
    • notifySuspended Link icon

      public void notifySuspended(ServerMessage message, long timeout)
    • notifyResumed Link icon

      public void notifyResumed(ServerMessage message, boolean timeout)
    • removeListener Link icon

      public void removeListener(ServerSession.ServerSessionListener listener)
      Description copied from interface: ServerSession

      Removes the given listener from this session.

      Specified by:
      removeListener in interface ServerSession
      Parameters:
      listener - the listener to remove
      See Also:
    • getListeners Link icon

      public List<ServerSession.ServerSessionListener> getListeners()
    • setScheduler Link icon

      public void setScheduler(AbstractServerTransport.Scheduler newScheduler)
    • shouldSchedule Link icon

      public boolean shouldSchedule()
    • flush Link icon

      public void flush()
    • destroyScheduler Link icon

      public void destroyScheduler()
    • cancelExpiration Link icon

      public void cancelExpiration(boolean metaConnect)
    • scheduleExpiration Link icon

      public void scheduleExpiration(long defaultInterval, long defaultMaxInterval, long metaConnectCycle)
    • getMetaConnectCycle Link icon

      public long getMetaConnectCycle()
    • getMaxInterval Link icon

      public long getMaxInterval()
      Specified by:
      getMaxInterval in interface ServerSession
      Returns:
      the max period of time, in milliseconds, that the server waits before expiring the session when the client does not send messages to the server, or -1 if the default value is used
    • setMaxInterval Link icon

      public void setMaxInterval(long maxInterval)
      Specified by:
      setMaxInterval in interface ServerSession
      Parameters:
      maxInterval - the max period of time, in milliseconds, that the server waits before expiring the session
    • getIntervalNanoTime Link icon

      public long getIntervalNanoTime()
      Returns:
      the nanoTime at which this session is expired
    • 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
    • isHandshook Link icon

      public boolean isHandshook()
      Description copied from interface: Session

      A handshook session is a session where the handshake has successfully completed

      Specified by:
      isHandshook in interface Session
      Returns:
      whether the session is handshook
    • isConnected Link icon

      public boolean isConnected()
      Description copied from interface: Session

      A connected session is a session where the link between the client and the server has been established.

      Specified by:
      isConnected in interface Session
      Returns:
      whether the session is connected
      See Also:
    • isDisconnected Link icon

      public boolean isDisconnected()
    • isTerminated Link icon

      public boolean isTerminated()
    • extendIncoming Link icon

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

      public void reAdvise()
    • takeAdvice Link icon

      public Map<String,Object> takeAdvice(ServerTransport transport)
    • getServerTransport Link icon

      public ServerTransport getServerTransport()
      Specified by:
      getServerTransport in interface ServerSession
      Returns:
      the ServerTransport associated with this session
    • setServerTransport Link icon

      public void setServerTransport(ServerTransport transport)
    • updateServerEndPoint Link icon

      public boolean updateServerEndPoint(Object newEndPoint)
    • getTimeout Link icon

      public long getTimeout()
      Specified by:
      getTimeout in interface ServerSession
      Returns:
      the period of time, in milliseconds, that the server will hold connect messages for this session or -1 if the default value is used
      See Also:
    • getInterval Link icon

      public long getInterval()
      Specified by:
      getInterval in interface ServerSession
      Returns:
      the period of time, in milliseconds, that the client associated with this session will wait before issuing a connect message, or -1 if the default value is used
      See Also:
    • setTimeout Link icon

      public void setTimeout(long timeoutMS)
      Specified by:
      setTimeout in interface ServerSession
      Parameters:
      timeoutMS - the period of time, in milliseconds, that the server will hold connect messages for this session
    • setInterval Link icon

      public void setInterval(long intervalMS)
      Specified by:
      setInterval in interface ServerSession
      Parameters:
      intervalMS - the period of time, in milliseconds, that the client associated with this session will wait before issuing a connect message
    • isBroadcastToPublisher Link icon

      public boolean isBroadcastToPublisher()
      Specified by:
      isBroadcastToPublisher in interface ServerSession
      Returns:
      whether this session sends messages back to itself
    • setBroadcastToPublisher Link icon

      public void setBroadcastToPublisher(boolean value)
      Description copied from interface: ServerSession
      Sets whether this session sends messages back to itself.
      Specified by:
      setBroadcastToPublisher in interface ServerSession
      Parameters:
      value - whether this session sends messages back to itself
    • removed Link icon

      protected boolean removed(ServerMessage message, boolean timeout)
      Parameters:
      message - the message that caused the removal, or null
      timeout - whether the session has been removed due a timeout
      Returns:
      True if the session was connected.
    • setMetaConnectDeliveryOnly Link icon

      public void setMetaConnectDeliveryOnly(boolean meta)
      Description copied from interface: ServerSession

      Sets whether delivery of messages only happen via the /meta/connect channel.

      Transports that use more than one connection to the server (e.g. HTTP transports) may deliver some messages in one connection and some in another connection, causing messages to arrive out-of-order.

      Forcing messages to be delivered only via the /meta/connect channel guarantees server-to-client message ordering.

      Specified by:
      setMetaConnectDeliveryOnly in interface ServerSession
      Parameters:
      meta - whether delivery of messages only happens via the /meta/connect channel
    • isMetaConnectDeliveryOnly Link icon

      public boolean isMetaConnectDeliveryOnly()
      Specified by:
      isMetaConnectDeliveryOnly in interface ServerSession
      Returns:
      whether delivery of messages only happens via the /meta/connect channel
    • isAllowMessageDeliveryDuringHandshake Link icon

      public boolean isAllowMessageDeliveryDuringHandshake()
    • setAllowMessageDeliveryDuringHandshake Link icon

      public void setAllowMessageDeliveryDuringHandshake(boolean allow)
    • subscribe Link icon

      protected boolean subscribe(ServerChannelImpl channel)
    • unsubscribedFrom Link icon

      protected void unsubscribedFrom(ServerChannelImpl channel)
    • calculateTimeout Link icon

      public long calculateTimeout(long defaultTimeout)
    • calculateInterval Link icon

      public long calculateInterval(long defaultInterval)
    • updateTransientTimeout Link icon

      public void updateTransientTimeout(long timeout)
      Updates the transient timeout with the given value. The transient timeout is the one sent by the client, that should temporarily override the session/transport timeout, for example when the client sends {timeout:0}
      Parameters:
      timeout - the value to update the timeout to
      See Also:
    • updateTransientInterval Link icon

      public void updateTransientInterval(long interval)
      Updates the transient interval with the given value. The transient interval is the one sent by the client, that should temporarily override the session/transport interval, for example when the client sends {timeout:0,interval:60000}
      Parameters:
      interval - the value to update the interval to
      See Also:
    • 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
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object