Add AbstractXMPPConnection.toString()

This commit is contained in:
Florian Schmaus 2015-04-22 09:28:30 +02:00
parent bfb3f5cd95
commit 7c3f4b7129
4 changed files with 17 additions and 11 deletions

View File

@ -115,7 +115,7 @@ public final class ServerPingWithAlarmManager extends Manager {
XMPPConnection connection = it.next(); XMPPConnection connection = it.next();
if (ServerPingWithAlarmManager.getInstanceFor(connection).isEnabled()) { if (ServerPingWithAlarmManager.getInstanceFor(connection).isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection " LOGGER.fine("Calling pingServerIfNecessary for connection "
+ connection.getConnectionCounter()); + connection);
final PingManager pingManager = PingManager.getInstanceFor(connection); final PingManager pingManager = PingManager.getInstanceFor(connection);
// Android BroadcastReceivers have a timeout of 60 seconds. // Android BroadcastReceivers have a timeout of 60 seconds.
// The connections reply timeout may be higher, which causes // The connections reply timeout may be higher, which causes

View File

@ -1303,8 +1303,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
LOGGER.fine("finalizing XMPPConnection ( " + getConnectionCounter() LOGGER.fine("finalizing " + this + ": Shutting down executor services");
+ "): Shutting down executor services");
try { try {
// It's usually not a good idea to rely on finalize. But this is the easiest way to // It's usually not a good idea to rely on finalize. But this is the easiest way to
// avoid the "Smack Listener Processor" leaking. The thread(s) of the executor have a // avoid the "Smack Listener Processor" leaking. The thread(s) of the executor have a
@ -1569,6 +1568,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return parsingExceptionCallback; return parsingExceptionCallback;
} }
@Override
public final String toString() {
FullJid localEndpoint = getUser();
String localEndpointString = (localEndpoint == null ? "not-authenticated" : localEndpoint.toString());
return getClass().getSimpleName() + '[' + localEndpointString + "] (" + getConnectionCounter() + ')';
}
protected final void asyncGo(Runnable runnable) { protected final void asyncGo(Runnable runnable) {
cachedExecutorService.execute(runnable); cachedExecutorService.execute(runnable);
} }

View File

@ -78,10 +78,10 @@ public abstract class AbstractDebugger implements SmackDebugger {
connListener = new ConnectionListener() { connListener = new ConnectionListener() {
public void connected(XMPPConnection connection) { public void connected(XMPPConnection connection) {
log("XMPPConnection connected (" log("XMPPConnection connected ("
+ connection.getConnectionCounter() + ")"); + connection + ")");
} }
public void authenticated(XMPPConnection connection, boolean resumed) { public void authenticated(XMPPConnection connection, boolean resumed) {
String logString = "XMPPConnection authenticated (" + connection.getConnectionCounter() + ")"; String logString = "XMPPConnection authenticated (" + connection + ")";
if (resumed) { if (resumed) {
logString += " and resumed"; logString += " and resumed";
} }
@ -90,32 +90,32 @@ public abstract class AbstractDebugger implements SmackDebugger {
public void connectionClosed() { public void connectionClosed() {
log( log(
"XMPPConnection closed (" + "XMPPConnection closed (" +
connection.getConnectionCounter() + connection +
")"); ")");
} }
public void connectionClosedOnError(Exception e) { public void connectionClosedOnError(Exception e) {
log( log(
"XMPPConnection closed due to an exception (" + "XMPPConnection closed due to an exception (" +
connection.getConnectionCounter() + connection +
")", e); ")", e);
} }
public void reconnectionFailed(Exception e) { public void reconnectionFailed(Exception e) {
log( log(
"Reconnection failed due to an exception (" + "Reconnection failed due to an exception (" +
connection.getConnectionCounter() + connection +
")", e); ")", e);
} }
public void reconnectionSuccessful() { public void reconnectionSuccessful() {
log( log(
"XMPPConnection reconnected (" + "XMPPConnection reconnected (" +
connection.getConnectionCounter() + connection +
")"); ")");
} }
public void reconnectingIn(int seconds) { public void reconnectingIn(int seconds) {
log( log(
"XMPPConnection (" + "XMPPConnection (" +
connection.getConnectionCounter() + connection +
") will reconnect in " + seconds); ") will reconnect in " + seconds);
} }
}; };

View File

@ -454,7 +454,7 @@ public class SmackIntegrationTestFramework {
try { try {
AccountManager.getInstance(connections[i]).deleteAccount(); AccountManager.getInstance(connections[i]).deleteAccount();
LOGGER.info("Successfully deleted account for connection (" LOGGER.info("Successfully deleted account for connection ("
+ connections[i].getConnectionCounter() + ')'); + connections[i] + ')');
} }
catch (NoResponseException | XMPPErrorException | NotConnectedException catch (NoResponseException | XMPPErrorException | NotConnectedException
| InterruptedException e) { | InterruptedException e) {