Make the next server ping code easier to read

This commit is contained in:
Florian Schmaus 2014-08-20 10:44:02 +02:00
parent e16997eb9d
commit b9b43ad5d7
1 changed files with 6 additions and 6 deletions

View File

@ -301,7 +301,7 @@ public class PingManager extends Manager {
* Cancels any existing periodic ping task if there is one and schedules a new ping task if * Cancels any existing periodic ping task if there is one and schedules a new ping task if
* pingInterval is greater then zero. * pingInterval is greater then zero.
* *
* @param delta the delta to the last received ping in seconds * @param delta the delta to the last received stanza in seconds
*/ */
private synchronized void maybeSchedulePingServerTask(int delta) { private synchronized void maybeSchedulePingServerTask(int delta) {
maybeStopPingServerTask(); maybeStopPingServerTask();
@ -339,11 +339,11 @@ public class PingManager extends Manager {
long lastStanzaReceived = connection.getLastStanzaReceived(); long lastStanzaReceived = connection.getLastStanzaReceived();
if (lastStanzaReceived > 0) { if (lastStanzaReceived > 0) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
// Calculate the delta from now to the next ping time. If delta is positive, the // Delta since the last stanza was received
// last successful ping was not to long ago, so we can defer the current ping. int deltaInSeconds = (int) ((now - lastStanzaReceived) / 1000);
int delta = (int) (((pingInterval * 1000) - (now - lastStanzaReceived)) / 1000); // If the delta is small then the ping interval, then we can defer the ping
if (delta > 0) { if (deltaInSeconds < pingInterval) {
maybeSchedulePingServerTask(delta); maybeSchedulePingServerTask(deltaInSeconds);
return; return;
} }
} }