Class WebSocketSession

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.websocket.common.WebSocketSession
All Implemented Interfaces:
Closeable, AutoCloseable, org.eclipse.jetty.io.Connection.Listener, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, IncomingFrames, OutgoingFrames, Session, RemoteEndpointFactory, WebSocketSessionScope
Direct Known Subclasses:
JsrSession

@ManagedObject("A Jetty WebSocket Session") public class WebSocketSession extends org.eclipse.jetty.util.component.ContainerLifeCycle implements Session, RemoteEndpointFactory, WebSocketSessionScope, IncomingFrames, OutgoingFrames, org.eclipse.jetty.io.Connection.Listener
  • Field Details

  • Constructor Details

  • Method Details

    • close

      public void close(Throwable cause)
      Close the active session based on the throwable
      Parameters:
      cause - the cause for closing the connection
    • close

      public void close()
      Description copied from interface: Session
      Request a close of the current conversation with a normal status code and no reason phrase.

      This will enqueue a graceful close to the remote endpoint.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Session
      See Also:
    • close

      public void close(CloseStatus closeStatus)
      Description copied from interface: Session
      Request Close the current conversation, giving a reason for the closure. Note the websocket spec defines the acceptable uses of status codes and reason phrases.

      This will enqueue a graceful close to the remote endpoint.

      Specified by:
      close in interface Session
      Parameters:
      closeStatus - the reason for the closure
      See Also:
    • close

      public void close(int statusCode, String reason)
      Description copied from interface: Session
      Send a websocket Close frame, with status code.

      This will enqueue a graceful close to the remote endpoint.

      Specified by:
      close in interface Session
      Parameters:
      statusCode - the status code
      reason - the (optional) reason. (can be null for no reason)
      See Also:
    • close

      private void close(CloseInfo closeInfo, org.eclipse.jetty.util.Callback callback)
      Close Primary Entry Point.
      Parameters:
      closeInfo - the close details
    • disconnect

      public void disconnect()
      Harsh disconnect
      Specified by:
      disconnect in interface Session
      See Also:
    • dispatch

      public void dispatch(Runnable runnable)
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • dumpSelf

      public String dumpSelf()
      Specified by:
      dumpSelf in interface org.eclipse.jetty.util.component.Dumpable
    • getBufferPool

      public org.eclipse.jetty.io.ByteBufferPool getBufferPool()
    • getClassLoader

      public ClassLoader getClassLoader()
    • getConnection

      public LogicalConnection getConnection()
    • getContainerScope

      public WebSocketContainerScope getContainerScope()
      Description copied from interface: WebSocketSessionScope
      The parent WebSocketContainerScope for this session scope.
      Specified by:
      getContainerScope in interface WebSocketSessionScope
      Returns:
      the websocket container scope
    • getExtensionFactory

      public ExtensionFactory getExtensionFactory()
    • getIdleTimeout

      public long getIdleTimeout()
      The idle timeout in milliseconds
      Specified by:
      getIdleTimeout in interface Session
      Returns:
      the timeout in milliseconds.
    • getIncomingHandler

      @ManagedAttribute(readonly=true) public IncomingFrames getIncomingHandler()
    • getLocalAddress

      public InetSocketAddress getLocalAddress()
      Description copied from interface: Session
      Get the address of the local side.
      Specified by:
      getLocalAddress in interface Session
      Returns:
      the local side address
    • getOutgoingHandler

      @ManagedAttribute(readonly=true) public OutgoingFrames getOutgoingHandler()
    • getPolicy

      public WebSocketPolicy getPolicy()
      Description copied from interface: Session
      Access the (now read-only) WebSocketPolicy in use for this connection.
      Specified by:
      getPolicy in interface Session
      Returns:
      the policy in use
    • getProtocolVersion

      public String getProtocolVersion()
      Description copied from interface: Session
      Returns the version of the websocket protocol currently being used. This is taken as the value of the Sec-WebSocket-Version header used in the opening handshake. i.e. "13".
      Specified by:
      getProtocolVersion in interface Session
      Returns:
      the protocol version
    • getRemote

      public RemoteEndpoint getRemote()
      Description copied from interface: Session
      Return a reference to the RemoteEndpoint object representing the other end of this conversation.
      Specified by:
      getRemote in interface Session
      Returns:
      the remote endpoint
    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Description copied from interface: Session
      Get the address of the remote side.
      Specified by:
      getRemoteAddress in interface Session
      Returns:
      the remote side address
    • getRequestURI

      public URI getRequestURI()
    • getUpgradeRequest

      public UpgradeRequest getUpgradeRequest()
      Description copied from interface: Session
      Get the UpgradeRequest used to create this session
      Specified by:
      getUpgradeRequest in interface Session
      Returns:
      the UpgradeRequest used to create this session
    • getUpgradeResponse

      public UpgradeResponse getUpgradeResponse()
      Description copied from interface: Session
      Get the UpgradeResponse used to create this session
      Specified by:
      getUpgradeResponse in interface Session
      Returns:
      the UpgradeResponse used to create this session
    • getWebSocketSession

      public WebSocketSession getWebSocketSession()
      Description copied from interface: WebSocketSessionScope
      Active WebSocketSession associated with this scope.
      Specified by:
      getWebSocketSession in interface WebSocketSessionScope
      Returns:
      the websocket session
    • incomingFrame

      public void incomingFrame(Frame frame)
      Incoming Raw Frames from Parser
      Specified by:
      incomingFrame in interface IncomingFrames
      Parameters:
      frame - the frame to process
    • outgoingFrame

      public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)
      Description copied from interface: OutgoingFrames
      A frame, and optional callback, intended for the network layer.

      Note: the frame can undergo many transformations in the various layers and extensions present in the implementation.

      If you are implementing a mutation, you are obliged to handle the incoming WriteCallback appropriately.

      Specified by:
      outgoingFrame in interface OutgoingFrames
      Parameters:
      frame - the frame to eventually write to the network layer.
      callback - the callback to notify when the frame is written.
      batchMode - the batch mode requested by the sender.
    • isOpen

      public boolean isOpen()
      Description copied from interface: Session
      Return true if and only if the underlying socket is open.
      Specified by:
      isOpen in interface Session
      Returns:
      whether the session is open
    • isSecure

      public boolean isSecure()
      Description copied from interface: Session
      Return true if and only if the underlying socket is using a secure transport.
      Specified by:
      isSecure in interface Session
      Returns:
      whether its using a secure transport
    • callApplicationOnClose

      public void callApplicationOnClose(CloseInfo closeInfo)
    • callApplicationOnError

      public void callApplicationOnError(Throwable cause)
    • onClosed

      public void onClosed(org.eclipse.jetty.io.Connection connection)
      Jetty Connection onSessionClosed event
      Specified by:
      onClosed in interface org.eclipse.jetty.io.Connection.Listener
      Parameters:
      connection - the connection that was closed
    • onOpened

      public void onOpened(org.eclipse.jetty.io.Connection connection)
      Jetty Connection onOpen event
      Specified by:
      onOpened in interface org.eclipse.jetty.io.Connection.Listener
      Parameters:
      connection - the connection that was opened
    • newRemoteEndpoint

      public WebSocketRemoteEndpoint newRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoingFrames, BatchMode batchMode)
      Specified by:
      newRemoteEndpoint in interface RemoteEndpointFactory
    • open

      public void open()
      Open/Activate the session
    • setExtensionFactory

      public void setExtensionFactory(ExtensionFactory extensionFactory)
    • setFuture

      public void setFuture(CompletableFuture<Session> fut)
    • setIdleTimeout

      public void setIdleTimeout(long ms)
      Set the timeout in milliseconds
      Specified by:
      setIdleTimeout in interface Session
      Parameters:
      ms - the number of milliseconds.
    • setOutgoingHandler

      public void setOutgoingHandler(OutgoingFrames outgoing)
    • setPolicy

      @Deprecated public void setPolicy(WebSocketPolicy policy)
      Deprecated.
    • setUpgradeRequest

      public void setUpgradeRequest(UpgradeRequest request)
    • setUpgradeResponse

      public void setUpgradeResponse(UpgradeResponse response)
    • suspend

      public SuspendToken suspend()
      Description copied from interface: Session
      Suspend the incoming read events on the connection.
      Specified by:
      suspend in interface Session
      Returns:
      the suspend token suitable for resuming the reading of data on the connection.
    • getBatchMode

      public BatchMode getBatchMode()
      Returns:
      the default (initial) value for the batching mode.
    • notifySessionListeners

      private void notifySessionListeners(WebSocketContainerScope scope, Consumer<WebSocketSessionListener> consumer)
    • toString

      public String toString()
      Overrides:
      toString in class org.eclipse.jetty.util.component.AbstractLifeCycle