org.apache.commons.httpclient

Class MultiThreadedHttpConnectionManager

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 intDEFAULT_MAX_HOST_CONNECTIONS
The default maximum number of connections allowed per host
static intDEFAULT_MAX_TOTAL_CONNECTIONS
The default maximum number of connections allowed overall
Constructor Summary
MultiThreadedHttpConnectionManager()
No-args constructor
Method Summary
voidcloseIdleConnections(long idleTimeout)
voiddeleteClosedConnections()
Deletes all closed connections.
HttpConnectiongetConnection(HostConfiguration hostConfiguration)
HttpConnectiongetConnection(HostConfiguration hostConfiguration, long timeout)
intgetConnectionsInPool(HostConfiguration hostConfiguration)
Gets the total number of pooled connections for the given host configuration.
intgetConnectionsInPool()
Gets the total number of pooled connections.
intgetConnectionsInUse(HostConfiguration hostConfiguration)
Gets the number of connections in use for this configuration.
intgetConnectionsInUse()
Gets the total number of connections in use.
HttpConnectiongetConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout)
intgetMaxConnectionsPerHost()
Gets the maximum number of connections allowed for a given hostConfiguration.
intgetMaxTotalConnections()
Gets the maximum number of connections allowed for this connection manager.
HttpConnectionManagerParamsgetParams()
Returns parameters associated with this connection manager.
booleanisConnectionStaleCheckingEnabled()
Gets the staleCheckingEnabled value to be set on HttpConnections that are created.
voidreleaseConnection(HttpConnection conn)
Make the given HttpConnection available for use by other requests.
voidsetConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled)
Sets the staleCheckingEnabled value to be set on HttpConnections that are created.
voidsetMaxConnectionsPerHost(int maxHostConnections)
Sets the maximum number of connections allowed for a given HostConfiguration.
voidsetMaxTotalConnections(int maxTotalConnections)
Sets the maximum number of connections allowed for this connection manager.
voidsetParams(HttpConnectionManagerParams params)
Assigns parameters for this connection manager.
voidshutdown()
Shuts down the connection manager and releases all resources.
static voidshutdownAll()
Shuts down and cleans up resources used by all instances of MultiThreadedHttpConnectionManager.

Field Detail

DEFAULT_MAX_HOST_CONNECTIONS

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

DEFAULT_MAX_TOTAL_CONNECTIONS

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

Constructor Detail

MultiThreadedHttpConnectionManager

public MultiThreadedHttpConnectionManager()
No-args constructor

Method Detail

closeIdleConnections

public void closeIdleConnections(long idleTimeout)

Since: 3.0

deleteClosedConnections

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

Since: 3.0

See Also:

getConnection

public HttpConnection getConnection(HostConfiguration hostConfiguration)

See Also: getConnection

getConnection

public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout)

Deprecated: Use #getConnectionWithTimeout(HostConfiguration, long)

See Also:

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

getConnectionsInUse

public int getConnectionsInUse(HostConfiguration hostConfiguration)

Deprecated: Use getConnectionsInPool

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()

Deprecated: Use getConnectionsInPool

Gets the total number of connections in use.

Returns: the total number of connections in use

getConnectionWithTimeout

public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout)

Since: 3.0

See Also:

getMaxConnectionsPerHost

public int getMaxConnectionsPerHost()

Deprecated: Use getDefaultMaxConnectionsPerHost, getParams.

Gets the maximum number of connections allowed for a given hostConfiguration.

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

getMaxTotalConnections

public int getMaxTotalConnections()

Deprecated: Use getMaxTotalConnections, getParams.

Gets the maximum number of connections allowed for this connection manager.

Returns: The maximum number of connections allowed

getParams

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

Since: 3.0

See Also: HttpConnectionManagerParams

isConnectionStaleCheckingEnabled

public boolean isConnectionStaleCheckingEnabled()

Deprecated: Use HttpConnectionManagerParams, getParams.

Gets the staleCheckingEnabled value to be set on HttpConnections that are created.

Returns: true if stale checking will be enabled on HttpConnections

See Also:

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.

Parameters: conn the HttpConnection to make available.

setConnectionStaleCheckingEnabled

public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled)

Deprecated: Use HttpConnectionManagerParams, getParams.

Sets the staleCheckingEnabled value to be set on HttpConnections that are created.

Parameters: connectionStaleCheckingEnabled true if stale checking will be enabled on HttpConnections

See Also:

setMaxConnectionsPerHost

public void setMaxConnectionsPerHost(int maxHostConnections)

Deprecated: Use HttpConnectionManagerParams, getParams.

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

setMaxTotalConnections

public void setMaxTotalConnections(int maxTotalConnections)

Deprecated: Use HttpConnectionManagerParams, getParams.

Sets the maximum number of connections allowed for this connection manager.

Parameters: maxTotalConnections the maximum number of connections allowed

setParams

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

Since: 3.0

See Also: HttpConnectionManagerParams

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.

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

Copyright (c) 1999-2005 - Apache Software Foundation