mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[lifx] Improve InterruptedException handling (#11653)
When the binding is stopped sleeping threads are interrupted by design. By throwing the InterruptedException, it should be caught in LifxSelectorUtil.sendPacket (which is waiting for the packet interval to elapse), which will then abort sending a packet. This prevents: ``` [ERROR] [lifx.internal.util.LifxThrottlingUtil] - An exception occurred while putting the thread to sleep : 'sleep interrupted' ``` Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
parent
612afd2e07
commit
73ed075d4e
@ -81,7 +81,7 @@ public final class LifxThrottlingUtil {
|
||||
|
||||
private static Map<MACAddress, LifxLightCommunicationTracker> macTrackerMapping = new ConcurrentHashMap<>();
|
||||
|
||||
public static void lock(@Nullable MACAddress mac) {
|
||||
public static void lock(@Nullable MACAddress mac) throws InterruptedException {
|
||||
if (mac != null) {
|
||||
LifxLightCommunicationTracker tracker = getOrCreateTracker(mac);
|
||||
tracker.lock();
|
||||
@ -108,14 +108,10 @@ public final class LifxThrottlingUtil {
|
||||
return tracker;
|
||||
}
|
||||
|
||||
private static void waitForNextPacketInterval(long timestamp) {
|
||||
private static void waitForNextPacketInterval(long timestamp) throws InterruptedException {
|
||||
long timeToWait = Math.max(PACKET_INTERVAL - (System.currentTimeMillis() - timestamp), 0);
|
||||
if (timeToWait > 0) {
|
||||
try {
|
||||
Thread.sleep(timeToWait);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("An exception occurred while putting the thread to sleep : '{}'", e.getMessage());
|
||||
}
|
||||
Thread.sleep(timeToWait);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +126,7 @@ public final class LifxThrottlingUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void lock() {
|
||||
public static void lock() throws InterruptedException {
|
||||
long lastStamp = 0;
|
||||
for (LifxLightCommunicationTracker tracker : trackers) {
|
||||
tracker.lock();
|
||||
|
Loading…
Reference in New Issue
Block a user