mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 03:14:07 +01:00
[insteon] Use separate pool for long running threads
Signed-off-by: Jeremy Setton <jeremy.setton@gmail.com>
This commit is contained in:
parent
3827872c20
commit
34f84c3b54
@ -370,9 +370,8 @@ public abstract class InsteonBaseThingHandler extends BaseThingHandler implement
|
||||
}
|
||||
|
||||
protected void cancelJob(@Nullable ScheduledFuture<?> job, boolean interrupt) {
|
||||
if (job != null) {
|
||||
if (job != null && !job.isCancelled()) {
|
||||
job.cancel(interrupt);
|
||||
job = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ package org.openhab.binding.insteon.internal.handler;
|
||||
import static org.openhab.binding.insteon.internal.InsteonBindingConstants.*;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
@ -33,6 +34,7 @@ import org.openhab.binding.insteon.internal.device.InsteonAddress;
|
||||
import org.openhab.binding.insteon.internal.device.InsteonModem;
|
||||
import org.openhab.binding.insteon.internal.device.ProductData;
|
||||
import org.openhab.binding.insteon.internal.discovery.InsteonDiscoveryService;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
import org.openhab.core.io.transport.serial.SerialPortManager;
|
||||
import org.openhab.core.storage.Storage;
|
||||
import org.openhab.core.storage.StorageService;
|
||||
@ -58,6 +60,9 @@ public class InsteonBridgeHandler extends InsteonBaseThingHandler implements Bri
|
||||
private static final int RETRY_INTERVAL = 30; // seconds
|
||||
private static final int START_DELAY = 5; // seconds
|
||||
|
||||
private final ScheduledExecutorService insteonScheduler = ThreadPoolManager
|
||||
.getScheduledPool(BINDING_ID + "-" + getThingId());
|
||||
|
||||
private @Nullable InsteonModem modem;
|
||||
private @Nullable InsteonDiscoveryService discoveryService;
|
||||
private @Nullable ScheduledFuture<?> connectJob;
|
||||
@ -167,7 +172,7 @@ public class InsteonBridgeHandler extends InsteonBaseThingHandler implements Bri
|
||||
legacyHandler.disable();
|
||||
}
|
||||
|
||||
InsteonModem modem = InsteonModem.makeModem(this, config, httpClient, scheduler, serialPortManager);
|
||||
InsteonModem modem = InsteonModem.makeModem(this, config, httpClient, insteonScheduler, serialPortManager);
|
||||
this.modem = modem;
|
||||
|
||||
if (isInitialized()) {
|
||||
@ -314,8 +319,9 @@ public class InsteonBridgeHandler extends InsteonBaseThingHandler implements Bri
|
||||
return;
|
||||
}
|
||||
|
||||
cancelJob(reconnectJob, false);
|
||||
updateStatus();
|
||||
|
||||
cancelJob(reconnectJob, false);
|
||||
}, 0, RETRY_INTERVAL, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@ -327,10 +333,7 @@ public class InsteonBridgeHandler extends InsteonBaseThingHandler implements Bri
|
||||
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.DUTY_CYCLE, "Resetting bridge.");
|
||||
|
||||
resetJob = scheduler.schedule(() -> {
|
||||
initialize();
|
||||
cancelJob(resetJob, false);
|
||||
}, delay, TimeUnit.SECONDS);
|
||||
resetJob = scheduler.schedule(this::initialize, delay, TimeUnit.SECONDS);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -16,18 +16,21 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.openhab.binding.insteon.internal.InsteonBindingConstants;
|
||||
import org.openhab.binding.insteon.internal.InsteonLegacyBinding;
|
||||
import org.openhab.binding.insteon.internal.config.InsteonBridgeConfiguration;
|
||||
import org.openhab.binding.insteon.internal.config.InsteonLegacyNetworkConfiguration;
|
||||
import org.openhab.binding.insteon.internal.device.DeviceAddress;
|
||||
import org.openhab.binding.insteon.internal.device.InsteonAddress;
|
||||
import org.openhab.binding.insteon.internal.discovery.InsteonLegacyDiscoveryService;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
import org.openhab.core.io.console.Console;
|
||||
import org.openhab.core.io.transport.serial.SerialPortManager;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
@ -61,6 +64,9 @@ public class InsteonLegacyNetworkHandler extends BaseBridgeHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(InsteonLegacyNetworkHandler.class);
|
||||
|
||||
private final ScheduledExecutorService insteonScheduler = ThreadPoolManager
|
||||
.getScheduledPool(InsteonBindingConstants.BINDING_ID + "-" + getThing().getUID().getId());
|
||||
|
||||
private @Nullable InsteonLegacyBinding insteonBinding;
|
||||
private @Nullable InsteonLegacyDiscoveryService insteonDiscoveryService;
|
||||
private @Nullable ScheduledFuture<?> driverInitializedJob = null;
|
||||
@ -108,7 +114,7 @@ public class InsteonLegacyNetworkHandler extends BaseBridgeHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
insteonBinding = new InsteonLegacyBinding(this, config, httpClient, scheduler, serialPortManager);
|
||||
insteonBinding = new InsteonLegacyBinding(this, config, httpClient, insteonScheduler, serialPortManager);
|
||||
updateStatus(ThingStatus.UNKNOWN);
|
||||
|
||||
// hold off on starting to poll until devices that already are defined as things are added.
|
||||
|
Loading…
Reference in New Issue
Block a user