From d03174bf40a55c8c2a48139a4eb35d07d1ae7ef2 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Fri, 8 Jan 2021 10:10:01 +0100 Subject: [PATCH] Improved CallMonitorThread handling Signed-off-by: Christoph Weitkamp --- .../internal/callmonitor/CallMonitor.java | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/callmonitor/CallMonitor.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/callmonitor/CallMonitor.java index c4a19f8a1085d..148688ce5ae5e 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/callmonitor/CallMonitor.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/callmonitor/CallMonitor.java @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory; /** - * This class handles all communication with the call monitor port of the fritzbox. + * This class handles all communication with the Call Monitor port of the FRITZ!Box. * * @author Kai Kreuzer - Initial contribution */ @@ -42,7 +42,7 @@ public class CallMonitor { protected final Logger logger = LoggerFactory.getLogger(CallMonitor.class); - // port number to connect to fritzbox + // port number to connect to FRITZ!Box private static final int MONITOR_PORT = 1012; private @Nullable CallMonitorThread monitorThread; @@ -75,9 +75,9 @@ public CallMonitor(String ip, BoxHandler handler, ScheduledExecutorService sched * Refresh channels. */ public void refreshChannels() { - CallMonitorThread monitorThread = this.monitorThread; - if (monitorThread != null) { - monitorThread.resetChannels(); + CallMonitorThread thread = this.monitorThread; + if (thread != null) { + thread.resetChannels(); } } @@ -86,10 +86,7 @@ public void refreshChannels() { */ public void dispose() { reconnectJob.cancel(true); - CallMonitorThread monitorThread = this.monitorThread; - if (monitorThread != null) { - monitorThread.interrupt(); - } + stopThread(); } public class CallMonitorThread extends Thread { @@ -228,20 +225,10 @@ private void handleCallEvent(CallEvent ce) { public void stopThread() { logger.debug("Stopping call monitor thread..."); - if (monitorThread != null) { - monitorThread.interrupt(); - monitorThread = null; - } - } - - public void startThread() { - logger.debug("Starting call monitor thread..."); - if (monitorThread != null) { - monitorThread.interrupt(); + CallMonitorThread thread = this.monitorThread; + if (thread != null) { + thread.interrupt(); monitorThread = null; } - // create a new thread for listening to the FritzBox - monitorThread = new CallMonitorThread(); - monitorThread.start(); } }