Skip to content

Commit

Permalink
[network] fix discovery service (openhab#4729)
Browse files Browse the repository at this point in the history
* fix discovery service
* shutdown executor service

Signed-off-by: Jan N. Klug <[email protected]>
Signed-off-by: Maximilian Hess <[email protected]>
  • Loading branch information
J-N-K authored and ne0h committed Sep 15, 2019
1 parent 73ce2d6 commit 089b2d8
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ protected void modified(@Nullable Map<String, @Nullable Object> config) {
@Override
@Deactivate
protected void deactivate() {
if (executorService != null) {
executorService.shutdown();
}
super.deactivate();
}

Expand All @@ -121,6 +124,9 @@ public void finalDetectionResult(PresenceDetectionValue value) {
*/
@Override
protected void startScan() {
if (executorService == null) {
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
}
final ExecutorService service = executorService;
if (service == null) {
return;
Expand All @@ -129,7 +135,6 @@ protected void startScan() {
logger.trace("Starting Network Device Discovery");

final Set<String> networkIPs = networkUtils.getNetworkIPs(MAXIMUM_IPS_PER_INTERFACE);
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
scannedIPcount = 0;

for (String ip : networkIPs) {
Expand Down Expand Up @@ -233,7 +238,7 @@ public void newPingDevice(String ip) {

Map<String, Object> properties = new HashMap<>();
properties.put(PARAMETER_HOSTNAME, ip);
thingDiscovered(DiscoveryResultBuilder.create(createPingUID(ip)).withTTL(120).withProperties(properties)
.withLabel("Network Device (" + ip + ")").build());
thingDiscovered(DiscoveryResultBuilder.create(createPingUID(ip)).withTTL(DISCOVERY_RESULT_TTL)
.withProperties(properties).withLabel("Network Device (" + ip + ")").build());
}
}

0 comments on commit 089b2d8

Please sign in to comment.