org.apache.commons.httpclient
Class MultiThreadedHttpConnectionManager

java.lang.Object
  extended byorg.apache.commons.httpclient.MultiThreadedHttpConnectionManager
All Implemented Interfaces:
org.apache.commons.httpclient.HttpConnectionManager

public class MultiThreadedHttpConnectionManager
extends java.lang.Object
implements org.apache.commons.httpclient.HttpConnectionManager

Manages a set of HttpConnections for various HostConfigurations.

Since:
2.0
Author:
Michael Becke, Eric Johnson, Mike Bowler, Carl A. Dunham

Field Summary
static int DEFAULT_MAX_HOST_CONNECTIONS
          The default maximum number of connections allowed per host
static int DEFAULT_MAX_TOTAL_CONNECTIONS
          The default maximum number of connections allowed overall
static java.util.Map REFERENCE_TO_CONNECTION_SOURCE
          A mapping from Reference to ConnectionSource.
 
Constructor Summary
MultiThreadedHttpConnectionManager()
          No-args constructor
 
Method Summary
 HttpConnection getConnection(org.apache.commons.httpclient.HostConfiguration hostConfiguration)
           
 HttpConnection getConnection(org.apache.commons.httpclient.HostConfiguration hostConfiguration, long timeout)
           
 int getConnectionsInUse()
          Gets the total number of connections in use.
 int getConnectionsInUse(org.apache.commons.httpclient.HostConfiguration hostConfiguration)
          Gets the number of connections in use for this configuration.
 int getMaxConnectionsPerHost()
          Gets the maximum number of connections allowed for a given hostConfiguration.
 int getMaxTotalConnections()
          Gets the maximum number of connections allowed in the system.
 boolean isConnectionStaleCheckingEnabled()
          Gets the staleCheckingEnabled value to be set on HttpConnections that are created.
 void releaseConnection(HttpConnection conn)
          Make the given HttpConnection available for use by other requests.
 void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled)
          Sets the staleCheckingEnabled value to be set on HttpConnections that are created.
 void setMaxConnectionsPerHost(int maxHostConnections)
          Sets the maximum number of connections allowed for a given HostConfiguration.
 void setMaxTotalConnections(int maxTotalConnections)
          Sets the maximum number of connections allowed in the system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_HOST_CONNECTIONS

public static final int DEFAULT_MAX_HOST_CONNECTIONS
The default maximum number of connections allowed per host

See Also:
Constant Field Values

DEFAULT_MAX_TOTAL_CONNECTIONS

public static final int DEFAULT_MAX_TOTAL_CONNECTIONS
The default maximum number of connections allowed overall

See Also:
Constant Field Values

REFERENCE_TO_CONNECTION_SOURCE

public static final java.util.Map REFERENCE_TO_CONNECTION_SOURCE
A mapping from Reference to ConnectionSource. Used to reclaim resources when connections are lost to the garbage collector.

Constructor Detail

MultiThreadedHttpConnectionManager

public MultiThreadedHttpConnectionManager()
No-args constructor

Method Detail

isConnectionStaleCheckingEnabled

public boolean isConnectionStaleCheckingEnabled()
Gets the staleCheckingEnabled value to be set on HttpConnections that are created.

Returns:
true if stale checking will be enabled on HttpConections
See Also:
HttpConnection.isStaleCheckingEnabled()

setConnectionStaleCheckingEnabled

public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled)
Sets the staleCheckingEnabled value to be set on HttpConnections that are created.

Parameters:
connectionStaleCheckingEnabled - true if stale checking will be enabled on HttpConections
See Also:
HttpConnection.setStaleCheckingEnabled(boolean)

setMaxConnectionsPerHost

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

Parameters:
maxHostConnections - 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.

setMaxTotalConnections

public void setMaxTotalConnections(int maxTotalConnections)
Sets the maximum number of connections allowed in the system.

Parameters:
maxTotalConnections - the maximum number of connections allowed

getMaxTotalConnections

public int getMaxTotalConnections()
Gets the maximum number of connections allowed in the system.

Returns:
The maximum number of connections allowed

getConnection

public HttpConnection getConnection(org.apache.commons.httpclient.HostConfiguration hostConfiguration)
Specified by:
getConnection in interface org.apache.commons.httpclient.HttpConnectionManager
See Also:
HttpConnectionManager#getConnection(HostConfiguration)

getConnection

public HttpConnection getConnection(org.apache.commons.httpclient.HostConfiguration hostConfiguration,
                                    long timeout)
                             throws org.apache.commons.httpclient.HttpException
Specified by:
getConnection in interface org.apache.commons.httpclient.HttpConnectionManager
Throws:
org.apache.commons.httpclient.HttpException
See Also:
HttpConnectionManager#getConnection(HostConfiguration, long)

getConnectionsInUse

public int getConnectionsInUse(org.apache.commons.httpclient.HostConfiguration hostConfiguration)
Gets 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

getConnectionsInUse

public int getConnectionsInUse()
Gets the total number of connections in use.

Returns:
the total 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 org.apache.commons.httpclient.HttpConnectionManager
Parameters:
conn - the HttpConnection to make available.


Copyright © 2003-2004 Internet Archive. All Rights Reserved.