Top Description Fields Constructors Methods
org.apache.http.impl.conn.tsccm

public Class ThreadSafeClientConnManager

extends Object
implements ClientConnectionManager
Class Inheritance
All Implemented Interfaces
org.apache.http.conn.ClientConnectionManager
Annotations
@Contract
threading:SAFE_CONDITIONAL
@Deprecated
Imports
java.io.IOException, java.util.concurrent.TimeUnit, org.apache.commons.logging.Log, .LogFactory, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.conn.ClientConnectionManager, .ClientConnectionOperator, .ClientConnectionRequest, .ConnectionPoolTimeoutException, .ManagedClientConnection, org.apache.http.conn.params.ConnPerRouteBean, org.apache.http.conn.routing.HttpRoute, org.apache.http.conn.scheme.SchemeRegistry, org.apache.http.impl.conn.DefaultClientConnectionOperator, .SchemeRegistryFactory, org.apache.http.params.HttpParams, org.apache.http.util.Args, .Asserts

Deprecated

(4.2) use org.apache.http.impl.conn.PoolingHttpClientConnectionManager

Manages a pool of org.apache.http.conn.OperatedClientConnection and is able to service connection requests from multiple execution threads. Connections are pooled on a per route basis. A request for a route which already the manager has persistent connections for available in the pool will be services by leasing a connection from the pool rather than creating a brand new connection.

ThreadSafeClientConnManager maintains a maximum limit of connection on a per route basis and in total. Per default this implementation will create no more than than 2 concurrent connections per given route and no more 20 connections in total. For many real-world applications these limits may prove too constraining, especially if they use HTTP as a transport protocol for their services. Connection limits, however, can be adjusted using HTTP parameters.

Since
4.0

Field Summary

Modifier and TypeField and Description
protected final AbstractConnPool
connectionPool

Deprecated as a consequence of AbstractConnPool being deprecated.
protected final ClientConnectionOperator
connOperator

The operator for opening and updating connections.

protected final ConnPerRouteBean
connPerRoute

Deprecated as a consequence of ConnPerRouteBean being deprecated.
private final Log
protected final ConnPoolByRoute
pool

The pool of connections being managed.

protected final SchemeRegistry
schemeRegistry

The schemes supported by this connection manager.

Constructor Summary

AccessConstructor and Description
public
ThreadSafeClientConnManager(final SchemeRegistry
the scheme registry.
schreg
)

Deprecated as a consequence of SchemeRegistry being deprecated.
Creates a new thread safe connection manager.
public
public
ThreadSafeClientConnManager(final SchemeRegistry
the scheme registry.
schreg
,
final long
max connection lifetime, <=0 implies "infinity"
connTTL
,
final TimeUnit
TimeUnit of connTTL
connTTLTimeUnit
)

Deprecated as a consequence of SchemeRegistry being deprecated.
Creates a new thread safe connection manager.
public
ThreadSafeClientConnManager(final SchemeRegistry
the scheme registry.
schreg
,
final long
max connection lifetime, <=0 implies "infinity"
connTTL
,
final TimeUnit
TimeUnit of connTTL
connTTLTimeUnit
,
final ConnPerRouteBean
mapping of maximum connections per route, provided as a dependency so it can be managed externally, e.g. for dynamic connection pool size management.
connPerRoute
)

Deprecated as a consequence of SchemeRegistry and ConnPerRouteBean being deprecated.
Creates a new thread safe connection manager.
public
ThreadSafeClientConnManager(final HttpParams
the parameters for this manager.
params
,
final SchemeRegistry
the scheme registry.
schreg
)

Creates a new thread safe connection manager.

Method Summary

Modifier and TypeMethod and Description
public void
public void
closeIdleConnections(final long
the idle time of connections to be closed
idleTimeout
,
final TimeUnit
the unit for the idletime
timeUnit
)

Implements org.apache.http.conn.ClientConnectionManager.closeIdleConnections.

Closes idle connections in the pool.
protected ClientConnectionOperator

Returns:

the connection operator to use
createConnectionOperator
(final SchemeRegistry
the scheme registry.
schreg
)

Deprecated as a consequence of SchemeRegistry and ClientConnectionOperator being deprecated.
Hook for creating the connection operator.
protected AbstractConnPool

Returns:

the connection pool to use
createConnectionPool
(final HttpParams params)

Deprecated (4.1) use #createConnectionPool(long, TimeUnit))
Hook for creating the connection pool.
protected ConnPoolByRoute

Returns:

the connection pool to use
createConnectionPool
(final long connTTL, final TimeUnit connTTLTimeUnit)

Deprecated as a consequence of ConnPoolByRoute being deprecated.
Hook for creating the connection pool.
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
public int

Returns:

the total number of pooled connections for that route
getConnectionsInPool
(final HttpRoute
the route in question
route
)

