org.apache.commons.httpclient
Class MultiThreadedHttpConnectionManager

java.lang.Object
  |
  +--org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
All Implemented Interfaces:
HttpConnectionManager

public class MultiThreadedHttpConnectionManager
extends Object
implements HttpConnectionManager

Manages a set of HttpConnections for various HostConfigurations.

Since:
2.0
Author:
Michael Becke, Eric Johnson, Mike Bowler

Constructor Summary
MultiThreadedHttpConnectionManager()
          No-args constructor
 
Method Summary
 HttpConnection getConnection(HostConfiguration hostConfiguration)
          Gets an HttpConnection for a given host configuration.
 HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout)
          Gets an HttpConnection for a given host configuration.
 int getConnectionsInUse(HostConfiguration hostConfiguration)
          Get the number of connections in use for this configuration.
 int getMaxConnectionsPerHost()
          Gets the maximum number of connections allowed for a given hostConfiguration.
 void releaseConnection(HttpConnection conn)
          Make the given HttpConnection available for use by other requests.
 void setMaxConnectionsPerHost(int maxConnections)
          Sets the maximum number of connections allowed for a given HostConfiguration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiThreadedHttpConnectionManager

public MultiThreadedHttpConnectionManager()
No-args constructor

Method Detail

setMaxConnectionsPerHost

public void setMaxConnectionsPerHost(int maxConnections)
Sets the maximum number of connections allowed for a given HostConfiguration. Per RFC 2616 section 8.1.4, this value defaults to 2.

Parameters:
maxConnections - the number of connections allowed for each hostConfiguration

getMaxConnectionsPerHost

public int getMaxConnectionsPerHost()
Gets the maximum number of connections allowed for a given hostConfiguration.

Returns:
The maximum number of connections allowed for a given hostConfiguration.

getConnection

public HttpConnection getConnection(HostConfiguration hostConfiguration)
Description copied from interface: HttpConnectionManager
Gets an HttpConnection for a given host configuration. If a connection is not available this method will block until one is. The connection manager should be registered with any HttpConnection that is created.

Specified by:
getConnection in interface HttpConnectionManager
Parameters:
hostConfiguration - the host configuration to use to configure the connection
Returns:
an HttpConnection for the given configuration
See Also:
HttpConnectionManager.getConnection(HostConfiguration)

getConnection

public HttpConnection getConnection(HostConfiguration hostConfiguration,
                                    long timeout)
                             throws HttpException
Description copied from interface: HttpConnectionManager
Gets an HttpConnection for a given host configuration. If a connection is not available, this method will block for at most the specified number of milliseconds or until a connection becomes available. The connection manager should be registered with any HttpConnection that is created.

Specified by:
getConnection in interface HttpConnectionManager
Parameters:
hostConfiguration - the host configuration to use to configure the connection
timeout - - the time (in milliseconds) to wait for a connection to become available, 0 to specify an infinite timeout
Returns:
an HttpConnection for the given configuraiton
Throws:
HttpException - if no connection becomes available before the timeout expires
See Also:
HttpConnectionManager.getConnection(HostConfiguration, long)

getConnectionsInUse

public int getConnectionsInUse(HostConfiguration hostConfiguration)
Get the number of connections in use for this configuration.

Parameters:
hostConfiguration - the key that connections are tracked on
Returns:
the number of connections in use

releaseConnection

public void releaseConnection(HttpConnection conn)
Make the given HttpConnection available for use by other requests. If another thread is blocked in getConnection() that could use this connection, it will be woken up.

Specified by:
releaseConnection in interface HttpConnectionManager
Parameters:
conn - the HttpConnection to make available.


Copyright (c) 1999-2002 - Apache Software Foundation