Class ReconnectingGateway
java.lang.Object
com.sportradar.livedata.sdk.common.networking.ReconnectingGateway
- All Implemented Interfaces:
Gateway
A
Gateway
which periodically attempts to connect to the server until the connection is established-
Constructor Summary
ConstructorsConstructorDescriptionReconnectingGateway
(Gateway actualGateway, Timer connectTimer, org.joda.time.Duration initialReconnectDelay, org.joda.time.Duration reconnectInterval) Initializes a new instance of theReconnectingGateway
class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
connect()
Attempts to establish a connection to the remote site.void
disconnect
(boolean dueToError) Drops the established connection.getId()
Gets gateway id (hostname, port, ...)long
Gets last timestamp in unix millis when the last msg was receivedboolean
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 Details
-
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 Details
-
setListener
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
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
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
-
getId
Description copied from interface:Gateway
Gets gateway id (hostname, port, ...)
-