Constructor and Description |
---|
ReconnectingGateway(Gateway actualGateway,
Timer connectTimer,
org.joda.time.Duration initialReconnectDelay,
org.joda.time.Duration reconnectInterval)
Initializes a new instance of the
ReconnectingGateway class. |
Modifier and Type | Method and 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 received
|
boolean |
isConnected()
Gets a value specifying whether the connection to the remote site is established.
|
void |
sendData(byte[] data)
Sends data through the current
Gateway . |
void |
setListener(GatewayListener listener)
Sets the
GatewayListener used to observe the current Gateway implementation. |
@Inject public ReconnectingGateway(Gateway actualGateway, Timer connectTimer, org.joda.time.Duration initialReconnectDelay, org.joda.time.Duration reconnectInterval)
ReconnectingGateway
class.actualGateway
- The wrapped Gateway
instance used for actual communicationconnectTimer
- The Timer
used to periodically attempt to establish a connection.initialReconnectDelay
- reconnectInterval
- IllegalArgumentException
- The actualGateway
is a null reference or a
connectTimer
is a null reference or a
reconnectInterval
is a null reference.public void setListener(GatewayListener listener)
GatewayListener
used to observe the current Gateway
implementation.setListener
in interface Gateway
listener
- the GatewayListener
used to observe the current Gateway
implementation or a null reference if observation is not required.public void sendData(byte[] data) throws IOException
Gateway
.sendData
in interface Gateway
data
- data to send.IllegalArgumentException
- The data
is a null reference or an empty arrayIOException
public void connect() throws IOException
connect
in interface Gateway
IOException
- There was an error establishing the connection.public void disconnect(boolean dueToError)
disconnect
in interface Gateway
dueToError
- - when false user wished to close connection; when true there was a problem and we had
to close itpublic boolean isConnected()
isConnected
in interface Gateway
public long getLastReceivedMsgTimestamp()
getLastReceivedMsgTimestamp
in interface Gateway
Copyright © 2013–2023. All rights reserved.