mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +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:
parent
cd3692f329
commit
bfdcfba092
4 changed files with 30 additions and 4 deletions
|
@ -1466,7 +1466,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
// If the packetListener got removed, then it was never run and
|
// If the packetListener got removed, then it was never run and
|
||||||
// we never received a response, inform the exception callback
|
// we never received a response, inform the exception callback
|
||||||
if (removed && exceptionCallback != null) {
|
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);
|
}, timeout, TimeUnit.MILLISECONDS);
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.jivesoftware.smack;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||||
|
@ -199,8 +200,10 @@ public class PacketCollector {
|
||||||
* @throws XMPPErrorException in case an error response.
|
* @throws XMPPErrorException in case an error response.
|
||||||
* @throws NoResponseException if there was no response from the server.
|
* @throws NoResponseException if there was no response from the server.
|
||||||
* @throws InterruptedException
|
* @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());
|
return nextResultOrThrow(connection.getPacketReplyTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,11 +216,16 @@ public class PacketCollector {
|
||||||
* @throws NoResponseException if there was no response from the server.
|
* @throws NoResponseException if there was no response from the server.
|
||||||
* @throws XMPPErrorException in case an error response.
|
* @throws XMPPErrorException in case an error response.
|
||||||
* @throws InterruptedException
|
* @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);
|
P result = nextResult(timeout);
|
||||||
cancel();
|
cancel();
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
if (!connection.isConnected()) {
|
||||||
|
throw new NotConnectedException(connection, packetFilter);
|
||||||
|
}
|
||||||
throw NoResponseException.newWith(connection, this);
|
throw NoResponseException.newWith(connection, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,11 @@ public class SmackException extends Exception {
|
||||||
super("The connection " + connection.toString() + " is no longer connected. "
|
super("The connection " + connection.toString() + " is no longer connected. "
|
||||||
+ details);
|
+ 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 {
|
public static class IllegalStateChangeException extends SmackException {
|
||||||
|
|
|
@ -341,7 +341,13 @@ public final class Roster extends Manager {
|
||||||
connection.sendIqWithResponseCallback(packet, new RosterResultListener(), new ExceptionCallback() {
|
connection.sendIqWithResponseCallback(packet, new RosterResultListener(), new ExceptionCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void processException(Exception exception) {
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue