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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.sync.net;
michael@0 6
michael@0 7 import org.mozilla.gecko.background.common.log.Logger;
michael@0 8
michael@0 9 /**
michael@0 10 * Every <code>REAP_INTERVAL</code> milliseconds, wake up
michael@0 11 * and expire any connections that need cleaning up.
michael@0 12 *
michael@0 13 * When we're told to shut down, take the connection manager
michael@0 14 * with us.
michael@0 15 */
michael@0 16 public class ConnectionMonitorThread extends Thread {
michael@0 17 private static final long REAP_INTERVAL = 5000; // 5 seconds.
michael@0 18 private static final String LOG_TAG = "ConnectionMonitorThread";
michael@0 19
michael@0 20 private volatile boolean stopping;
michael@0 21
michael@0 22 @Override
michael@0 23 public void run() {
michael@0 24 try {
michael@0 25 while (!stopping) {
michael@0 26 synchronized (this) {
michael@0 27 wait(REAP_INTERVAL);
michael@0 28 BaseResource.closeExpiredConnections();
michael@0 29 }
michael@0 30 }
michael@0 31 } catch (InterruptedException e) {
michael@0 32 Logger.trace(LOG_TAG, "Interrupted.");
michael@0 33 }
michael@0 34 BaseResource.shutdownConnectionManager();
michael@0 35 }
michael@0 36
michael@0 37 public void shutdown() {
michael@0 38 Logger.debug(LOG_TAG, "ConnectionMonitorThread told to shut down.");
michael@0 39 stopping = true;
michael@0 40 synchronized (this) {
michael@0 41 notifyAll();
michael@0 42 }
michael@0 43 }
michael@0 44 }

mercurial