Filters out too frequent calls to KeepAliveSendTask on Android, when the Timer tries to catch up.

cusax-fix 5055
paweldomas 13 years ago
parent 7a109ca8f1
commit e6d2663d26

@ -187,12 +187,36 @@ public void processPacket(Packet packet)
private class KeepAliveSendTask
extends TimerTask
{
/**
* Minimal sleep interval between calls to this <tt>TimerTask</tt>.
*/
private final long MIN_WAKE_UP_INTERVAL = 5000L; // 5 sec
/**
* Remembers when it was woken up for the last time.
*/
private long lastWakeUp;
/**
* Sends a single <tt>KeepAliveEvent</tt>.
*/
@Override
public void run()
{
/**
* Timers on Android when CPU is sleeping can often sleep for too
* long and then they try to catch up doing rapid callbacks.
* The intention here is to filter out such calls.
*/
long sleepDuration = (System.currentTimeMillis() - lastWakeUp);
lastWakeUp = System.currentTimeMillis();
if(sleepDuration < MIN_WAKE_UP_INTERVAL)
{
logger.error( this + " woken up too early !");
return;
}
// if we are not registered do nothing
if(!parentProvider.isRegistered())
{

Loading…
Cancel
Save