1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

Throw NotConnectedException instead of NoResponseException

if the connection is not connected in sendStanzaWithResponseCallback and
in PacketCollector.

Also decrease log level if roster result listener's exeption callback is
invoked with a NotConnectedException.
This commit is contained in:
Florian Schmaus 2015-07-03 12:57:30 +02:00
parent cd3692f329
commit bfdcfba092
4 changed files with 30 additions and 4 deletions

View file

@ -1466,7 +1466,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// If the packetListener got removed, then it was never run and
// we never received a response, inform the exception callback
if (removed && exceptionCallback != null) {
exceptionCallback.processException(NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter));
Exception exception;
if (!isConnected()) {
// If the connection is no longer connected, throw a not connected exception.
exception = new NotConnectedException(AbstractXMPPConnection.this, replyFilter);
} else {
exception = NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter);
}
exceptionCallback.processException(exception);
}
}
}, timeout, TimeUnit.MILLISECONDS);

View file

@ -20,6 +20,7 @@ package org.jivesoftware.smack;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.StanzaFilter;
@ -199,8 +200,10 @@ public class PacketCollector {
* @throws XMPPErrorException in case an error response.
* @throws NoResponseException if there was no response from the server.
* @throws InterruptedException
* @throws NotConnectedException
*/
public <P extends Stanza> P nextResultOrThrow() throws NoResponseException, XMPPErrorException, InterruptedException {
public <P extends Stanza> P nextResultOrThrow() throws NoResponseException, XMPPErrorException,
InterruptedException, NotConnectedException {
return nextResultOrThrow(connection.getPacketReplyTimeout());
}
@ -213,11 +216,16 @@ public class PacketCollector {
* @throws NoResponseException if there was no response from the server.
* @throws XMPPErrorException in case an error response.
* @throws InterruptedException
* @throws NotConnectedException
*/
public <P extends Stanza> P nextResultOrThrow(long timeout) throws NoResponseException, XMPPErrorException, InterruptedException {
public <P extends Stanza> P nextResultOrThrow(long timeout) throws NoResponseException,
XMPPErrorException, InterruptedException, NotConnectedException {
P result = nextResult(timeout);
cancel();
if (result == null) {
if (!connection.isConnected()) {
throw new NotConnectedException(connection, packetFilter);
}
throw NoResponseException.newWith(connection, this);
}

View file

@ -171,6 +171,11 @@ public class SmackException extends Exception {
super("The connection " + connection.toString() + " is no longer connected. "
+ details);
}
public NotConnectedException(XMPPConnection connection, StanzaFilter stanzaFilter) {
super("The connection " + connection
+ " is no longer connected while waiting for response with " + stanzaFilter);
}
}
public static class IllegalStateChangeException extends SmackException {

View file

@ -341,7 +341,13 @@ public final class Roster extends Manager {
connection.sendIqWithResponseCallback(packet, new RosterResultListener(), new ExceptionCallback() {
@Override
public void processException(Exception exception) {
LOGGER.log(Level.SEVERE, "Exception reloading roster" , exception);
Level logLevel;
if (exception instanceof NotConnectedException) {
logLevel = Level.FINE;
} else {
logLevel = Level.SEVERE;
}
LOGGER.log(logLevel, "Exception reloading roster" , exception);
}
});
}