michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.sync.net; michael@0: michael@0: import org.mozilla.gecko.background.common.log.Logger; michael@0: michael@0: /** michael@0: * Every REAP_INTERVAL milliseconds, wake up michael@0: * and expire any connections that need cleaning up. michael@0: * michael@0: * When we're told to shut down, take the connection manager michael@0: * with us. michael@0: */ michael@0: public class ConnectionMonitorThread extends Thread { michael@0: private static final long REAP_INTERVAL = 5000; // 5 seconds. michael@0: private static final String LOG_TAG = "ConnectionMonitorThread"; michael@0: michael@0: private volatile boolean stopping; michael@0: michael@0: @Override michael@0: public void run() { michael@0: try { michael@0: while (!stopping) { michael@0: synchronized (this) { michael@0: wait(REAP_INTERVAL); michael@0: BaseResource.closeExpiredConnections(); michael@0: } michael@0: } michael@0: } catch (InterruptedException e) { michael@0: Logger.trace(LOG_TAG, "Interrupted."); michael@0: } michael@0: BaseResource.shutdownConnectionManager(); michael@0: } michael@0: michael@0: public void shutdown() { michael@0: Logger.debug(LOG_TAG, "ConnectionMonitorThread told to shut down."); michael@0: stopping = true; michael@0: synchronized (this) { michael@0: notifyAll(); michael@0: } michael@0: } michael@0: }