Better handling of InterruptedExceptions.

This commit is contained in:
akwizgran
2011-12-08 13:55:19 +00:00
parent c1ab21ba2f
commit d9fc8d18d1
16 changed files with 115 additions and 52 deletions

View File

@@ -246,11 +246,18 @@ class BluetoothPlugin extends AbstractPlugin implements StreamPlugin {
synchronized(discoveryLock) {
try {
discoveryAgent.startInquiry(DiscoveryAgent.GIAC, listener);
return listener.waitForUrls();
} catch(BluetoothStateException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage());
return Collections.emptyMap();
}
try {
return listener.waitForUrls();
} catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO))
LOG.info("Interrupted while waiting for URLs");
Thread.currentThread().interrupt();
return Collections.emptyMap();
}
}
}
@@ -294,8 +301,15 @@ class BluetoothPlugin extends AbstractPlugin implements StreamPlugin {
ConnectionCallback c = new ConnectionCallback(uuid, timeout);
startOutgoingInvitationThread(c);
startIncomingInvitationThread(c);
StreamConnection s = c.waitForConnection();
return s == null ? null : new BluetoothTransportConnection(s);
try {
StreamConnection s = c.waitForConnection();
return s == null ? null : new BluetoothTransportConnection(s);
} catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO))
LOG.info("Interrupted while waiting for connection");
Thread.currentThread().interrupt();
return null;
}
}
private String convertInvitationCodeToUuid(int code) {
@@ -333,6 +347,11 @@ class BluetoothPlugin extends AbstractPlugin implements StreamPlugin {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
return;
} catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO))
LOG.info("Interrupted while waiting for URL");
Thread.currentThread().interrupt();
return;
}
}
synchronized(this) {
@@ -376,9 +395,13 @@ class BluetoothPlugin extends AbstractPlugin implements StreamPlugin {
// Close the socket when the invitation times out
try {
Thread.sleep(c.getTimeout());
scn.close();
} catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO))
LOG.info("Interrupted while waiting for invitation timeout");
Thread.currentThread().interrupt();
}
try {
scn.close();
} catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage());
}