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();
if (ServerPingWithAlarmManager.getInstanceFor(connection).isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection "
+ connection.getConnectionCounter());
+ connection);
final PingManager pingManager = PingManager.getInstanceFor(connection);
// Android BroadcastReceivers have a timeout of 60 seconds.
// The connections reply timeout may be higher, which causes

View File

@ -1303,8 +1303,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
protected void finalize() throws Throwable {
LOGGER.fine("finalizing XMPPConnection ( " + getConnectionCounter()
+ "): Shutting down executor services");
LOGGER.fine("finalizing " + this + ": Shutting down executor services");
try {
// 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
@ -1569,6 +1568,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
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) {
cachedExecutorService.execute(runnable);
}

View File

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

View File

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