Suppose that the timeout is defined to 30 seconds.
There is no way to cancel the nextResult(). I have to wait ~30 seconds to the call returns. Even if the connection is closed.
I my particular case, I want to interrupt the thread when the connection is closedOnError. But the ReconnectionManager starts another connection while the old thread is still waiting for nextResult().
PS: I could use the sendIqWithResponseCallback() call, but the nextResultOrThrow is used internally by Smack in a lot of cases.
Better than test if the connection is connected in the while clause is to check the connection and throw an NotConnectedException.
while (res == null && remainingWait > 0) {
if (!connection.isConnected()) {
throw new NotConnectedException();
}
try {
res = (P) resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS);
remainingWait = timeout - (System.currentTimeMillis() - waitStart);
} catch (InterruptedException e) {
LOGGER.log(Level.FINE, "nextResult was interrupted", e);
}
}
Wha do you think about that?