]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lifx] Improve InterruptedException handling (#11653)
authorWouter Born <github@maindrain.net>
Sun, 28 Nov 2021 15:37:29 +0000 (16:37 +0100)
committerGitHub <noreply@github.com>
Sun, 28 Nov 2021 15:37:29 +0000 (16:37 +0100)
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>
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxThrottlingUtil.java

index 8001d1e74b5e7d876b77b78455bb221c1ed89937..30d542842266b899258cab1032ff09a20bcea6a1 100644 (file)
@@ -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();