Skip to content

Commit

Permalink
Exit SwitchableRouterImpl correctly when lock acquisition was interru…
Browse files Browse the repository at this point in the history
…pted
  • Loading branch information
Christian Bauer committed Feb 5, 2013
1 parent 0500c23 commit e4337c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Expand Up @@ -18,6 +18,9 @@
import org.fourthline.cling.UpnpService;
import org.fourthline.cling.model.message.UpnpMessage;
import org.fourthline.cling.model.message.header.UpnpHeader;
import org.seamless.util.Exceptions;

import java.util.logging.Logger;

/**
* Supertype for all asynchronously executing protocols, handling reception of UPnP messages.
Expand All @@ -33,6 +36,8 @@
*/
public abstract class ReceivingAsync<M extends UpnpMessage> implements Runnable {

final private static Logger log = Logger.getLogger(ReceivingAsync.class.getName());

private final UpnpService upnpService;

private M inputMessage;
Expand All @@ -55,11 +60,21 @@ public void run() {
try {
proceed = waitBeforeExecution();
} catch (InterruptedException ex) {
log.info("Protocol wait before execution interrupted (on shutdown?): " + getClass().getSimpleName());
proceed = false;
}

if (proceed) {
execute();
try {
execute();
} catch (RuntimeException ex) {
Throwable cause = Exceptions.unwrap(ex);
if (cause instanceof InterruptedException) {
log.info("Protocol execution interrupted (on shutdown?): " + ex);
} else {
throw ex;
}
}
}
}

Expand Down
Expand Up @@ -238,7 +238,9 @@ protected void lock(Lock lock, int timeoutMilliseconds) throws RouterLockAcquisi
throw new RouterLockAcquisitionException("Failed to acquire router lock: " + lock.getClass().getSimpleName());
}
} catch (InterruptedException ex) {
log.log(Level.INFO, "Waiting for lock interrupted: " + lock.getClass().getSimpleName(), ex);
throw new RouterLockAcquisitionException(
"Interruption while waiting for lock: " + lock.getClass().getSimpleName(), ex
);
}
}

Expand Down

0 comments on commit e4337c4

Please sign in to comment.