1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-15 20:12:04 +01:00

Add PingManager.pingServerIfNecessary()

which is basically the body of the pingServerRunnable available as
public part of the API. The intention is to allow 3rd party
components (e.g. Android's AlarmManager) to trigger the code.
This commit is contained in:
Florian Schmaus 2014-09-08 10:07:01 +02:00
parent 184604bba2
commit 090f7cfc49

View file

@ -317,13 +317,14 @@ public class PingManager extends Manager {
} }
} }
private final Runnable pingServerRunnable = new Runnable() { /**
private static final int DELTA = 1000; // 1 seconds * Ping the server if deemed necessary because automatic server pings are
private static final int TRIES = 3; // 3 tries * enabled ({@link #setPingInterval(int)}) and the ping interval has expired.
*/
public void run() { public synchronized void pingServerIfNecessary() {
LOGGER.fine("ServerPingTask run()"); final int DELTA = 1000; // 1 seconds
XMPPConnection connection = connection(); final int TRIES = 3; // 3 tries
final XMPPConnection connection = connection();
if (connection == null) { if (connection == null) {
// connection has been collected by GC // connection has been collected by GC
// which means we can stop the thread by breaking the loop // which means we can stop the thread by breaking the loop
@ -369,7 +370,6 @@ public class PingManager extends Manager {
break; break;
} }
} }
LOGGER.fine("ServerPingTask res=" + res);
if (!res) { if (!res) {
for (PingFailedListener l : pingFailedListeners) { for (PingFailedListener l : pingFailedListeners) {
l.pingFailed(); l.pingFailed();
@ -379,9 +379,15 @@ public class PingManager extends Manager {
maybeSchedulePingServerTask(); maybeSchedulePingServerTask();
} }
} else { } else {
LOGGER.warning("ServerPingTask: XMPPConnection was not authenticated"); LOGGER.warning("XMPPConnection was not authenticated");
} }
} }
private final Runnable pingServerRunnable = new Runnable() {
public void run() {
LOGGER.fine("ServerPingTask run()");
pingServerIfNecessary();
}
}; };
@Override @Override