Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lifx] Improve InterruptedException handling #11653

Merged
merged 1 commit into from
Nov 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public long getTimestamp() {

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();
Expand All @@ -108,14 +108,10 @@ private static LifxLightCommunicationTracker getOrCreateTracker(MACAddress mac)
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);
}
}

Expand All @@ -130,7 +126,7 @@ public static void unlock(@Nullable MACAddress mac) {
}
}

public static void lock() {
public static void lock() throws InterruptedException {
long lastStamp = 0;
for (LifxLightCommunicationTracker tracker : trackers) {
tracker.lock();
Expand Down