Interface Session

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
JsrSession, WebSocketSession

public interface Session extends Closeable
Session represents an active link of communications with a Remote WebSocket Endpoint.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Request a close of the current conversation with a normal status code and no reason phrase.
    void
    close(int statusCode, String reason)
    Send a websocket Close frame, with status code.
    void
    close(CloseStatus closeStatus)
    Request Close the current conversation, giving a reason for the closure.
    void
    Issue a harsh disconnect of the underlying connection.
    long
    Return the number of milliseconds before this conversation will be closed by the container if it is inactive, ie no messages are either sent or received in that time.
    Get the address of the local side.
    Access the (now read-only) WebSocketPolicy in use for this connection.
    Returns the version of the websocket protocol currently being used.
    Return a reference to the RemoteEndpoint object representing the other end of this conversation.
    Get the address of the remote side.
    Get the UpgradeRequest used to create this session
    Get the UpgradeResponse used to create this session
    boolean
    Return true if and only if the underlying socket is open.
    boolean
    Return true if and only if the underlying socket is using a secure transport.
    void
    setIdleTimeout(long ms)
    Set the number of milliseconds before this conversation will be closed by the container if it is inactive, ie no messages are either sent or received.
    Suspend the incoming read events on the connection.
  • Method Details

    • close

      void close()
      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
      See Also:
    • close

      void close(CloseStatus closeStatus)
      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.

      Parameters:
      closeStatus - the reason for the closure
      See Also:
    • close

      void close(int statusCode, String reason)
      Send a websocket Close frame, with status code.

      This will enqueue a graceful close to the remote endpoint.

      Parameters:
      statusCode - the status code
      reason - the (optional) reason. (can be null for no reason)
      See Also:
    • disconnect

      void disconnect() throws IOException
      Issue a harsh disconnect of the underlying connection.

      This will terminate the connection, without sending a websocket close frame.

      Once called, any read/write activity on the websocket from this point will be indeterminate.

      Once the underlying connection has been determined to be closed, the various onClose() events (either WebSocketConnectionListener.onWebSocketClose(int, String) or OnWebSocketClose) will be called on your websocket.

      Throws:
      IOException - if unable to disconnect
      See Also:
    • getIdleTimeout

      long getIdleTimeout()
      Return the number of milliseconds before this conversation will be closed by the container if it is inactive, ie no messages are either sent or received in that time.
      Returns:
      the timeout in milliseconds.
    • getLocalAddress

      InetSocketAddress getLocalAddress()
      Get the address of the local side.
      Returns:
      the local side address
    • getPolicy

      WebSocketPolicy getPolicy()
      Access the (now read-only) WebSocketPolicy in use for this connection.
      Returns:
      the policy in use
    • getProtocolVersion

      String getProtocolVersion()
      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".
      Returns:
      the protocol version
    • getRemote

      RemoteEndpoint getRemote()
      Return a reference to the RemoteEndpoint object representing the other end of this conversation.
      Returns:
      the remote endpoint
    • getRemoteAddress

      InetSocketAddress getRemoteAddress()
      Get the address of the remote side.
      Returns:
      the remote side address
    • getUpgradeRequest

      UpgradeRequest getUpgradeRequest()
      Get the UpgradeRequest used to create this session
      Returns:
      the UpgradeRequest used to create this session
    • getUpgradeResponse

      UpgradeResponse getUpgradeResponse()
      Get the UpgradeResponse used to create this session
      Returns:
      the UpgradeResponse used to create this session
    • isOpen

      boolean isOpen()
      Return true if and only if the underlying socket is open.
      Returns:
      whether the session is open
    • isSecure

      boolean isSecure()
      Return true if and only if the underlying socket is using a secure transport.
      Returns:
      whether its using a secure transport
    • setIdleTimeout

      void setIdleTimeout(long ms)
      Set the number of milliseconds before this conversation will be closed by the container if it is inactive, ie no messages are either sent or received.
      Parameters:
      ms - the number of milliseconds.
    • suspend

      SuspendToken suspend()
      Suspend the incoming read events on the connection.
      Returns:
      the suspend token suitable for resuming the reading of data on the connection.