From 5ef20aba2139bb3cee19e44cd5f953e32a20f1c8 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 28 Oct 2015 01:36:35 -0700 Subject: [PATCH] Decrease polling period and increase polls before declaring the machine offline. Try requesting the app list again every 2 seconds if the app list has not been received yet. --- .../computers/ComputerManagerService.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/limelight/computers/ComputerManagerService.java b/app/src/main/java/com/limelight/computers/ComputerManagerService.java index fb9aaef5..0ffd1a62 100644 --- a/app/src/main/java/com/limelight/computers/ComputerManagerService.java +++ b/app/src/main/java/com/limelight/computers/ComputerManagerService.java @@ -31,11 +31,12 @@ import android.os.IBinder; import org.xmlpull.v1.XmlPullParserException; public class ComputerManagerService extends Service { - private static final int SERVERINFO_POLLING_PERIOD_MS = 3000; + private static final int SERVERINFO_POLLING_PERIOD_MS = 1500; private static final int APPLIST_POLLING_PERIOD_MS = 30000; + private static final int APPLIST_FAILED_POLLING_RETRY_MS = 2000; private static final int MDNS_QUERY_PERIOD_MS = 1000; private static final int FAST_POLL_TIMEOUT = 500; - private static final int OFFLINE_POLL_TRIES = 3; + private static final int OFFLINE_POLL_TRIES = 5; private final ComputerManagerBinder binder = new ComputerManagerBinder(); @@ -139,7 +140,7 @@ public class ComputerManagerService extends Service { } // Wait until the next polling interval - Thread.sleep(SERVERINFO_POLLING_PERIOD_MS / ((offlineCount > 0) ? 2 : 1)); + Thread.sleep(SERVERINFO_POLLING_PERIOD_MS); } catch (InterruptedException e) { break; } @@ -612,6 +613,7 @@ public class ComputerManagerService extends Service { private Thread thread; private final ComputerDetails computer; private final Object pollEvent = new Object(); + private boolean receivedAppList = false; public ApplistPoller(ComputerDetails computer) { this.computer = computer; @@ -626,7 +628,15 @@ public class ComputerManagerService extends Service { private boolean waitPollingDelay() { try { synchronized (pollEvent) { - pollEvent.wait(APPLIST_POLLING_PERIOD_MS); + if (receivedAppList) { + // If we've already reported an app list successfully, + // wait the full polling period + pollEvent.wait(APPLIST_POLLING_PERIOD_MS); + } + else { + // If we've failed to get an app list so far, retry much earlier + pollEvent.wait(APPLIST_FAILED_POLLING_RETRY_MS); + } } } catch (InterruptedException e) { return false; @@ -713,6 +723,7 @@ public class ComputerManagerService extends Service { // Update the computer computer.rawAppList = appList; + receivedAppList = true; // Notify that the app list has been updated // and ensure that the thread is still active