Class WsRemoteEndpointImplBase

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.Semaphore messagePartInProgress
      Semaphore to ensure only one message part is being processed at a time.
      protected static SendResult SENDRESULT_OK  
      protected static StringManager sm
      String manager for this class.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean acquireMessagePartInProgressSemaphore​(byte opCode, long timeoutExpiry)
      Acquire the semaphore that allows a message part to be written.
      void close()
      Closes all encoders associated with this endpoint.
      protected abstract void doClose()
      Performs the actual close operation on the underlying connection.
      protected abstract void doWrite​(SendHandler handler, long blockingWriteTimeoutExpiry, java.nio.ByteBuffer... data)
      Writes data to the underlying connection.
      void flushBatch()
      Flush any currently batched messages to the remote endpoint.
      boolean getBatchingAllowed()
      Obtains the current batching status of the endpoint.
      protected abstract java.util.concurrent.locks.Lock getLock()
      Returns the lock used for thread-safe operations.
      java.io.OutputStream getSendStream()
      Returns an OutputStream for sending binary data.
      long getSendTimeout()
      Returns the send timeout in milliseconds.
      java.io.Writer getSendWriter()
      Returns a Writer for sending text data.
      protected abstract boolean isMasked()
      Checks if frames should be masked.
      void sendBytes​(java.nio.ByteBuffer data)
      Sends binary data to the remote endpoint.
      void sendBytesByCompletion​(java.nio.ByteBuffer data, SendHandler handler)
      Sends binary data asynchronously with a completion handler.
      java.util.concurrent.Future<java.lang.Void> sendBytesByFuture​(java.nio.ByteBuffer data)
      Sends binary data asynchronously, returning a Future for completion tracking.
      void sendObject​(java.lang.Object obj)
      Sends an object to the remote endpoint using the appropriate encoder.
      void sendObjectByCompletion​(java.lang.Object obj, SendHandler completion)
      Sends an object asynchronously with a completion handler.
      java.util.concurrent.Future<java.lang.Void> sendObjectByFuture​(java.lang.Object obj)
      Sends an object asynchronously, returning a Future for completion tracking.
      void sendPartialBytes​(java.nio.ByteBuffer partialByte, boolean last)
      Sends a partial binary message fragment.
      void sendPartialString​(java.lang.String fragment, boolean isLast)
      Sends a partial text message fragment.
      void sendPing​(java.nio.ByteBuffer applicationData)
      Send a ping message blocking until the message has been sent.
      void sendPong​(java.nio.ByteBuffer applicationData)
      Send a pong message blocking until the message has been sent.
      void sendString​(java.lang.String text)
      Sends a text message to the remote endpoint.
      void sendStringByCompletion​(java.lang.String text, SendHandler handler)
      Sends a text message asynchronously with a completion handler.
      java.util.concurrent.Future<java.lang.Void> sendStringByFuture​(java.lang.String text)
      Sends a text message asynchronously, returning a Future for completion tracking.
      void setBatchingAllowed​(boolean batchingAllowed)
      Enable or disable the batching of outgoing messages for this endpoint.
      protected void setEncoders​(EndpointConfig endpointConfig)
      Initializes the encoders for this endpoint from the given endpoint configuration.
      void setSendTimeout​(long timeout)
      Sets the send timeout in milliseconds.
      protected void setSession​(WsSession wsSession)
      Sets the WebSocket session for this endpoint.
      protected void setTransformation​(Transformation transformation)
      Sets the transformation for this endpoint.
      protected void updateStats​(long payloadLength)
      Hook for updating server side statistics.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sm

        protected static final StringManager sm
        String manager for this class.
      • SENDRESULT_OK

        protected static final SendResult SENDRESULT_OK
      • messagePartInProgress

        protected final java.util.concurrent.Semaphore messagePartInProgress
        Semaphore to ensure only one message part is being processed at a time.
    • Constructor Detail

      • WsRemoteEndpointImplBase

        public WsRemoteEndpointImplBase()
        Default constructor.
    • Method Detail

      • setTransformation

        protected void setTransformation​(Transformation transformation)
        Sets the transformation for this endpoint.
        Parameters:
        transformation - the transformation to use
      • getSendTimeout

        public long getSendTimeout()
        Returns the send timeout in milliseconds.
        Returns:
        the send timeout
      • setSendTimeout

        public void setSendTimeout​(long timeout)
        Sets the send timeout in milliseconds.
        Parameters:
        timeout - the send timeout
      • setBatchingAllowed

        public void setBatchingAllowed​(boolean batchingAllowed)
                                throws java.io.IOException
        Description copied from interface: jakarta.websocket.RemoteEndpoint
        Enable or disable the batching of outgoing messages for this endpoint. If batching is disabled when it was previously enabled then this method will block until any currently batched messages have been written.
        Specified by:
        setBatchingAllowed in interface RemoteEndpoint
        Parameters:
        batchingAllowed - New setting
        Throws:
        java.io.IOException - If changing the value resulted in a call to RemoteEndpoint.flushBatch() and that call threw an IOException.
      • flushBatch

        public void flushBatch()
                        throws java.io.IOException
        Description copied from interface: jakarta.websocket.RemoteEndpoint
        Flush any currently batched messages to the remote endpoint. This method will block until the flush completes.
        Specified by:
        flushBatch in interface RemoteEndpoint
        Throws:
        java.io.IOException - If an I/O error occurs while flushing
      • sendBytes

        public void sendBytes​(java.nio.ByteBuffer data)
                       throws java.io.IOException
        Sends binary data to the remote endpoint.
        Parameters:
        data - the binary data
        Throws:
        java.io.IOException - if a send error occurs
      • sendBytesByFuture

        public java.util.concurrent.Future<java.lang.Void> sendBytesByFuture​(java.nio.ByteBuffer data)
        Sends binary data asynchronously, returning a Future for completion tracking.
        Parameters:
        data - the binary data
        Returns:
        a Future that completes when the send is done
      • sendBytesByCompletion

        public void sendBytesByCompletion​(java.nio.ByteBuffer data,
                                          SendHandler handler)
        Sends binary data asynchronously with a completion handler.
        Parameters:
        data - the binary data
        handler - the completion handler
      • sendPartialBytes

        public void sendPartialBytes​(java.nio.ByteBuffer partialByte,
                                     boolean last)
                              throws java.io.IOException
        Sends a partial binary message fragment.
        Parameters:
        partialByte - the binary data fragment
        last - whether this is the last fragment
        Throws:
        java.io.IOException - if a send error occurs
      • sendPing

        public void sendPing​(java.nio.ByteBuffer applicationData)
                      throws java.io.IOException,
                             java.lang.IllegalArgumentException
        Description copied from interface: jakarta.websocket.RemoteEndpoint
        Send a ping message blocking until the message has been sent. Note that if a message is in the process of being sent asynchronously, this method will block until that message and this ping has been sent.
        Specified by:
        sendPing in interface RemoteEndpoint
        Parameters:
        applicationData - The payload for the ping message
        Throws:
        java.io.IOException - If an I/O error occurs while sending the ping
        java.lang.IllegalArgumentException - if the applicationData is too large for a control message (max 125 bytes)
      • sendPong

        public void sendPong​(java.nio.ByteBuffer applicationData)
                      throws java.io.IOException,
                             java.lang.IllegalArgumentException
        Description copied from interface: jakarta.websocket.RemoteEndpoint
        Send a pong message blocking until the message has been sent. Note that if a message is in the process of being sent asynchronously, this method will block until that message and this pong has been sent.
        Specified by:
        sendPong in interface RemoteEndpoint
        Parameters:
        applicationData - The payload for the pong message
        Throws:
        java.io.IOException - If an I/O error occurs while sending the pong
        java.lang.IllegalArgumentException - if the applicationData is too large for a control message (max 125 bytes)
      • sendString

        public void sendString​(java.lang.String text)
                        throws java.io.IOException
        Sends a text message to the remote endpoint.
        Parameters:
        text - the text data
        Throws:
        java.io.IOException - if a send error occurs
      • sendStringByFuture

        public java.util.concurrent.Future<java.lang.Void> sendStringByFuture​(java.lang.String text)
        Sends a text message asynchronously, returning a Future for completion tracking.
        Parameters:
        text - the text data
        Returns:
        a Future that completes when the send is done
      • sendStringByCompletion

        public void sendStringByCompletion​(java.lang.String text,
                                           SendHandler handler)
        Sends a text message asynchronously with a completion handler.
        Parameters:
        text - the text data
        handler - the completion handler
      • sendPartialString

        public void sendPartialString​(java.lang.String fragment,
                                      boolean isLast)
                               throws java.io.IOException
        Sends a partial text message fragment.
        Parameters:
        fragment - the text fragment
        isLast - whether this is the last fragment
        Throws:
        java.io.IOException - if a send error occurs
      • getSendStream

        public java.io.OutputStream getSendStream()
        Returns an OutputStream for sending binary data.
        Returns:
        the output stream
      • getSendWriter

        public java.io.Writer getSendWriter()
        Returns a Writer for sending text data.
        Returns:
        the writer
      • acquireMessagePartInProgressSemaphore

        protected boolean acquireMessagePartInProgressSemaphore​(byte opCode,
                                                                long timeoutExpiry)
                                                         throws java.lang.InterruptedException
        Acquire the semaphore that allows a message part to be written.
        Parameters:
        opCode - The OPCODE for the message to be written
        timeoutExpiry - The time when the attempt to acquire the semaphore should expire
        Returns:
        true if the semaphore is obtained, otherwise false.
        Throws:
        java.lang.InterruptedException - If the wait for the semaphore is interrupted
      • updateStats

        protected void updateStats​(long payloadLength)
        Hook for updating server side statistics. Called on every frame written (including when batching is enabled and the frames are buffered locally until the buffer is full or is flushed).
        Parameters:
        payloadLength - Size of message payload
      • sendObject

        public void sendObject​(java.lang.Object obj)
                        throws java.io.IOException,
                               EncodeException
        Sends an object to the remote endpoint using the appropriate encoder.
        Parameters:
        obj - the object to send
        Throws:
        java.io.IOException - if a send error occurs
        EncodeException - if encoding fails
      • sendObjectByFuture

        public java.util.concurrent.Future<java.lang.Void> sendObjectByFuture​(java.lang.Object obj)
        Sends an object asynchronously, returning a Future for completion tracking.
        Parameters:
        obj - the object to send
        Returns:
        a Future that completes when the send is done
      • sendObjectByCompletion

        public void sendObjectByCompletion​(java.lang.Object obj,
                                           SendHandler completion)
        Sends an object asynchronously with a completion handler.
        Parameters:
        obj - the object to send
        completion - the completion handler
      • setSession

        protected void setSession​(WsSession wsSession)
        Sets the WebSocket session for this endpoint.
        Parameters:
        wsSession - the session
      • setEncoders

        protected void setEncoders​(EndpointConfig endpointConfig)
                            throws DeploymentException
        Initializes the encoders for this endpoint from the given endpoint configuration.
        Parameters:
        endpointConfig - the endpoint configuration
        Throws:
        DeploymentException - if an encoder cannot be initialized
      • close

        public final void close()
        Closes all encoders associated with this endpoint.
      • doWrite

        protected abstract void doWrite​(SendHandler handler,
                                        long blockingWriteTimeoutExpiry,
                                        java.nio.ByteBuffer... data)
        Writes data to the underlying connection.
        Parameters:
        handler - the send handler
        blockingWriteTimeoutExpiry - the timeout expiry time
        data - the data buffers to write
      • isMasked

        protected abstract boolean isMasked()
        Checks if frames should be masked.
        Returns:
        true if masking is required
      • doClose

        protected abstract void doClose()
        Performs the actual close operation on the underlying connection.
      • getLock

        protected abstract java.util.concurrent.locks.Lock getLock()
        Returns the lock used for thread-safe operations.
        Returns:
        the reentrant lock