mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 20:47:57 +01:00
Improve handling of InterruptedException
InterruptedExceptions should be treated as the users intention to 'cancel' the current thread's task. There is no such thing as a spurious interrupt (not to be confused with "spurious wakeups").
This commit is contained in:
parent
14b03149db
commit
d099e7b16d
5 changed files with 15 additions and 11 deletions
|
@ -156,13 +156,15 @@ public class ReconnectionManager {
|
|||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// We don't need to handle spurious interrupts, in the worst case, this will cause to
|
||||
// reconnect a few seconds earlier, depending on how many (spurious) interrupts arrive while
|
||||
// sleep() is called.
|
||||
LOGGER.log(Level.FINE, "Supurious interrupt", e);
|
||||
LOGGER.log(Level.FINE, "waiting for reconnection interrupted", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (ConnectionListener listener : connection.connectionListeners) {
|
||||
listener.reconnectingIn(0);
|
||||
}
|
||||
|
||||
// Makes a reconnection attempt
|
||||
try {
|
||||
if (isReconnectionPossible(connection)) {
|
||||
|
|
|
@ -248,7 +248,8 @@ public class Roster {
|
|||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOGGER.log(Level.FINE, "spurious interrupt", e);
|
||||
LOGGER.log(Level.FINE, "interrupted", e);
|
||||
break;
|
||||
}
|
||||
long now = System.currentTimeMillis();
|
||||
waitTime -= now - start;
|
||||
|
|
|
@ -201,7 +201,6 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
return (P) queue.poll(wait, TimeUnit.SECONDS);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// TODO handle spurious interrupts
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ public class WaitForPacketListener implements PacketListener {
|
|||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// TODO better handling of spurious interrupts
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1216,9 +1216,11 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
}
|
||||
catch (InterruptedException e) {
|
||||
throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
|
||||
// If the method above did not throw, we have a spurious interrupt and we should try to enqueue the
|
||||
// element again
|
||||
LOGGER.log(Level.FINE, "Spurious interrupt", e);
|
||||
// If the method above did not throw, then the sending thread was interrupted
|
||||
// TODO in a later version of Smack the InterruptedException should be thrown to
|
||||
// allow users to interrupt a sending thread that is currently blocking because
|
||||
// the queue is full.
|
||||
LOGGER.log(Level.WARNING, "Sending thread was interrupted", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1253,7 +1255,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
}
|
||||
catch (InterruptedException e) {
|
||||
if (!queue.isShutdown()) {
|
||||
LOGGER.log(Level.FINER, "Spurious interrupt", e);
|
||||
// Users shouldn't try to interrupt the packet writer thread
|
||||
LOGGER.log(Level.WARNING, "Packet writer thread was interrupted. Don't do that. Use disconnect() instead.", e);
|
||||
}
|
||||
}
|
||||
return packet;
|
||||
|
|
Loading…
Reference in a new issue