org.apache.http.impl.conn
Class ThreadSafeClientConnManager

java.lang.Object
  extended by org.apache.http.impl.conn.ThreadSafeClientConnManager
All Implemented Interfaces:
ClientConnectionManager

public class ThreadSafeClientConnManager
extends java.lang.Object
implements ClientConnectionManager

Manages a pool of client connections.

This class is derived from MultiThreadedHttpConnectionManager in HttpClient 3. See there for original authors.

Since:
4.0
Version:
$Revision: 534769 $ $Date: 2007-05-03 11:51:22 +0200 (Thu, 03 May 2007) $
Author:
Roland Weber, Michael Becke

Field Summary
protected  SchemeRegistry schemeRegistry
          The schemes supported by this connection manager.
 
Constructor Summary
ThreadSafeClientConnManager(org.apache.http.params.HttpParams params, SchemeRegistry schreg)
          Creates a new thread safe connection manager.
 
Method Summary
 void closeIdleConnections(long idleTimeout)
          Deletes all free connections that are idle or closed.
protected  ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg)
          Hook for creating the connection operator.
 ManagedClientConnection getConnection(HttpRoute route)
          Obtains a connection.
 ManagedClientConnection getConnection(HttpRoute route, long timeout)
          Obtains a connection within a given time.
 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.
 org.apache.http.params.HttpParams getParams()
          Returns parameters associated with this connection manager.
 SchemeRegistry getSchemeRegistry()
           
 void releaseConnection(ManagedClientConnection conn)
          Releases an allocated connection.
 void setParams(org.apache.http.params.HttpParams 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 ThreadSafeClientConnManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schemeRegistry

protected SchemeRegistry schemeRegistry
The schemes supported by this connection manager.

Constructor Detail

ThreadSafeClientConnManager

public ThreadSafeClientConnManager(org.apache.http.params.HttpParams params,
                                   SchemeRegistry schreg)
Creates a new thread safe connection manager.

Parameters:
params - the parameters for this manager
schreg - the scheme registry, or null for the default registry
Method Detail

getSchemeRegistry

public SchemeRegistry getSchemeRegistry()
Specified by:
getSchemeRegistry in interface ClientConnectionManager

getConnection

public ManagedClientConnection getConnection(HttpRoute route)
Description copied from interface: ClientConnectionManager
Obtains a connection. This method will block until a connection becomes available or the connection manager is shut down.

Specified by:
getConnection in interface ClientConnectionManager
Parameters:
route - where the connection should point to
Returns:
a connection that can be used to communicate along the given route

getConnection

public ManagedClientConnection getConnection(HttpRoute route,
                                             long timeout)
                                      throws ConnectionPoolTimeoutException
Description copied from interface: ClientConnectionManager
Obtains a connection within a given time. This method will block until a connection becomes available, the timeout expires, or the connection manager is shut down.

Specified by:
getConnection in interface ClientConnectionManager
Parameters:
route - where the connection should point to
timeout - the timeout in milliseconds
Returns:
a connection that can be used to communicate along the given route
Throws:
ConnectionPoolTimeoutException - in case of a timeout

createConnectionOperator

protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg)
Hook for creating the connection operator. It is called by the constructor. Derived classes can override this method to change the instantiation of the operator. The default implementation here instantiates DefaultClientConnectionOperator.

Parameters:
schreg - the scheme registry to use, or null
Returns:
the connection operator to use

releaseConnection

public void releaseConnection(ManagedClientConnection conn)
Releases an allocated connection. If another thread is blocked in getConnection() that could use this connection, it will be woken up.

Specified by:
releaseConnection in interface ClientConnectionManager
Parameters:
conn - the connection to make available.

shutdownAll

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

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.

Specified by:
shutdown in interface ClientConnectionManager

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 in total.

Returns:
the total number of pooled connections

closeIdleConnections

public void closeIdleConnections(long idleTimeout)
Deletes all free connections that are idle or closed.

Specified by:
closeIdleConnections in interface ClientConnectionManager
Parameters:
idleTimeout - the idle time in milliseconds

getParams

public org.apache.http.params.HttpParams getParams()
Returns parameters associated with this connection manager.


setParams

public void setParams(org.apache.http.params.HttpParams params)
Assigns parameters for this connection manager.

See Also:
HttpConnectionManagerParams


Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.