Class ConnectionMonitoringGateway

java.lang.Object
com.sportradar.livedata.sdk.common.networking.ConnectionMonitoringGateway
All Implemented Interfaces:
Gateway

public class ConnectionMonitoringGateway extends Object implements Gateway
A Gateway implementation which observes the received messages to determine when the connection is unstable
  • Constructor Details

    • ConnectionMonitoringGateway

      public ConnectionMonitoringGateway(Gateway actualGateway, Timer monitorTimer, org.joda.time.Duration checkInterval, org.joda.time.Duration noActivityTimeout, boolean debugMode)
      Initializes a new instance of the ConnectionMonitoringGateway class.
      Parameters:
      actualGateway - the wrapped Gateway implementation used to communicate with the server.
      monitorTimer - The timer used to periodically monitor the connection status.
      checkInterval - Check interval for socket connection.
      noActivityTimeout - The Duration specifying the time window in milliseconds after which the connection will be considered unstable if the gateway does not receive any data.
      debugMode - Adds debug logging.
      Throws:
      IllegalArgumentException - the actualGateway is a null reference or monitorTimer is a null reference or checkInterval is a null reference or noActivityTimeout is a null reference.
  • Method Details

    • setListener

      public void setListener(GatewayListener listener)
      Sets the GatewayListener used to observe the current Gateway implementation.
      Specified by:
      setListener in interface Gateway
      Parameters:
      listener - the GatewayListener used to observe the current Gateway implementation or a null reference if observation is not required.
    • sendData

      public void sendData(byte[] data) throws IOException
      Sends data through the current Gateway.
      Specified by:
      sendData in interface Gateway
      Parameters:
      data - data to send.
      Throws:
      IllegalArgumentException - The data is a null reference or an empty array
      IOException - connection problem
    • connect

      public void connect() throws IOException
      Attempts to establish a connection to the remote site.
      Specified by:
      connect in interface Gateway
      Throws:
      IOException - There was an error establishing the connection.
    • disconnect

      public void disconnect(boolean dueToError)
      Drops the established connection.
      Specified by:
      disconnect in interface Gateway
      Parameters:
      dueToError - - when false user wished to close connection; when true there was a problem and we had to close it
    • isConnected

      public boolean isConnected()
      Gets a value specifying whether the connection to the remote site is established.
      Specified by:
      isConnected in interface Gateway
      Returns:
      Value specifying whether the connection to the remote site is established.
    • getLastReceivedMsgTimestamp

      public long getLastReceivedMsgTimestamp()
      Gets last timestamp in unix millis when the last msg was received
      Specified by:
      getLastReceivedMsgTimestamp in interface Gateway
      Returns:
      timestamp when the last msg was received
    • getId

      public String getId()
      Description copied from interface: Gateway
      Gets gateway id (hostname, port, ...)
      Specified by:
      getId in interface Gateway
      Returns:
      gateway identification