Class StreamRemoteConnector

  • All Implemented Interfaces:
    RemoteConnector
    Direct Known Subclasses:
    Rs232RemoteConnector, SocketBasedConnector

    public abstract class StreamRemoteConnector
    extends java.lang.Object
    implements RemoteConnector
    Stream remote connector is the base class for all stream implementations, such as Socket and RS232. Any remote with stream like semantics can use this as the base for building out an adapter.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Force close a connection when its known to be bad, the connector will try and establish a new connection.
      static boolean doesBufferHaveEOM​(java.nio.ByteBuffer inputBuffer)  
      protected abstract void getAtLeastBytes​(java.nio.ByteBuffer inputBuffer, int len)
      Reads at least the number of bytes requested waiting if need be for more data.
      boolean isConnected()
      Gets the underlying connection state for this connector.
      protected void logByteBuffer​(java.lang.String msg, java.nio.ByteBuffer inBuffer)
      Helper method that logs the entire message buffer when at debug logging level.
      protected void notifyConnection()
      Helper method that notifies all connection listeners of a change in connectivity
      protected void processMessagesOnConnection()
      This is the loop that handles a connection by reading messages until there's an IOException, or the transport or thread change to an end state.
      protected void readCompleteMessage​(java.nio.ByteBuffer inputBuffer)  
      void registerConnectionChangeListener​(ConnectionChangeListener listener)
      Register for connection change events, when there is a change in connectivity status on the underlying transport.
      void registerConnectorListener​(RemoteConnectorListener listener)
      Register for connector messages, when new messages are received from this stream.
      protected abstract void sendInternal​(java.nio.ByteBuffer outputBuffer)
      performs a send of all bytes in the output buffer until the output buffer is empty
      void sendMenuCommand​(MenuCommand msg)
      Sends a command to the remote with the protocol and usual headers.
      • Methods inherited from class java.lang.Object

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

      • logger

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

        protected final java.util.concurrent.ScheduledExecutorService executor
    • Constructor Detail

      • StreamRemoteConnector

        protected StreamRemoteConnector​(MenuCommandProtocol protocol,
                                        java.util.concurrent.ScheduledExecutorService executor)
    • Method Detail

      • processMessagesOnConnection

        protected void processMessagesOnConnection()
        This is the loop that handles a connection by reading messages until there's an IOException, or the transport or thread change to an end state.
      • close

        public void close()
        Description copied from interface: RemoteConnector
        Force close a connection when its known to be bad, the connector will try and establish a new connection.
        Specified by:
        close in interface RemoteConnector
      • isConnected

        public boolean isConnected()
        Description copied from interface: RemoteConnector
        Gets the underlying connection state for this connector.
        Specified by:
        isConnected in interface RemoteConnector
        Returns:
        the underlying connection state.
      • 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
      • 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)
                                         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
      • 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)