FileDocCategorySizeDatePackage
HttpConnectionManager.javaAPI DocAndroid 1.5 API7417Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.internal.net.www.protocol.http

HttpConnectionManager

public class HttpConnectionManager extends Object
HttpConnectionManager manages a pool of HttpConnections that are not currently in use and is used to get hold of persistent HttpConnections. Clients should return an HttpConnection to the pool after use by calling returnConnectionToPool Two system properties affect the behaviour of this class - http.maxConnections and http.keepAlive. http.keepAlive determines whether or not connections should be persisted and http.maxConnections determines the maximum number of connections to each individual host that should be kept in the pool.

Fields Summary
private static int
maxConnections
private static boolean
keepAlive
private static HttpConnectionManager
defaultConnectionManager
private ConnectionPool
pool
Constructors Summary
Methods Summary
private voidcheckSystemProperties()

        String httpMaxConnections =  AccessController.doPrivileged(new PriviAction<String>("http.maxConnections"));
        String httpKeepAlive = AccessController.doPrivileged(new PriviAction<String>("http.keepAlive"));
        if(httpMaxConnections != null) {
            maxConnections = Integer.parseInt(httpMaxConnections);
        }
        if(httpKeepAlive != null) {
            keepAlive = Boolean.parseBoolean(httpKeepAlive);
            if(!keepAlive) {
                pool.clear();
            }
        }
    
public HttpConnectiongetConnection(java.net.URI uri, int connectTimeout)

        checkSystemProperties();
        HttpConfiguration config = new HttpConfiguration(uri);
        return pool.getHttpConnection(config, connectTimeout);
    
public HttpConnectiongetConnection(java.net.URI uri, java.net.Proxy proxy, int connectTimeout)

        checkSystemProperties();
        HttpConfiguration config = new HttpConfiguration(uri, proxy);
        return pool.getHttpConnection(config, connectTimeout);
    
public static org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManagergetDefault()
Returns the default connection manager


              
        
        if(defaultConnectionManager == null) {
            defaultConnectionManager = new HttpConnectionManager();
        }
        return defaultConnectionManager;
    
public intnumFreeConnections()

        return pool.numFreeConnections();
    
public voidreset()

        pool.clear();
    
public voidreturnConnectionToPool(HttpConnection connection)

        checkSystemProperties();
        pool.returnConnection(connection);