mobile/android/base/sync/net/ConnectionMonitorThread.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/sync/net/ConnectionMonitorThread.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.sync.net;
     1.9 +
    1.10 +import org.mozilla.gecko.background.common.log.Logger;
    1.11 +
    1.12 +/**
    1.13 + * Every <code>REAP_INTERVAL</code> milliseconds, wake up
    1.14 + * and expire any connections that need cleaning up.
    1.15 + *
    1.16 + * When we're told to shut down, take the connection manager
    1.17 + * with us.
    1.18 + */
    1.19 +public class ConnectionMonitorThread extends Thread {
    1.20 +  private static final long REAP_INTERVAL = 5000;     // 5 seconds.
    1.21 +  private static final String LOG_TAG = "ConnectionMonitorThread";
    1.22 +
    1.23 +  private volatile boolean stopping;
    1.24 +
    1.25 +  @Override
    1.26 +  public void run() {
    1.27 +    try {
    1.28 +      while (!stopping) {
    1.29 +        synchronized (this) {
    1.30 +          wait(REAP_INTERVAL);
    1.31 +          BaseResource.closeExpiredConnections();
    1.32 +        }
    1.33 +      }
    1.34 +    } catch (InterruptedException e) {
    1.35 +      Logger.trace(LOG_TAG, "Interrupted.");
    1.36 +    }
    1.37 +    BaseResource.shutdownConnectionManager();
    1.38 +  }
    1.39 +
    1.40 +  public void shutdown() {
    1.41 +    Logger.debug(LOG_TAG, "ConnectionMonitorThread told to shut down.");
    1.42 +    stopping = true;
    1.43 +    synchronized (this) {
    1.44 +      notifyAll();
    1.45 +    }
    1.46 +  }
    1.47 +}

mercurial