Class ReconnectingGateway

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

public class ReconnectingGateway extends Object implements Gateway
A Gateway which periodically attempts to connect to the server until the connection is established
  • Constructor Details

    • ReconnectingGateway

      @Inject public ReconnectingGateway(Gateway actualGateway, Timer connectTimer, org.joda.time.Duration initialReconnectDelay, org.joda.time.Duration reconnectInterval)
      Initializes a new instance of the ReconnectingGateway class.
      Parameters:
      actualGateway - The wrapped Gateway instance used for actual communication
      connectTimer - The Timer used to periodically attempt to establish a connection.
      initialReconnectDelay - The Duration specifying the initial reconnect interval.
      reconnectInterval - The Duration specifying the reconnect interval.
      Throws:
      IllegalArgumentException - The actualGateway is a null reference or a connectTimer is a null reference or a reconnectInterval 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