Class StreamRemoteConnector

    • Field Detail

      • logger

        protected final java.lang.System.Logger logger
      • executor

        protected final java.util.concurrent.ScheduledExecutorService executor
      • clock

        protected final java.time.Clock clock
    • Constructor Detail

      • StreamRemoteConnector

        protected StreamRemoteConnector​(LocalIdentifier ourLocalId,
                                        MenuCommandProtocol protocol,
                                        java.util.concurrent.ScheduledExecutorService executor,
                                        java.time.Clock clock)
    • Method Detail

      • sendMenuCommand

        public void sendMenuCommand​(MenuCommand msg)
                             throws java.io.IOException
        Sends a command to the remote with the protocol and usual headers.
        Specified by:
        sendMenuCommand in interface RemoteConnector
        Parameters:
        msg - the message to send.
        Throws:
        java.io.IOException - if there are issues with the transport
      • handleCoreConnectionStates

        protected void handleCoreConnectionStates​(ConnectMode connectMode)
      • sendInternal

        protected abstract void sendInternal​(java.nio.ByteBuffer outputBuffer)
                                      throws java.io.IOException
        performs a send of all bytes in the output buffer until the output buffer is empty
        Parameters:
        outputBuffer - the buffer data to be sent
        Throws:
        java.io.IOException - if there are problems writing
      • getAtLeastBytes

        protected abstract void getAtLeastBytes​(java.nio.ByteBuffer inputBuffer,
                                                int len,
                                                StreamRemoteConnector.ReadMode mode)
                                         throws java.io.IOException
        Reads at least the number of bytes requested waiting if need be for more data.
        Parameters:
        inputBuffer - the buffer to read from
        len - the minimum number of bytes needed
        Throws:
        java.io.IOException - if there are problems reading.
      • readCompleteMessage

        protected void readCompleteMessage​(java.nio.ByteBuffer inputBuffer)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • notifyListeners

        public void notifyListeners​(MenuCommand mc)
        Helper method that notifies all listeners of a new command message
        Specified by:
        notifyListeners in interface RemoteConnectorContext
        Parameters:
        mc - the message to notify
      • notifyConnection

        protected void notifyConnection()
        Helper method that notifies all connection listeners of a change in connectivity
      • logByteBuffer

        protected void logByteBuffer​(java.lang.String msg,
                                     java.nio.ByteBuffer inBuffer)
        Helper method that logs the entire message buffer when at debug logging level.
        Parameters:
        msg - the message to print first
        inBuffer - the buffer to be logged
      • doesBufferHaveEOM

        public static boolean doesBufferHaveEOM​(java.nio.ByteBuffer inputBuffer)
      • sendJoin

        public void sendJoin()
                      throws java.io.IOException
        Specified by:
        sendJoin in interface RemoteConnectorContext
        Throws:
        java.io.IOException