private final Logger logger = LoggerFactory.getLogger(Debouncer.class);
private volatile Long lastCallAttempt;
- private ScheduledFuture<?> feature;
+ private ScheduledFuture<?> future;
/**
* Highly performant generic debouncer
lastCallAttempt = clock.millis();
calls.incrementAndGet();
if (pending.compareAndSet(false, true)) {
- feature = scheduler.schedule(this::tryActionOrPostpone, delayMs, TimeUnit.MILLISECONDS);
+ future = scheduler.schedule(this::tryActionOrPostpone, delayMs, TimeUnit.MILLISECONDS);
}
}
public void stop() {
logger.trace("stop debouncer");
- if (feature != null) {
- feature.cancel(true);
+ if (future != null) {
+ future.cancel(true);
calls.set(0);
pending.set(false);
}
// Note: we use Math.max as there's a _very_ small chance lastCallAttempt could advance in another thread,
// and result in a negative calculation
long delay = Math.max(1, lastCallAttempt - now + delayMs);
- feature = scheduler.schedule(this::tryActionOrPostpone, delay, TimeUnit.MILLISECONDS);
+ future = scheduler.schedule(this::tryActionOrPostpone, delay, TimeUnit.MILLISECONDS);
}
}
}
accessoryRegistry.setBridge(bridge);
}
- public synchronized void unsetBridge() {
- applyUpdatesDebouncer.stop();
- accessoryRegistry.unsetBridge();
- }
-
public void setUpdater(HomekitAccessoryUpdater updater) {
this.updater = updater;
}
this.settings = settings;
}
- public void stop() {
+ public synchronized void stop() {
this.itemRegistry.removeRegistryChangeListener(this);
this.metadataRegistry.removeRegistryChangeListener(metadataChangeListener);
+ applyUpdatesDebouncer.stop();
+ accessoryRegistry.unsetBridge();
}
public Map<String, HomekitAccessory> getAccessories() {
private void stopHomekitServer() {
logger.trace("stop HomeKit bridge");
- for (int i = 0; i < homekitServers.size(); ++i) {
- changeListeners.get(i).unsetBridge();
- bridges.get(i).stop();
- homekitServers.get(i).stop();
- changeListeners.get(i).stop();
- }
+ changeListeners.parallelStream().forEach(HomekitChangeListener::stop);
+ bridges.parallelStream().forEach(HomekitRoot::stop);
+ homekitServers.parallelStream().forEach(HomekitServer::stop);
homekitServers.clear();
bridges.clear();
changeListeners.clear();