mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 03:52:06 +01:00
Add 'resumed' bool ConnectionListener's authenticated()
It's important to know if the stream was resumed. authenticated() is the ideal callback for Managers to reset their state (e.g. cached values of the connection state). But if the stream was resumed, the cached values don't have to be reset.
This commit is contained in:
parent
3dd1365a5a
commit
e380872a41
10 changed files with 38 additions and 20 deletions
|
@ -31,7 +31,7 @@ public class AbstractConnectionListener implements ConnectionListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
|
|
@ -500,7 +500,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
if (config.isDebuggerEnabled() && debugger != null) {
|
||||
debugger.userHasLogged(user);
|
||||
}
|
||||
callConnectionAuthenticatedListener();
|
||||
callConnectionAuthenticatedListener(resumed);
|
||||
|
||||
// Set presence to online. It is important that this is done after
|
||||
// callConnectionAuthenticatedListener(), as this call will also
|
||||
|
@ -1040,9 +1040,15 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
protected void callConnectionAuthenticatedListener() {
|
||||
protected void callConnectionAuthenticatedListener(boolean resumed) {
|
||||
for (ConnectionListener listener : getConnectionListeners()) {
|
||||
listener.authenticated(this);
|
||||
try {
|
||||
listener.authenticated(this, resumed);
|
||||
} catch (Exception e) {
|
||||
// Catch and print any exception so we can recover
|
||||
// from a faulty listener and finish the shutdown process
|
||||
LOGGER.log(Level.SEVERE, "Exception in authenticated listener", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public interface ConnectionListener {
|
|||
* TODO
|
||||
* @param connection
|
||||
*/
|
||||
public void authenticated(XMPPConnection connection);
|
||||
public void authenticated(XMPPConnection connection, boolean resumed);
|
||||
|
||||
/**
|
||||
* Notification that the connection was closed normally or that the reconnection
|
||||
|
|
|
@ -264,7 +264,7 @@ public class ReconnectionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
done = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ public class Roster {
|
|||
connection.addConnectionListener(new AbstractConnectionClosedListener() {
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
// Anonymous users can't have a roster, but it is possible that a Roster instance is
|
||||
// retrieved if getRoster() is called *before* connect(). So we have to check here
|
||||
// again if it's an anonymous connection.
|
||||
|
@ -146,6 +146,10 @@ public class Roster {
|
|||
return;
|
||||
if (!connection.isRosterLoadedAtLogin())
|
||||
return;
|
||||
// We are done here if the connection was resumed
|
||||
if (resumed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Roster.this.reload();
|
||||
}
|
||||
|
|
|
@ -80,8 +80,12 @@ public abstract class AbstractDebugger implements SmackDebugger {
|
|||
log("XMPPConnection connected ("
|
||||
+ connection.getConnectionCounter() + ")");
|
||||
}
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
log("XMPPConnection authenticated (" + connection.getConnectionCounter() + ")");
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
String logString = "XMPPConnection authenticated (" + connection.getConnectionCounter() + ")";
|
||||
if (resumed) {
|
||||
logString += " and resumed";
|
||||
}
|
||||
log(logString);
|
||||
}
|
||||
public void connectionClosed() {
|
||||
log(
|
||||
|
|
|
@ -36,7 +36,7 @@ class SLF4JLoggingConnectionListener implements ConnectionListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
logger.debug("({}) Connection authenticated as {}", connection.hashCode(), connection.getUser());
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.caps;
|
||||
|
||||
import org.jivesoftware.smack.AbstractConnectionClosedListener;
|
||||
import org.jivesoftware.smack.AbstractConnectionListener;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
@ -274,7 +274,7 @@ public class EntityCapsManager extends Manager {
|
|||
this.sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
instances.put(connection, this);
|
||||
|
||||
connection.addConnectionListener(new AbstractConnectionClosedListener() {
|
||||
connection.addConnectionListener(new AbstractConnectionListener() {
|
||||
@Override
|
||||
public void connected(XMPPConnection connection) {
|
||||
// It's not clear when a server would report the caps stream
|
||||
|
@ -283,17 +283,17 @@ public class EntityCapsManager extends Manager {
|
|||
processCapsStreamFeatureIfAvailable(connection);
|
||||
}
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
// It's not clear when a server would report the caps stream
|
||||
// feature, so we try to process it after we are connected and
|
||||
// once after we are authenticated.
|
||||
processCapsStreamFeatureIfAvailable(connection);
|
||||
}
|
||||
@Override
|
||||
public void connectionTerminated() {
|
||||
presenceSend = false;
|
||||
}
|
||||
|
||||
// Reset presenceSend when the connection was not resumed
|
||||
if (!resumed) {
|
||||
presenceSend = false;
|
||||
}
|
||||
}
|
||||
private void processCapsStreamFeatureIfAvailable(XMPPConnection connection) {
|
||||
CapsExtension capsExtension = connection.getFeature(
|
||||
CapsExtension.ELEMENT, CapsExtension.NAMESPACE);
|
||||
|
|
|
@ -137,7 +137,7 @@ public class PingManager extends Manager {
|
|||
}, PING_PACKET_FILTER);
|
||||
connection.addConnectionListener(new AbstractConnectionClosedListener() {
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
maybeSchedulePingServerTask();
|
||||
}
|
||||
@Override
|
||||
|
|
|
@ -186,7 +186,11 @@ public class PrivacyListManager extends Manager {
|
|||
}, PRIVACY_RESULT);
|
||||
connection.addConnectionListener(new AbstractConnectionListener() {
|
||||
@Override
|
||||
public void reconnectionSuccessful() {
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
// No need to reset the cache if the connection got resumed.
|
||||
if (resumed) {
|
||||
return;
|
||||
}
|
||||
cachedActiveListName = cachedDefaultListName = null;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue