Class ProtocolBase<I extends IncomingMessage,O extends OutgoingMessage>

java.lang.Object
com.sportradar.livedata.sdk.proto.common.ProtocolBase<I,O>
All Implemented Interfaces:
Protocol<I,O>
Direct Known Subclasses:
LiveFeedProtocol

public abstract class ProtocolBase<I extends IncomingMessage,O extends OutgoingMessage> extends Object implements Protocol<I,O>
Base class for all Protocol implementations
  • Field Details

    • gateway

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

      protected final MessageParser<I extends IncomingMessage> messageParser
      The MessageParser used to parse data received from 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.
    • listener

      protected volatile ProtocolListener<I extends IncomingMessage> listener
      The listener used to observe the current ProtocolBase
  • Constructor Details

    • 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 Details

    • start

      public void start()
      Starts the protocol - i.e. enables(starts) the communication with the server.
      Specified by:
      start in interface Protocol<I extends IncomingMessage,O extends OutgoingMessage>
    • reconnect

      public void reconnect()
      Description copied from interface: Protocol
      Reconnects the underlying feed
      Specified by:
      reconnect in interface Protocol<I extends IncomingMessage,O extends OutgoingMessage>
    • 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.
    • setListener

      public void setListener(ProtocolListener<I> listener)
      Sets the ProtocolListener used to observe the current Protocol.
      Specified by:
      setListener in interface Protocol<I extends IncomingMessage,O extends OutgoingMessage>
      Parameters:
      listener - the ProtocolListener used to observe the current Protocol or a null reference.
    • stop

      public void stop()
      Stops the protocol - i.e. disables the communication with the server.
      Specified by:
      stop in interface Protocol<I extends IncomingMessage,O extends OutgoingMessage>
    • 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.