Class WebSocketSession

    • Field Summary

      • Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

        KEY
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Request a close of the current conversation with a normal status code and no reason phrase.
      void close​(int statusCode, java.lang.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 disconnect()
      Issue a harsh disconnect of the underlying connection.
      void dump​(java.lang.Appendable out, java.lang.String indent)
      Dump this object (and children) into an Appendable using the provided indent after any new lines.
      java.lang.String dumpSelf()
      The description of this/self found in the dump.
      WebSocketBehavior getBehavior()  
      CoreSession getCoreSession()  
      java.time.Duration getIdleTimeout()
      The duration that a websocket may be idle before being closed by the implementation
      int getInputBufferSize()
      The input (read from network layer) buffer size.
      java.net.SocketAddress getLocalAddress()
      The Local Socket Address for the active Session
      long getMaxBinaryMessageSize()
      Get the maximum size of a binary message during parsing.
      long getMaxFrameSize()
      The maximum payload size of any WebSocket Frame which can be received.
      long getMaxTextMessageSize()
      Get the maximum size of a text message during parsing.
      int getOutputBufferSize()
      The output (write to network layer) buffer size.
      java.lang.String getProtocolVersion()
      Returns the version of the websocket protocol currently being used.
      JettyWebSocketRemoteEndpoint getRemote()
      Return a reference to the RemoteEndpoint object representing the other end of this conversation.
      java.net.SocketAddress getRemoteAddress()
      The Remote Socket Address for the active Session
      UpgradeRequest getUpgradeRequest()
      Get the UpgradeRequest used to create this session
      UpgradeResponse getUpgradeResponse()
      Get the UpgradeResponse used to create this session
      boolean isAutoFragment()
      If true, frames are automatically fragmented to respect the maximum frame size.
      boolean isOpen()
      Return true if and only if the underlying socket is open.
      boolean isSecure()
      Return true if and only if the underlying socket is using a secure transport.
      void resume()
      Resume a previously suspended connection.
      void setAutoFragment​(boolean autoFragment)
      If set to true, frames are automatically fragmented to respect the maximum frame size.
      void setIdleTimeout​(java.time.Duration duration)
      The duration that a websocket may be idle before being closed by the implementation
      void setInputBufferSize​(int size)
      The input (read from network layer) buffer size.
      void setMaxBinaryMessageSize​(long size)
      The maximum size of a binary message during parsing/generating.
      void setMaxFrameSize​(long maxFrameSize)
      The maximum payload size of any WebSocket Frame which can be received.
      void setMaxTextMessageSize​(long size)
      The maximum size of a text message during parsing/generating.
      void setOutputBufferSize​(int size)
      The output (write to network layer) buffer size.
      SuspendToken suspend()
      Suspend the delivery of incoming WebSocket frames.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

        dump
      • Methods inherited from interface org.eclipse.jetty.websocket.api.Session

        getPolicy
    • Method Detail

      • 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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface Session
        See Also:
        Session.close(CloseStatus), Session.close(int, String), Session.disconnect()
      • 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:
        Session.close(), Session.close(int, String), Session.disconnect()
      • close

        public void close​(int statusCode,
                          java.lang.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:
        StatusCode, Session.close(), Session.close(CloseStatus), Session.disconnect()
      • getIdleTimeout

        public java.time.Duration getIdleTimeout()
        Description copied from interface: WebSocketPolicy
        The duration that a websocket may be idle before being closed by the implementation
        Specified by:
        getIdleTimeout in interface WebSocketPolicy
        Returns:
        the timeout duration
      • getInputBufferSize

        public int getInputBufferSize()
        Description copied from interface: WebSocketPolicy
        The input (read from network layer) buffer size.

        This is the raw read operation buffer size, before the parsing of the websocket frames.

        Specified by:
        getInputBufferSize in interface WebSocketPolicy
        Returns:
        the raw network buffer input size.
      • getOutputBufferSize

        public int getOutputBufferSize()
        Description copied from interface: WebSocketPolicy
        The output (write to network layer) buffer size.

        This is the raw write operation buffer size and has no relationship to the websocket frame.

        Specified by:
        getOutputBufferSize in interface WebSocketPolicy
        Returns:
        the raw network buffer output size.
      • getMaxBinaryMessageSize

        public long getMaxBinaryMessageSize()
        Description copied from interface: WebSocketPolicy
        Get the maximum size of a binary message during parsing.

        This is a memory conservation option, memory over this limit will not be allocated by Jetty for handling binary messages. This applies to individual frames, whole message handling, and partial message handling.

        Binary messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        getMaxBinaryMessageSize in interface WebSocketPolicy
        Returns:
        the maximum size of a binary message
      • getMaxTextMessageSize

        public long getMaxTextMessageSize()
        Description copied from interface: WebSocketPolicy
        Get the maximum size of a text message during parsing.

        This is a memory conservation option, memory over this limit will not be allocated by Jetty for handling text messages. This applies to individual frames, whole message handling, and partial message handling.

        Text messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        getMaxTextMessageSize in interface WebSocketPolicy
        Returns:
        the maximum size of a text message.
      • getMaxFrameSize

        public long getMaxFrameSize()
        Description copied from interface: WebSocketPolicy
        The maximum payload size of any WebSocket Frame which can be received.
        Specified by:
        getMaxFrameSize in interface WebSocketPolicy
        Returns:
        the maximum size of a WebSocket Frame.
      • isAutoFragment

        public boolean isAutoFragment()
        Description copied from interface: WebSocketPolicy
        If true, frames are automatically fragmented to respect the maximum frame size.
        Specified by:
        isAutoFragment in interface WebSocketPolicy
        Returns:
        whether to automatically fragment incoming WebSocket Frames.
      • setIdleTimeout

        public void setIdleTimeout​(java.time.Duration duration)
        Description copied from interface: WebSocketPolicy
        The duration that a websocket may be idle before being closed by the implementation
        Specified by:
        setIdleTimeout in interface WebSocketPolicy
        Parameters:
        duration - the timeout duration (may not be null or negative)
      • setInputBufferSize

        public void setInputBufferSize​(int size)
        Description copied from interface: WebSocketPolicy
        The input (read from network layer) buffer size.
        Specified by:
        setInputBufferSize in interface WebSocketPolicy
        Parameters:
        size - the size in bytes
      • setOutputBufferSize

        public void setOutputBufferSize​(int size)
        Description copied from interface: WebSocketPolicy
        The output (write to network layer) buffer size.
        Specified by:
        setOutputBufferSize in interface WebSocketPolicy
        Parameters:
        size - the size in bytes
      • setMaxBinaryMessageSize

        public void setMaxBinaryMessageSize​(long size)
        Description copied from interface: WebSocketPolicy
        The maximum size of a binary message during parsing/generating.

        Binary messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        setMaxBinaryMessageSize in interface WebSocketPolicy
        Parameters:
        size - the maximum allowed size of a binary message.
      • setMaxTextMessageSize

        public void setMaxTextMessageSize​(long size)
        Description copied from interface: WebSocketPolicy
        The maximum size of a text message during parsing/generating.

        Text messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        setMaxTextMessageSize in interface WebSocketPolicy
        Parameters:
        size - the maximum allowed size of a text message.
      • setMaxFrameSize

        public void setMaxFrameSize​(long maxFrameSize)
        Description copied from interface: WebSocketPolicy
        The maximum payload size of any WebSocket Frame which can be received.

        WebSocket Frames over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        setMaxFrameSize in interface WebSocketPolicy
        Parameters:
        maxFrameSize - the maximum allowed size of a WebSocket Frame.
      • setAutoFragment

        public void setAutoFragment​(boolean autoFragment)
        Description copied from interface: WebSocketPolicy
        If set to true, frames are automatically fragmented to respect the maximum frame size.
        Specified by:
        setAutoFragment in interface WebSocketPolicy
        Parameters:
        autoFragment - whether to automatically fragment incoming WebSocket Frames.
      • getProtocolVersion

        public java.lang.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 JettyWebSocketRemoteEndpoint 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
      • 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
      • getLocalAddress

        public java.net.SocketAddress getLocalAddress()
        Description copied from interface: Session
        The Local Socket Address for the active Session

        Do not assume that this will return a InetSocketAddress in all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supporting InetSocketAddress

        Specified by:
        getLocalAddress in interface Session
        Returns:
        the SocketAddress for the local connection, or null if not supported by Session
      • getRemoteAddress

        public java.net.SocketAddress getRemoteAddress()
        Description copied from interface: Session
        The Remote Socket Address for the active Session

        Do not assume that this will return a InetSocketAddress in all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supporting InetSocketAddress

        Specified by:
        getRemoteAddress in interface Session
        Returns:
        the SocketAddress for the remote connection, or null if not supported by Session
      • 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
      • suspend

        public SuspendToken suspend()
        Description copied from interface: Session
        Suspend the delivery of incoming WebSocket frames.

        If this is called from inside the scope of the message handler the suspend takes effect immediately. If suspend is called outside the scope of the message handler then the call may take effect after 1 more frame is delivered.

        Specified by:
        suspend in interface Session
        Returns:
        the suspend token suitable for resuming the reading of data on the connection.
      • resume

        public void resume()
        Description copied from interface: SuspendToken
        Resume a previously suspended connection.
        Specified by:
        resume in interface SuspendToken
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • dumpSelf

        public java.lang.String dumpSelf()
        Description copied from interface: Dumpable
        The description of this/self found in the dump. Allows for alternative representation of Object other then .toString() where the long form output of toString() is represented in a cleaner way within the dump infrastructure.
        Specified by:
        dumpSelf in interface Dumpable
        Returns:
        the representation of self
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object