Gets the total number of pooled connections for the given route.

public int

Returns:

the total number of pooled connections
getConnectionsInPool
()

Gets the total number of pooled connections.

public int
public int
public int
getMaxTotal()

since 4.1

public SchemeRegistry
getSchemeRegistry()

Implements org.apache.http.conn.ClientConnectionManager.getSchemeRegistry.

Deprecated as a consequence of SchemeRegistry being deprecated.
Obtains the scheme registry used by this manager.
public void
releaseConnection(final ManagedClientConnection
the connection to release
conn
,
final long
the duration of time this connection is valid for reuse
validDuration
,
final TimeUnit
the unit of time validDuration is measured in
timeUnit
)

Implements org.apache.http.conn.ClientConnectionManager.releaseConnection.

Deprecated as a consequence of ManagedClientConnection being deprecated.
Releases a connection for use by others.
public ClientConnectionRequest
requestConnection(final HttpRoute route, final Object state)

Implements org.apache.http.conn.ClientConnectionManager.requestConnection.

Deprecated as a consequence of ClientConnectionRequest being deprecated.
Returns a new ClientConnectionRequest, from which a ManagedClientConnection can be obtained or the request can be aborted.
public void
setDefaultMaxPerRoute(final int max)

public void
setMaxForRoute(final HttpRoute route, final int max)

public void
setMaxTotal(final int max)

since 4.1

public void
shutdown()

Implements org.apache.http.conn.ClientConnectionManager.shutdown.

Shuts down this connection manager and releases allocated resources.
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionPoolback to summary
protected final AbstractConnPool connectionPool

Deprecated

as a consequence of AbstractConnPool being deprecated. See corresponding docs for further information.

connOperatorback to summary
protected final ClientConnectionOperator connOperator

Deprecated

as a consequence of ClientConnectionOperator being deprecated. See corresponding docs for further information.

The operator for opening and updating connections.

connPerRouteback to summary
protected final ConnPerRouteBean connPerRoute

Deprecated

as a consequence of ConnPerRouteBean being deprecated. See corresponding docs for further information.

logback to summary
private final Log log
poolback to summary
protected final ConnPoolByRoute pool

Deprecated

as a consequence of ConnPoolByRoute being deprecated. See corresponding docs for further information.

The pool of connections being managed.

schemeRegistryback to summary
protected final SchemeRegistry schemeRegistry

Deprecated

as a consequence of SchemeRegistry being deprecated. See corresponding docs for further information.

The schemes supported by this connection manager.

Constructor Detail

ThreadSafeClientConnManagerback to summary
public ThreadSafeClientConnManager(final SchemeRegistry schreg)

Deprecated

as a consequence of SchemeRegistry being deprecated. See corresponding docs for further information.

Creates a new thread safe connection manager.

Parameters
schreg:SchemeRegistry

the scheme registry.

ThreadSafeClientConnManagerback to summary
public ThreadSafeClientConnManager()
Since
4.1
ThreadSafeClientConnManagerback to summary
public ThreadSafeClientConnManager(final SchemeRegistry schreg, final long connTTL, final TimeUnit connTTLTimeUnit)

Deprecated

as a consequence of SchemeRegistry being deprecated. See corresponding docs for further information.

Creates a new thread safe connection manager.

Parameters
schreg:SchemeRegistry

the scheme registry.

connTTL:long

max connection lifetime, <=0 implies "infinity"

connTTLTimeUnit:TimeUnit

TimeUnit of connTTL

Since
4.1
ThreadSafeClientConnManagerback to summary
public ThreadSafeClientConnManager(final SchemeRegistry schreg, final long connTTL, final TimeUnit connTTLTimeUnit, final ConnPerRouteBean connPerRoute)

Deprecated

as a consequence of SchemeRegistry and ConnPerRouteBean being deprecated. See corresponding docs for further information.

Creates a new thread safe connection manager.

Parameters
schreg:SchemeRegistry

the scheme registry.

connTTL:long

max connection lifetime, <=0 implies "infinity"

connTTLTimeUnit:TimeUnit

TimeUnit of connTTL

connPerRoute:ConnPerRouteBean

mapping of maximum connections per route, provided as a dependency so it can be managed externally, e.g. for dynamic connection pool size management.

Since
4.2
ThreadSafeClientConnManagerback to summary
public ThreadSafeClientConnManager(final HttpParams params, final SchemeRegistry schreg)

Creates a new thread safe connection manager.

Parameters
params:HttpParams

the parameters for this manager.

schreg:SchemeRegistry

the scheme registry.

Annotations
@Deprecated

Method Detail

closeExpiredConnectionsback to summary
public void closeExpiredConnections()

Implements org.apache.http.conn.ClientConnectionManager.closeExpiredConnections.

Doc from org.apache.http.conn.ClientConnectionManager.closeExpiredConnections.

