public abstract class RobustConnection extends Object
Helper class for handling automatic reconnections to remote devices/services.
It must be subclassed to provide an implementation of the tryConnect()
method
Modifier and Type | Field and Description |
---|---|
protected RobustConnectionConfig |
connectConfig |
protected boolean |
connected |
protected AbstractModule<?> |
module |
protected String |
remoteServiceName |
protected Thread |
waitThread |
Constructor and Description |
---|
RobustConnection(AbstractModule<?> module,
RobustConnectionConfig config,
String remoteServiceName) |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the automatic reconnection loop if still running
|
boolean |
isConnected() |
void |
reconnect()
Helper method to reconnect after a disconnection has been detected
The default implementation just restarts the module asynchronously. |
abstract boolean |
tryConnect()
Implements the connection process.
This is called for each connection attempt |
void |
updateConfig(RobustConnectionConfig config) |
void |
waitForConnection()
Waits until the client is connected
If connection is detected by another thread, this method can also be notified by calling stateLock.notify() |
protected AbstractModule<?> module
protected RobustConnectionConfig connectConfig
protected String remoteServiceName
protected Thread waitThread
protected volatile boolean connected
public RobustConnection(AbstractModule<?> module, RobustConnectionConfig config, String remoteServiceName)
public void updateConfig(RobustConnectionConfig config)
public abstract boolean tryConnect() throws Exception
Exception
- sent on error that requires aborting the connection process
(no more connection attempts will be made after such exception is thrown)public void waitForConnection() throws SensorHubException
SensorHubException
- on error preventing further attempts or max number of attempts reachedpublic void cancel()
public void reconnect()
public boolean isConnected()
Copyright © 2016 Sensia Software LLC. All rights reserved.