Class AuthenticatedWebSocketHandler.InternalListener

  • All Implemented Interfaces:
    java.net.http.WebSocket.Listener
    Enclosing class:
    AuthenticatedWebSocketHandler

    protected class AuthenticatedWebSocketHandler.InternalListener
    extends java.lang.Object
    implements java.net.http.WebSocket.Listener
    HiroWebSocketListener (thread) for incoming websocket messages. Derivates of AuthenticatedWebSocketHandler have to supply an Object implementing the interface SpecificWebSocketListener for specific handling.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletionStage<?> onClose​(java.net.http.WebSocket webSocket, int statusCode, java.lang.String reason)
      Receives close messages.
      void onError​(java.net.http.WebSocket webSocket, java.lang.Throwable error)
      Handles errors (Throwable) regarding websocket operation.
      void onOpen​(java.net.http.WebSocket webSocket)
      java.util.concurrent.CompletionStage<?> onPing​(java.net.http.WebSocket webSocket, java.nio.ByteBuffer message)
      Keep-alive messages
      java.util.concurrent.CompletionStage<?> onText​(java.net.http.WebSocket webSocket, java.lang.CharSequence data, boolean last)
      Collects a text message from the websocket until 'last' is true.
      protected void reset()
      Reset listener for new usage.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.net.http.WebSocket.Listener

        onBinary, onPong
    • Constructor Detail

      • InternalListener

        public InternalListener​(java.lang.String name,
                                SpecificWebSocketListener listener)
        Constructor
        Parameters:
        name - Name of the handler (mainly for logging)
        listener - The listener which received messages.
    • Method Detail

      • onText

        public java.util.concurrent.CompletionStage<?> onText​(java.net.http.WebSocket webSocket,
                                                              java.lang.CharSequence data,
                                                              boolean last)
        Collects a text message from the websocket until 'last' is true. Then checks for an error message. If the error is 401 and the status is AuthenticatedWebSocketHandler.Status.RUNNING, tries to refresh the token. When the first non-error message comes it, sets the status from AuthenticatedWebSocketHandler.Status.RUNNING_PRELIMINARY to AuthenticatedWebSocketHandler.Status.RUNNING.
        Specified by:
        onText in interface java.net.http.WebSocket.Listener
        Parameters:
        webSocket - The webSocket using this HiroWebSocketListener.
        data - Message block
        last - True if this is the last message block of a message
        Returns:
        CompletionStage. See documentation at WebSocket.Listener.
      • onPing

        public java.util.concurrent.CompletionStage<?> onPing​(java.net.http.WebSocket webSocket,
                                                              java.nio.ByteBuffer message)
        Keep-alive messages
        Specified by:
        onPing in interface java.net.http.WebSocket.Listener
        Parameters:
        webSocket - The webSocket using this HiroWebSocketListener.
        message - The message received. It will be reflected back via Pong.
        Returns:
        The CompletionStage of WebSocket.sendPong(ByteBuffer).
      • onClose

        public java.util.concurrent.CompletionStage<?> onClose​(java.net.http.WebSocket webSocket,
                                                               int statusCode,
                                                               java.lang.String reason)
        Receives close messages. This will try to restart the WebSocket unless the status is AuthenticatedWebSocketHandler.Status.CLOSING.
        Specified by:
        onClose in interface java.net.http.WebSocket.Listener
        Parameters:
        webSocket - The webSocket using this HiroWebSocketListener.
        statusCode - Status code sent from the remote side.
        reason - Reason text sent from the remote side.
        Returns:
        null
      • onError

        public void onError​(java.net.http.WebSocket webSocket,
                            java.lang.Throwable error)
        Handles errors (Throwable) regarding websocket operation. This will try to restart the WebSocket unless the status is AuthenticatedWebSocketHandler.Status.CLOSING. This will tear down the WebSocket when the status is AuthenticatedWebSocketHandler.Status.FAILED.
        Specified by:
        onError in interface java.net.http.WebSocket.Listener
        Parameters:
        webSocket - The webSocket using this HiroWebSocketListener.
        error - The Throwable to handle.
      • reset

        protected void reset()
        Reset listener for new usage. Clears any previous exception by setting exception = null.