Search in sources :

Example 11 with HttpConnection

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);
            }
        }
    }
}
Also used : HttpConnection(org.apache.http.HttpConnection) IOException(java.io.IOException)

Example 12 with HttpConnection

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);
            }
        }
    }
}
Also used : HttpConnection(org.apache.http.HttpConnection) IOException(java.io.IOException)

Aggregations

HttpConnection (org.apache.http.HttpConnection)12 IOException (java.io.IOException)6 ProtocolVersion (org.apache.http.ProtocolVersion)6 InetAddress (java.net.InetAddress)3 HeaderIterator (org.apache.http.HeaderIterator)3 HttpEntity (org.apache.http.HttpEntity)3 HttpHost (org.apache.http.HttpHost)3 HttpInetConnection (org.apache.http.HttpInetConnection)3 ParseException (org.apache.http.ParseException)3 ProtocolException (org.apache.http.ProtocolException)3 TokenIterator (org.apache.http.TokenIterator)3 BasicTokenIterator (org.apache.http.message.BasicTokenIterator)3