Skip to content

Commit

Permalink
Improved CallMonitorThread handling
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <[email protected]>
  • Loading branch information
cweitkamp committed Jan 8, 2021
1 parent 239b0f1 commit d03174b
Showing 1 changed file with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}
}

0 comments on commit d03174b

Please sign in to comment.