Class WebSocketCoreSession

    • Method Detail

      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
      • setClassLoader

        public void setClassLoader​(java.lang.ClassLoader classLoader)
      • handle

        protected void handle​(java.lang.Runnable runnable)
        Can be overridden to scope into the correct classloader before calling application code.
        Parameters:
        runnable - the runnable to execute.
      • isDemanding

        public boolean isDemanding()
        Returns:
        True if the sessions handling is demanding.
      • getNegotiatedSubProtocol

        public java.lang.String getNegotiatedSubProtocol()
        Description copied from interface: CoreSession
        The negotiated WebSocket Sub-Protocol for this session.
        Specified by:
        getNegotiatedSubProtocol in interface CoreSession
        Returns:
        the negotiated WebSocket Sub-Protocol for this session.
      • getIdleTimeout

        public java.time.Duration getIdleTimeout()
        Description copied from interface: Configuration
        Get the Idle Timeout
        Specified by:
        getIdleTimeout in interface Configuration
        Returns:
        the idle timeout
      • setIdleTimeout

        public void setIdleTimeout​(java.time.Duration timeout)
        Description copied from interface: Configuration
        Set the Idle Timeout.
        Specified by:
        setIdleTimeout in interface Configuration
        Parameters:
        timeout - the timeout duration (timeout <= 0 implies an infinite timeout)
      • getWriteTimeout

        public java.time.Duration getWriteTimeout()
        Description copied from interface: Configuration
        Get the Write Timeout
        Specified by:
        getWriteTimeout in interface Configuration
        Returns:
        the write timeout
      • setWriteTimeout

        public void setWriteTimeout​(java.time.Duration timeout)
        Description copied from interface: Configuration
        Set the Write Timeout.
        Specified by:
        setWriteTimeout in interface Configuration
        Parameters:
        timeout - the timeout duration (timeout <= 0 implies an infinite timeout)
      • getLocalAddress

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

        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 CoreSession
        Returns:
        the SocketAddress for the local connection, or null if not supported by Session
      • getRemoteAddress

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

        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 CoreSession
        Returns:
        the SocketAddress for the remote connection, or null if not supported by Session
      • isInputOpen

        public boolean isInputOpen()
        Specified by:
        isInputOpen in interface CoreSession
        Returns:
        True if the websocket is open inbound
      • isOutputOpen

        public boolean isOutputOpen()
        Specified by:
        isOutputOpen in interface CoreSession
        Returns:
        True if the websocket is open outbound
      • isClosed

        public boolean isClosed()
      • setWebSocketConnection

        public void setWebSocketConnection​(WebSocketConnection connection)
      • close

        public void close​(Callback callback)
        Send Close Frame with no payload.
        Specified by:
        close in interface CoreSession
        Parameters:
        callback - the callback on successful send of close frame
      • close

        public void close​(int statusCode,
                          java.lang.String reason,
                          Callback callback)
        Send Close Frame with specified Status Code and optional Reason
        Specified by:
        close in interface CoreSession
        Parameters:
        statusCode - a valid WebSocket status code
        reason - an optional reason phrase
        callback - the callback on successful send of close frame
      • onEof

        public void onEof()
      • closeConnection

        public void closeConnection​(CloseStatus closeStatus,
                                    Callback callback)
      • processConnectionError

        public void processConnectionError​(java.lang.Throwable cause,
                                           Callback callback)
        Process an Error that originated from the connection. For protocol causes, send and abnormal close frame otherwise just close the connection.
        Parameters:
        cause - the cause
        callback - the callback on completion of error handling
      • processHandlerError

        public void processHandlerError​(java.lang.Throwable cause,
                                        Callback callback)
        Process an Error that originated from the handler. Send an abnormal close frame to ensure connection is closed.
        Parameters:
        cause - the cause
        callback - the callback on completion of error handling
      • onOpen

        public void onOpen()
        Open/Activate the session.
      • isRsv1Used

        public boolean isRsv1Used()
        Specified by:
        isRsv1Used in interface CoreSession
        Returns:
        true if an extension has been negotiated which uses the RSV1 bit.
      • isRsv2Used

        public boolean isRsv2Used()
        Specified by:
        isRsv2Used in interface CoreSession
        Returns:
        true if an extension has been negotiated which uses the RSV2 bit.
      • isRsv3Used

        public boolean isRsv3Used()
        Specified by:
        isRsv3Used in interface CoreSession
        Returns:
        true if an extension has been negotiated which uses the RSV3 bit.
      • getExecutor

        public java.util.concurrent.Executor getExecutor()
      • onFrame

        public void onFrame​(Frame frame,
                            Callback callback)
        Description copied from interface: IncomingFrames
        Process the incoming frame.

        Note: if you need to hang onto any information from the frame, be sure to copy it, as the information contained in the Frame will be released and/or reused by the implementation.

        Specified by:
        onFrame in interface IncomingFrames
        Parameters:
        frame - the frame to process
        callback - the read completion
      • sendFrame

        public void sendFrame​(Frame frame,
                              Callback callback,
                              boolean batch)
        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:
        sendFrame in interface OutgoingFrames
        Parameters:
        frame - the frame to eventually write to the network layer.
        callback - the callback to notify when the frame is written.
        batch - the batch mode requested by the sender.
      • flush

        public void flush​(Callback callback)
        Description copied from interface: CoreSession
        If using BatchMode.ON or BatchMode.AUTO, trigger a flush of enqueued / batched frames.
        Specified by:
        flush in interface CoreSession
        Parameters:
        callback - the callback to track close frame sent (or failed)
      • abort

        public void abort()
        Description copied from interface: CoreSession
        Issue a harsh abort of the underlying connection.

        This will terminate the connection, without sending a websocket close frame. No WebSocket Protocol close handshake will be performed.

        Once called, any read/write activity on the websocket from this point will be indeterminate. This can result in the FrameHandler.onError(Throwable, Callback) event being called indicating any issue that arises.

        Once the underlying connection has been determined to be closed, the FrameHandler.onClosed(CloseStatus, Callback) event will be called.

        Specified by:
        abort in interface CoreSession
      • getMaxOutgoingFrames

        public int getMaxOutgoingFrames()
        Description copied from interface: Configuration
        Get the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with a WritePendingException but the connection is not failed and will remain open.
        Specified by:
        getMaxOutgoingFrames in interface Configuration
        Returns:
        the max number of frames.
      • setMaxOutgoingFrames

        public void setMaxOutgoingFrames​(int maxOutgoingFrames)
        Description copied from interface: Configuration
        Set the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with a WritePendingException but the connection is not failed and will remain open.
        Specified by:
        setMaxOutgoingFrames in interface Configuration
        Parameters:
        maxOutgoingFrames - the max number of frames.
      • dump

        public java.lang.String dump()
        Specified by:
        dump in interface Dumpable
      • 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
      • getNegotiatedExtensions

        public java.util.List<ExtensionConfig> getNegotiatedExtensions()
        Description copied from interface: CoreSession
        The negotiated WebSocket Extension Configurations for this session.
        Specified by:
        getNegotiatedExtensions in interface CoreSession
        Returns:
        the list of Negotiated Extension Configurations for this session.
      • getParameterMap

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getParameterMap()
        Description copied from interface: CoreSession
        The parameter map (from URI Query) for the active session.
        Specified by:
        getParameterMap in interface CoreSession
        Returns:
        the immutable map of parameters
      • getProtocolVersion

        public java.lang.String getProtocolVersion()
        Description copied from interface: CoreSession
        The active Sec-WebSocket-Version (protocol version) in use.
        Specified by:
        getProtocolVersion in interface CoreSession
        Returns:
        the protocol version in use.
      • getRequestURI

        public java.net.URI getRequestURI()
        Description copied from interface: CoreSession
        The active connection's Request URI. This is the URI of the upgrade request and is typically http: or https: rather than the ws: or wss: scheme.
        Specified by:
        getRequestURI in interface CoreSession
        Returns:
        the absolute URI (including Query string)
      • isSecure

        public boolean isSecure()
        Description copied from interface: CoreSession
        The active connection's Secure status indicator.
        Specified by:
        isSecure in interface CoreSession
        Returns:
        true if connection is secure (similar in role to HttpServletRequest.isSecure())
      • toString

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