org.apache.commons.httpclient
Class MultiThreadedHttpConnectionManager

java.lang.Object
  extended by 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, 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
 
Constructor Summary
MultiThreadedHttpConnectionManager()
          No-args constructor
 
Method Summary
 void closeIdleConnections(long idleTimeout)
          Closes connections that have been idle for at least the given amount of time.
 void deleteClosedConnections()
          Deletes all closed connections.
 HttpConnection getConnection(HostConfiguration hostConfiguration)
          Gets an HttpConnection for a given host configuration.
 int getConnectionsInPool()
          Gets the total number of pooled connections.
 int getConnectionsInPool(HostConfiguration hostConfiguration)
          Gets the total number of pooled connections for the given host configuration.
 HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout)
          Gets an HttpConnection for a given host configuration.
 HttpConnectionManagerParams getParams()
          Returns parameters associated with this connection manager.
 void releaseConnection(HttpConnection conn)
          Make the given HttpConnection available for use by other requests.
 void setParams(HttpConnectionManagerParams params)
          Assigns parameters for this connection manager.
 void shutdown()
          Shuts down the connection manager and releases all resources.
static void shutdownAll()
          Shuts down and cleans up resources used by all instances of MultiThreadedHttpConnectionManager.
 
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
Constructor Detail

MultiThreadedHttpConnectionManager

public MultiThreadedHttpConnectionManager()
No-args constructor

Method Detail

shutdownAll

public static void shutdownAll()
Shuts down and cleans up resources used by all instances of MultiThreadedHttpConnectionManager. All static resources are released, all threads are stopped, and shutdown() is called on all live instances of MultiThreadedHttpConnectionManager.

See Also:
shutdown()

shutdown

public void shutdown()
Shuts down the connection manager and releases all resources. All connections associated with this class will be closed and released.

The connection manager can no longer be used once shutdown.

Calling this method more than once will have no effect.


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)

getConnectionWithTimeout

public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration,
                                               long timeout)
                                        throws ConnectionPoolTimeoutException
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:
getConnectionWithTimeout 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:
ConnectionPoolTimeoutException - if no connection becomes available before the timeout expires
Since:
3.0
See Also:
HttpConnectionManager.getConnectionWithTimeout(HostConfiguration, long)

getConnectionsInPool

public int getConnectionsInPool(HostConfiguration hostConfiguration)
Gets the total number of pooled connections for the given host configuration. This is the total number of connections that have been created and are still in use by this connection manager for the host configuration. This value will not exceed the maximum number of connections per host.

Parameters:
hostConfiguration - The host configuration
Returns:
The total number of pooled connections

getConnectionsInPool

public int getConnectionsInPool()
Gets the total number of pooled connections. This is the total number of connections that have been created and are still in use by this connection manager. This value will not exceed the maximum number of connections.

Returns:
the total number of pooled connections

deleteClosedConnections

public void deleteClosedConnections()
Deletes all closed connections. Only connections currently owned by the connection manager are processed.

Since:
3.0
See Also:
HttpConnection.isOpen()

closeIdleConnections

public void closeIdleConnections(long idleTimeout)
Description copied from interface: HttpConnectionManager
Closes connections that have been idle for at least the given amount of time. Only connections that are currently owned, not checked out, are subject to idle timeouts.

Specified by:
closeIdleConnections in interface HttpConnectionManager
Parameters:
idleTimeout -
Since:
3.0

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.

getParams

public HttpConnectionManagerParams getParams()
Returns parameters associated with this connection manager.

Specified by:
getParams in interface HttpConnectionManager
Returns:
all associated parameters
See Also:
HttpConnectionManagerParams

setParams

public void setParams(HttpConnectionManagerParams params)
Assigns parameters for this connection manager.

Specified by:
setParams in interface HttpConnectionManager
Parameters:
params - params to set
See Also:
HttpConnectionManagerParams


Copyright (c) 1999-2005 - Apache Software Foundation