From 05e2e682a0e1926fbdd267fde21903ec1c23bb11 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Tue, 8 Feb 2022 10:18:37 +0100 Subject: [PATCH] [ecovacs] Shorten XMPP ping intervals after failure If a ping failed, subsequent failures are very likely, so a shorter interval will shorten the time until reconnection while still providing robustness against single failures. --- .../ecovacs/internal/api/impl/EcovacsXmppDevice.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java index 3ac4774aa6833..44d66fe9c9532 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java @@ -246,6 +246,8 @@ public void disconnect() { private class PingHandler { private static final long INTERVAL = 30; // seconds + // After a failure, use shorter intervals since subsequent further failure is likely + private static final long POST_FAILURE_INTERVAL = 5; // seconds private static final int MAX_FAILURES = 4; private final PingManager pingManager; @@ -278,7 +280,7 @@ public void stop() { private void sendPing() { long timeSinceLastStanza = (System.currentTimeMillis() - connection.getLastStanzaReceived()) / 1000; - if (timeSinceLastStanza < INTERVAL) { + if (timeSinceLastStanza < currentPingInterval()) { scheduleNextPing(timeSinceLastStanza); return; } @@ -306,9 +308,13 @@ private synchronized void scheduleNextPing(long delta) { oldFuture.cancel(true); } if (started) { - this.nextPing = scheduler.schedule(this::sendPing, INTERVAL - delta, TimeUnit.SECONDS); + this.nextPing = scheduler.schedule(this::sendPing, currentPingInterval() - delta, TimeUnit.SECONDS); } } + + private long currentPingInterval() { + return failedPings > 0 ? POST_FAILURE_INTERVAL : INTERVAL; + } } private class IncomingMessageHandler extends AbstractIqRequestHandler {