Class ProtocolBase<I extends IncomingMessage,​O extends OutgoingMessage>

    • Field Detail

      • gateway

        protected final Gateway gateway
        The Gateway implementation used to establish a connection to the server.
      • sdkLogger

        protected final SdkLogger sdkLogger
        Sdk logging facility.
      • isStarted

        protected volatile boolean isStarted
        The value specifying whether the protocol is started - i.e. is communication with the server enabled.
    • Constructor Detail

      • ProtocolBase

        public ProtocolBase​(Gateway gateway,
                            MessageParser<I> messageParser)
        Initializes a new instance of the ProtocolBase class.
        Parameters:
        gateway - The Gateway implementation used to establish a connection to the server.
        messageParser - The MessageParser used to parse data received from the server.
        Throws:
        IllegalArgumentException - The sdkLogger is a null reference or gateway is a null reference or messageParser is a null reference.
    • Method Detail

      • isStarted

        public boolean isStarted()
        Gets the value indicating whether the protocol is started - i.e if the communication with server is enabled.
        Specified by:
        isStarted in interface Protocol<I extends IncomingMessage,​O extends OutgoingMessage>
        Returns:
        True if protocol is started. False otherwise.
      • setDependencyListeners

        protected void setDependencyListeners()
        Sets the listeners on the injected dependencies
      • onGatewayDataReceived

        protected void onGatewayDataReceived​(InputStream stream)
        Invoked by the observed Gateway instance when it receives new data from the server.
        Parameters:
        stream - The InputStream containing the received data.
      • onGatewayConnected

        protected void onGatewayConnected()
        Invoked when the internally used gateway establishes a connection to the remote host.
      • onGatewayDisconnected

        protected void onGatewayDisconnected()
        Invoked when the internally used Gateway drops connection to the remote host.
      • onGatewayError

        protected void onGatewayError​(Exception ex)
        Invoked by the observed Gateway when the connection to the server is closed due to some error - connection closed by the server, missed connection alive message, invalid data ...
        Parameters:
        ex - The exception which occurred on the observed gateway.
      • onMessageParsed

        protected void onMessageParsed​(I message)
        Invoked when the observed MessageParser parsed data which represented a whole message.
        Parameters:
        message - Message constructed from the received data.
      • notifyOnEvent

        protected void notifyOnEvent​(FeedEventType eventType,
                                     Object data)
        Notifies the attached observer that an error occurred on the observed protocol
        Parameters:
        eventType - The FeedEventType member specifying the type of the occurred error.
        data - Opaque additional data
      • notifyOnMessageReceived

        protected void notifyOnMessageReceived​(I message)
        Notifies the attached observer the protocol has received message from the server.
        Parameters:
        message - the message received from the server.
      • connect

        protected void connect()
        Instructs the internally used Gateway to connect to the host.