mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +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) {
|
catch (InterruptedException e) {
|
||||||
// We don't need to handle spurious interrupts, in the worst case, this will cause to
|
LOGGER.log(Level.FINE, "waiting for reconnection interrupted", e);
|
||||||
// reconnect a few seconds earlier, depending on how many (spurious) interrupts arrive while
|
break;
|
||||||
// sleep() is called.
|
|
||||||
LOGGER.log(Level.FINE, "Supurious interrupt", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ConnectionListener listener : connection.connectionListeners) {
|
||||||
|
listener.reconnectingIn(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Makes a reconnection attempt
|
// Makes a reconnection attempt
|
||||||
try {
|
try {
|
||||||
if (isReconnectionPossible(connection)) {
|
if (isReconnectionPossible(connection)) {
|
||||||
|
|
|
@ -248,7 +248,8 @@ public class Roster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
LOGGER.log(Level.FINE, "spurious interrupt", e);
|
LOGGER.log(Level.FINE, "interrupted", e);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
waitTime -= now - start;
|
waitTime -= now - start;
|
||||||
|
|
|
@ -201,7 +201,6 @@ public class DummyConnection extends AbstractXMPPConnection {
|
||||||
return (P) queue.poll(wait, TimeUnit.SECONDS);
|
return (P) queue.poll(wait, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
// TODO handle spurious interrupts
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ public class WaitForPacketListener implements PacketListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
// TODO better handling of spurious interrupts
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1216,9 +1216,11 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
|
throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
|
||||||
// If the method above did not throw, we have a spurious interrupt and we should try to enqueue the
|
// If the method above did not throw, then the sending thread was interrupted
|
||||||
// element again
|
// TODO in a later version of Smack the InterruptedException should be thrown to
|
||||||
LOGGER.log(Level.FINE, "Spurious interrupt", e);
|
// 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) {
|
catch (InterruptedException e) {
|
||||||
if (!queue.isShutdown()) {
|
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;
|
return packet;
|
||||||
|
|
Loading…
Reference in a new issue