only docs
This commit is contained in:
parent
247d5e1892
commit
850415ad6c
|
@ -18,25 +18,26 @@ public class ConnectionWatchdog {
|
||||||
private final Timer reconnectTimer;
|
private final Timer reconnectTimer;
|
||||||
private static boolean isCreated;
|
private static boolean isCreated;
|
||||||
|
|
||||||
private ConnectionWatchdog(int timeoutMs, Runnable action) {
|
private ConnectionWatchdog(int timeoutMs, Runnable restartAction) {
|
||||||
reconnectTimer = new Timer(timeoutMs, e -> {
|
reconnectTimer = new Timer(timeoutMs, e -> {
|
||||||
action.run();
|
restartAction.run();
|
||||||
|
// mark alive right after restart attempt
|
||||||
onDataArrived();
|
onDataArrived();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void init(LinkManager linkManager) {
|
public synchronized static void init(LinkManager linkManager) {
|
||||||
final AtomicBoolean isPending = new AtomicBoolean();
|
final AtomicBoolean isRestartPending = new AtomicBoolean();
|
||||||
|
|
||||||
if (isCreated)
|
if (isCreated)
|
||||||
return; // only one instance is needed
|
return; // only one instance is needed
|
||||||
isCreated = true;
|
isCreated = true;
|
||||||
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
|
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
|
||||||
if (isPending.compareAndSet(false, true)) {
|
if (isRestartPending.compareAndSet(false, true)) {
|
||||||
linkManager.execute(() -> {
|
linkManager.execute(() -> {
|
||||||
log.info("ConnectionWatchdog.reconnectTimer restarting: " + Timeouts.CONNECTION_RESTART_DELAY);
|
log.info("ConnectionWatchdog.reconnectTimer restarting: " + Timeouts.CONNECTION_RESTART_DELAY);
|
||||||
linkManager.restart();
|
linkManager.restart();
|
||||||
isPending.set(false);
|
isRestartPending.set(false);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
log.info("restart already pending...");
|
log.info("restart already pending...");
|
||||||
|
|
Loading…
Reference in New Issue