From: Wouter Born Date: Sun, 28 Nov 2021 15:37:29 +0000 (+0100) Subject: [lifx] Improve InterruptedException handling (#11653) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=73ed075d4efa65c61511c186d8c2ceee478ef133;p=openhab-addons.git [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 --- diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxThrottlingUtil.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxThrottlingUtil.java index 8001d1e74b..30d5428422 100644 --- a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxThrottlingUtil.java +++ b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxThrottlingUtil.java @@ -81,7 +81,7 @@ public final class LifxThrottlingUtil { private static Map 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();