Skip to content

Commit

Permalink
Fixed bug where the binding could not be stopped and started manually.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmaret committed Mar 6, 2017
1 parent 76a2de2 commit 546b3bd
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*/
package org.openhab.binding.zmote.internal.discovery;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.SocketException;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -57,7 +57,8 @@ public class ZMoteDiscoveryService implements IZMoteDiscoveryService {
private final Map<String, ZMoteDiscoveryResult> discoveryResults = new ConcurrentHashMap<>();
private final List<IDiscoveryListener> discoveryListeners = new CopyOnWriteArrayList<>();

private ScheduledExecutorService scheduler = null;
private final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(ZMoteDiscoveryService.class.getName());
private ScheduledFuture<?> discoveryFuture = null;
private MulticastSocket discoverySocket = null;

Expand Down Expand Up @@ -128,7 +129,6 @@ protected void activate() {
deactivate();
}

scheduler = ThreadPoolManager.getScheduledPool(ZMoteDiscoveryService.class.getName());
startDiscoveryFuture();
startScan();

Expand All @@ -147,10 +147,6 @@ protected void activate() {

protected void deactivate() {
try {
if (scheduler != null) {
scheduler.shutdown();
}

stopDiscoveryFuture();

if (logger.isDebugEnabled()) {
Expand All @@ -162,8 +158,6 @@ protected void deactivate() {
logger.debug("Ignored exception while deactivating ZMote discovery service.", e);
}

} finally {
scheduler = null;
}
}

Expand Down Expand Up @@ -198,7 +192,7 @@ private void executeDiscovery() {
}
}
} catch (final Exception e) {
if ((e instanceof IOException) && Thread.currentThread().isInterrupted()) {
if ((e instanceof SocketException) && Thread.currentThread().isInterrupted()) {
if (logger.isDebugEnabled()) {
logger.debug("Discovery service worker has been terminated.");
}
Expand Down

0 comments on commit 546b3bd

Please sign in to comment.