Class ReconnectingGateway
- java.lang.Object
-
- com.sportradar.livedata.sdk.common.networking.ReconnectingGateway
-
-
Constructor Summary
Constructors Constructor Description ReconnectingGateway(Gateway actualGateway, Timer connectTimer, org.joda.time.Duration initialReconnectDelay, org.joda.time.Duration reconnectInterval)
Initializes a new instance of theReconnectingGateway
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect()
Attempts to establish a connection to the remote site.void
disconnect(boolean dueToError)
Drops the established connection.String
getId()
Gets gateway id (hostname, port, ...)long
getLastReceivedMsgTimestamp()
Gets last timestamp in unix millis when the last msg was receivedboolean
isConnected()
Gets a value specifying whether the connection to the remote site is established.void
sendData(byte[] data)
Sends data through the currentGateway
.void
setListener(GatewayListener listener)
Sets theGatewayListener
used to observe the currentGateway
implementation.
-
-
-
Constructor Detail
-
ReconnectingGateway
@Inject public ReconnectingGateway(Gateway actualGateway, Timer connectTimer, org.joda.time.Duration initialReconnectDelay, org.joda.time.Duration reconnectInterval)
Initializes a new instance of theReconnectingGateway
class.- Parameters:
actualGateway
- The wrappedGateway
instance used for actual communicationconnectTimer
- TheTimer
used to periodically attempt to establish a connection.initialReconnectDelay
- TheDuration
specifying the initial reconnect interval.reconnectInterval
- TheDuration
specifying the reconnect interval.- Throws:
IllegalArgumentException
- TheactualGateway
is a null reference or aconnectTimer
is a null reference or areconnectInterval
is a null reference.
-
-
Method Detail
-
setListener
public void setListener(GatewayListener listener)
Sets theGatewayListener
used to observe the currentGateway
implementation.- Specified by:
setListener
in interfaceGateway
- Parameters:
listener
- theGatewayListener
used to observe the currentGateway
implementation or a null reference if observation is not required.
-
sendData
public void sendData(byte[] data) throws IOException
Sends data through the currentGateway
.- Specified by:
sendData
in interfaceGateway
- Parameters:
data
- data to send.- Throws:
IllegalArgumentException
- Thedata
is a null reference or an empty arrayIOException
- connection problem
-
connect
public void connect() throws IOException
Attempts to establish a connection to the remote site.- Specified by:
connect
in interfaceGateway
- Throws:
IOException
- There was an error establishing the connection.
-
disconnect
public void disconnect(boolean dueToError)
Drops the established connection.- Specified by:
disconnect
in interfaceGateway
- 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 interfaceGateway
- 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 interfaceGateway
- Returns:
- timestamp when the last msg was received
-
-