use of org.apache.http.HttpConnection in project platform_external_apache-http by android.
the class IdleConnectionHandler method closeExpiredConnections.
public void closeExpiredConnections() {
long now = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug("Checking for expired connections, now: " + now);
}
Iterator<HttpConnection> connectionIter = connectionToTimes.keySet().iterator();
while (connectionIter.hasNext()) {
HttpConnection conn = connectionIter.next();
TimeValues times = connectionToTimes.get(conn);
if (times.timeExpires <= now) {
if (log.isDebugEnabled()) {
log.debug("Closing connection, expired @: " + times.timeExpires);
}
connectionIter.remove();
try {
conn.close();
} catch (IOException ex) {
log.debug("I/O error closing connection", ex);
}
}
}
}
use of org.apache.http.HttpConnection in project platform_external_apache-http by android.
the class IdleConnectionHandler method closeIdleConnections.
/**
* Closes connections that have been idle for at least the given amount of time.
*
* @param idleTime the minimum idle time, in milliseconds, for connections to be closed
*/
//@@@ add TimeUnit argument here?
public void closeIdleConnections(long idleTime) {
// the latest time for which connections will be closed
long idleTimeout = System.currentTimeMillis() - idleTime;
if (log.isDebugEnabled()) {
log.debug("Checking for connections, idleTimeout: " + idleTimeout);
}
Iterator<HttpConnection> connectionIter = connectionToTimes.keySet().iterator();
while (connectionIter.hasNext()) {
HttpConnection conn = connectionIter.next();
TimeValues times = connectionToTimes.get(conn);
Long connectionTime = times.timeAdded;
if (connectionTime.longValue() <= idleTimeout) {
if (log.isDebugEnabled()) {
log.debug("Closing connection, connection time: " + connectionTime);
}
connectionIter.remove();
try {
conn.close();
} catch (IOException ex) {
log.debug("I/O error closing connection", ex);
}
}
}
}
Aggregations