Closes all expired connections in the pool. Open connections in the pool that have not been used for the timespan defined when the connection was released will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision.

Annotations
@Override
closeIdleConnectionsback to summary
public void closeIdleConnections(final long idleTimeout, final TimeUnit timeUnit)

Implements org.apache.http.conn.ClientConnectionManager.closeIdleConnections.

Doc from org.apache.http.conn.ClientConnectionManager.closeIdleConnections.

Closes idle connections in the pool. Open connections in the pool that have not been used for the timespan given by the argument will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision All expired connections will also be closed.

Parameters
idleTimeout:long

the idle time of connections to be closed

timeUnit:TimeUnit

the unit for the idletime

Annotations
@Override
createConnectionOperatorback to summary
protected ClientConnectionOperator createConnectionOperator(final SchemeRegistry schreg)

Deprecated

as a consequence of SchemeRegistry and ClientConnectionOperator being deprecated. See corresponding docs for further information.

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:SchemeRegistry

the scheme registry.

Returns:ClientConnectionOperator

the connection operator to use

createConnectionPoolback to summary
protected AbstractConnPool createConnectionPool(final HttpParams params)

Deprecated

(4.1) use #createConnectionPool(long, TimeUnit))

Hook for creating the connection pool.

Returns:AbstractConnPool

the connection pool to use

Annotations
@Deprecated
createConnectionPoolback to summary
protected ConnPoolByRoute createConnectionPool(final long connTTL, final TimeUnit connTTLTimeUnit)

Deprecated

as a consequence of ConnPoolByRoute being deprecated. See corresponding docs for further information.

Hook for creating the connection pool.

Returns:ConnPoolByRoute

the connection pool to use

Since
4.1
finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
getConnectionsInPoolback to summary
public int getConnectionsInPool(final HttpRoute route)

Gets the total number of pooled connections for the given route. This is the total number of connections that have been created and are still in use by this connection manager for the route. This value will not exceed the maximum number of connections per host.

Parameters
route:HttpRoute

the route in question

Returns:int

the total number of pooled connections for that route

getConnectionsInPoolback to summary
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:int

the total number of pooled connections

getDefaultMaxPerRouteback to summary
public int getDefaultMaxPerRoute()
Since
4.1
getMaxForRouteback to summary
public int getMaxForRoute(final HttpRoute route)
Since
4.1
getMaxTotalback to summary
public int getMaxTotal()

since 4.1

getSchemeRegistryback to summary
public SchemeRegistry getSchemeRegistry()

Implements org.apache.http.conn.ClientConnectionManager.getSchemeRegistry.

Doc from org.apache.http.conn.ClientConnectionManager.getSchemeRegistry.

Deprecated

as a consequence of SchemeRegistry being deprecated. See corresponding docs for further information.

Obtains the scheme registry used by this manager.

Returns:SchemeRegistry

the scheme registry, never null

Annotations
@Override
releaseConnectionback to summary
public void releaseConnection(final ManagedClientConnection conn, final long validDuration, final TimeUnit timeUnit)

Implements org.apache.http.conn.ClientConnectionManager.releaseConnection.

Doc from org.apache.http.conn.ClientConnectionManager.releaseConnection.

Deprecated

as a consequence of ManagedClientConnection being deprecated. See corresponding docs for further information.

Releases a connection for use by others. You may optionally specify how long the connection is valid to be reused. Values <= 0 are considered to be valid forever. If the connection is not marked as reusable, the connection will not be reused regardless of the valid duration. If the connection has been released before, the call will be ignored.

Parameters
conn:ManagedClientConnection

the connection to release

validDuration:long

the duration of time this connection is valid for reuse

timeUnit:TimeUnit

the unit of time validDuration is measured in

Annotations
@Override
requestConnectionback to summary
public ClientConnectionRequest requestConnection(final HttpRoute route, final Object state)

Implements org.apache.http.conn.ClientConnectionManager.requestConnection.

Doc from org.apache.http.conn.ClientConnectionManager.requestConnection.

Deprecated

as a consequence of ClientConnectionRequest being deprecated. See corresponding docs for further information.

Returns a new ClientConnectionRequest, from which a ManagedClientConnection can be obtained or the request can be aborted.

Annotations
@Override
setDefaultMaxPerRouteback to summary
public void setDefaultMaxPerRoute(final int max)
Since
4.1
setMaxForRouteback to summary
public void setMaxForRoute(final HttpRoute route, final int max)
Since
4.1
setMaxTotalback to summary
public void setMaxTotal(final int max)

since 4.1

shutdownback to summary
public void shutdown()

Implements org.apache.http.conn.ClientConnectionManager.shutdown.

Doc from org.apache.http.conn.ClientConnectionManager.shutdown.

Shuts down this connection manager and releases allocated resources. This includes closing all connections, whether they are currently used or not.

Annotations
@Override