org.apache.commons.httpclient
Class HttpConnectionManager

java.lang.Object
  |
  +--org.apache.commons.httpclient.HttpConnectionManager

public class HttpConnectionManager
extends java.lang.Object

Manages a set of HttpConnections for various host:ports. This class is used by HttpMultiClient.

Author:
Marc A. Saegesser

Constructor Summary
HttpConnectionManager()
          No-args constructor
 
Method Summary
 HttpConnection getConnection(java.lang.String sURL)
          Get an HttpConnection for a given URL.
 HttpConnection getConnection(java.lang.String sURL, long timeout)
          Get an HttpConnection for a given URL.
 java.lang.Integer getConnectionsInUse(java.lang.String hostAndPort)
          Get the number of connections in use for the key
 int getMaxConnectionsPerHost()
          Get the maximum number of connections allowed for a given host:port.
 java.lang.String getProxyHost()
          Get the proxy host.
 int getProxyPort()
          Get the proxy port number.
 void releaseConnection(HttpConnection conn)
          Make the given HttpConnection available for use by other requests.
 void setMaxConnectionsPerHost(int maxConnections)
          Set the maximum number of connections allowed for a given host:port.
 void setProxyHost(java.lang.String proxyHost)
          Set the proxy host to use for all connections.
 void setProxyPort(int proxyPort)
          Set the proxy port to use for all connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpConnectionManager

public HttpConnectionManager()
No-args constructor
Method Detail

setProxyHost

public void setProxyHost(java.lang.String proxyHost)
Set the proxy host to use for all connections.
Parameters:
proxyHost - - the proxy host name

getProxyHost

public java.lang.String getProxyHost()
Get the proxy host.
Returns:
the proxy host name

setProxyPort

public void setProxyPort(int proxyPort)
Set the proxy port to use for all connections.
Parameters:
proxyPort - - the proxy port number

getProxyPort

public int getProxyPort()
Get the proxy port number.
Returns:
the proxy port number

setMaxConnectionsPerHost

public void setMaxConnectionsPerHost(int maxConnections)
Set the maximum number of connections allowed for a given host:port. Per RFC 2616 section 8.1.4, this value defaults to 2.
Parameters:
maxConnections - - number of connections allowed for each host:port

getMaxConnectionsPerHost

public int getMaxConnectionsPerHost()
Get the maximum number of connections allowed for a given host:port.
Returns:
The maximum number of connections allowed for a given host:port.

getConnection

public HttpConnection getConnection(java.lang.String sURL)
                             throws HttpException,
                                    java.net.MalformedURLException
Get an HttpConnection for a given URL. The URL must be fully specified (i.e. contain a protocol and a host (and optional port number). If the maximum number of connections for the host has been reached, this method will block forever until a connection becomes available.
Parameters:
sURL - - a fully specified URL.
Returns:
an HttpConnection for the given host:port
Throws:
java.net.MalformedURLException -  
HttpException - - If no connection becomes available before the timeout expires

getConnection

public HttpConnection getConnection(java.lang.String sURL,
                                    long timeout)
                             throws HttpException,
                                    java.net.MalformedURLException
Get an HttpConnection for a given URL. The URL must be fully specified (i.e. contain a protocol and a host (and optional port number). If the maximum number of connections for the host has been reached, this method will block for timeout milliseconds or until a connection becomes available. If no connection becomes available before the timeout expires an HttpException exception will be thrown.
Parameters:
sURL - - a fully specified URL.
timeout - - the time (in milliseconds) to wait for a connection to become available
Returns:
an HttpConnection for the given host:port
Throws:
java.net.MalformedURLException -  
HttpException - - If no connection becomes available before the timeout expires

getConnectionsInUse

public java.lang.Integer getConnectionsInUse(java.lang.String hostAndPort)
Get the number of connections in use for the key
Parameters:
hostAndPort - the key that connections are tracked on
Returns:
the number of connections in use for the given key

releaseConnection

public void releaseConnection(HttpConnection conn)
Make the given HttpConnection available for use by other requests. If another thread is blocked in getConnection() waiting for a connection for this host:port, they will be woken up.
Parameters:
conn - - The HttpConnection to make available.


Copyright (c) 2001 - Apache Software Foundation