1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +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:
Florian Schmaus 2015-01-07 20:19:04 +01:00
parent 3dd1365a5a
commit e380872a41
10 changed files with 38 additions and 20 deletions

View file

@ -31,7 +31,7 @@ public class AbstractConnectionListener implements ConnectionListener {
} }
@Override @Override
public void authenticated(XMPPConnection connection) { public void authenticated(XMPPConnection connection, boolean resumed) {
// do nothing // do nothing
} }

View file

@ -500,7 +500,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
if (config.isDebuggerEnabled() && debugger != null) { if (config.isDebuggerEnabled() && debugger != null) {
debugger.userHasLogged(user); debugger.userHasLogged(user);
} }
callConnectionAuthenticatedListener(); callConnectionAuthenticatedListener(resumed);
// Set presence to online. It is important that this is done after // Set presence to online. It is important that this is done after
// callConnectionAuthenticatedListener(), as this call will also // 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()) { 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);
}
} }
} }

View file

@ -38,7 +38,7 @@ public interface ConnectionListener {
* TODO * TODO
* @param connection * @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 * Notification that the connection was closed normally or that the reconnection

View file

@ -264,7 +264,7 @@ public class ReconnectionManager {
} }
@Override @Override
public void authenticated(XMPPConnection connection) { public void authenticated(XMPPConnection connection, boolean resumed) {
done = false; done = false;
} }

View file

@ -138,7 +138,7 @@ public class Roster {
connection.addConnectionListener(new AbstractConnectionClosedListener() { connection.addConnectionListener(new AbstractConnectionClosedListener() {
@Override @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 // 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 // retrieved if getRoster() is called *before* connect(). So we have to check here
// again if it's an anonymous connection. // again if it's an anonymous connection.
@ -146,6 +146,10 @@ public class Roster {
return; return;
if (!connection.isRosterLoadedAtLogin()) if (!connection.isRosterLoadedAtLogin())
return; return;
// We are done here if the connection was resumed
if (resumed) {
return;
}
try { try {
Roster.this.reload(); Roster.this.reload();
} }

View file

@ -80,8 +80,12 @@ public abstract class AbstractDebugger implements SmackDebugger {
log("XMPPConnection connected (" log("XMPPConnection connected ("
+ connection.getConnectionCounter() + ")"); + connection.getConnectionCounter() + ")");
} }
public void authenticated(XMPPConnection connection) { public void authenticated(XMPPConnection connection, boolean resumed) {
log("XMPPConnection authenticated (" + connection.getConnectionCounter() + ")"); String logString = "XMPPConnection authenticated (" + connection.getConnectionCounter() + ")";
if (resumed) {
logString += " and resumed";
}
log(logString);
} }
public void connectionClosed() { public void connectionClosed() {
log( log(

View file

@ -36,7 +36,7 @@ class SLF4JLoggingConnectionListener implements ConnectionListener {
} }
@Override @Override
public void authenticated(XMPPConnection connection) { public void authenticated(XMPPConnection connection, boolean resumed) {
logger.debug("({}) Connection authenticated as {}", connection.hashCode(), connection.getUser()); logger.debug("({}) Connection authenticated as {}", connection.hashCode(), connection.getUser());
} }

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smackx.caps; 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.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -274,7 +274,7 @@ public class EntityCapsManager extends Manager {
this.sdm = ServiceDiscoveryManager.getInstanceFor(connection); this.sdm = ServiceDiscoveryManager.getInstanceFor(connection);
instances.put(connection, this); instances.put(connection, this);
connection.addConnectionListener(new AbstractConnectionClosedListener() { connection.addConnectionListener(new AbstractConnectionListener() {
@Override @Override
public void connected(XMPPConnection connection) { public void connected(XMPPConnection connection) {
// It's not clear when a server would report the caps stream // It's not clear when a server would report the caps stream
@ -283,17 +283,17 @@ public class EntityCapsManager extends Manager {
processCapsStreamFeatureIfAvailable(connection); processCapsStreamFeatureIfAvailable(connection);
} }
@Override @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 // It's not clear when a server would report the caps stream
// feature, so we try to process it after we are connected and // feature, so we try to process it after we are connected and
// once after we are authenticated. // once after we are authenticated.
processCapsStreamFeatureIfAvailable(connection); 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) { private void processCapsStreamFeatureIfAvailable(XMPPConnection connection) {
CapsExtension capsExtension = connection.getFeature( CapsExtension capsExtension = connection.getFeature(
CapsExtension.ELEMENT, CapsExtension.NAMESPACE); CapsExtension.ELEMENT, CapsExtension.NAMESPACE);

View file

@ -137,7 +137,7 @@ public class PingManager extends Manager {
}, PING_PACKET_FILTER); }, PING_PACKET_FILTER);
connection.addConnectionListener(new AbstractConnectionClosedListener() { connection.addConnectionListener(new AbstractConnectionClosedListener() {
@Override @Override
public void authenticated(XMPPConnection connection) { public void authenticated(XMPPConnection connection, boolean resumed) {
maybeSchedulePingServerTask(); maybeSchedulePingServerTask();
} }
@Override @Override

View file

@ -186,7 +186,11 @@ public class PrivacyListManager extends Manager {
}, PRIVACY_RESULT); }, PRIVACY_RESULT);
connection.addConnectionListener(new AbstractConnectionListener() { connection.addConnectionListener(new AbstractConnectionListener() {
@Override @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; cachedActiveListName = cachedDefaultListName = null;
} }
}); });