Top Description Fields Constructors Methods
org.apache.http.pool

public abstract Class AbstractConnPool<T, C, E extends org.apache.http.pool.PoolEntry<T, C>>

extends Object
implements ConnPool<T, E extends PoolEntry<T, C>>, ConnPoolControl<T>
Class Inheritance
All Implemented Interfaces
org.apache.http.pool.ConnPoolControl, org.apache.http.pool.ConnPool
Known Direct Subclasses
org.apache.http.impl.pool.BasicConnPool
Annotations
@Contract
threading:SAFE_CONDITIONAL
Type Parameters
<T>
the route type that represents the opposite endpoint of a pooled connection.
<C>
the connection type.
<E>
the type of the pool entry containing a pooled connection.
Imports
java.io.IOException, java.util.Date, .HashMap, .HashSet, .Iterator, .LinkedList, .Map, .Set, java.util.concurrent.CancellationException, .ExecutionException, .Future, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicBoolean, .AtomicReference, java.util.concurrent.locks.Condition, .Lock, .ReentrantLock, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.concurrent.FutureCallback, org.apache.http.util.Args, .Asserts

Abstract synchronous (blocking) pool of connections.

Please note that this class does not maintain its own pool of execution Threads. Therefore, one must call Future#get() or Future#get(long, TimeUnit) method on the Future object returned by the lease(Object, Object, FutureCallback) method in order for the lease operation to complete.

Since
4.2

Field Summary

Modifier and TypeField and Description
private final LinkedList<E>
private final Condition
private final ConnFactory<T, C>
private volatile int
private volatile boolean
private final Set<E>
private final Lock
private final Map<T, Integer>
private volatile int
private final LinkedList<Future<E>>
private final Map<T, RouteSpecificPool<T, C, E>>
private volatile int

Constructor Summary

AccessConstructor and Description
public
AbstractConnPool(final ConnFactory<T, C> connFactory, final int defaultMaxPerRoute, final int maxTotal)

Method Summary

Modifier and TypeMethod and Description
public void
closeExpired()

Closes expired connections and evicts them from the pool.

public void
closeIdle(final long
maximum idle time.
idletime
,
final TimeUnit
time unit.
timeUnit
)

Closes connections that have been idle longer than the given period of time and evicts them from the pool.

protected abstract E
createEntry(T route, C conn)

Creates a new entry for the given connection with the given route.

protected void
enumAvailable(final PoolEntryCallback<T, C> callback)

Enumerates all available connections.

protected void
enumLeased(final PoolEntryCallback<T, C> callback)

Enumerates all leased connections.

public int
private int
getMax(final T route)

public int
public int
private RouteSpecificPool<T, C, E>
getPool(final T route)

private E
getPoolEntryBlocking(final T route, final Object state, final long timeout, final TimeUnit timeUnit, final Future<E> future)

public Set<T>

Returns:

the set of routes
getRoutes
()

Returns snapshot of all knows routes

public PoolStats
public PoolStats
public int

Returns:

the number of milliseconds
getValidateAfterInactivity
()

public boolean
public Future<E>
lease(final T
route of the connection.
route
,
final Object
arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.
state
,
final FutureCallback<E>
operation completion callback.
callback
)

Implements org.apache.http.pool.ConnPool.lease.

Attempts to lease a connection for the given route and with the given state from the pool.
public Future<E>

Returns:

future for a leased pool entry.
lease
(final T
route of the connection.
route
,
final Object
arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.
state
)

Attempts to lease a connection for the given route and with the given state from the pool.

protected void
onLease(final E entry)

protected void
onRelease(final E entry)

protected void
onReuse(final E entry)

private static Exception
private void
public void
release(final E
pool entry leased from the pool
entry
,
final boolean
flag indicating whether or not the released connection is in a consistent state and is safe for further use.
reusable
)

Implements org.apache.http.pool.ConnPool.release.

Releases the pool entry back to the pool.
public void
public void
public void
public void
setValidateAfterInactivity(final int
the number of milliseconds
ms
)

public void
shutdown()

Shuts down the pool.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
protected boolean
validate(final E entry)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

availableback to summary
private final LinkedList<E> available
conditionback to summary
private final Condition condition
connFactoryback to summary
private final ConnFactory<T, C> connFactory
defaultMaxPerRouteback to summary
private volatile int defaultMaxPerRoute
isShutDownback to summary
private volatile boolean isShutDown
leasedback to summary
private final Set<E> leased
lockback to summary
private final Lock lock
maxPerRouteback to summary
private final Map<T, Integer> maxPerRoute
maxTotalback to summary
private volatile int maxTotal
pendingback to summary
private final LinkedList<Future<E>> pending
routeToPoolback to summary
private final Map<T, RouteSpecificPool<T, C, E>> routeToPool
validateAfterInactivityback to summary
private volatile int validateAfterInactivity

Constructor Detail

AbstractConnPoolback to summary
public AbstractConnPool(final ConnFactory<T, C> connFactory, final int defaultMaxPerRoute, final int maxTotal)

Method Detail

closeExpiredback to summary
public void closeExpired()

Closes expired connections and evicts them from the pool.

closeIdleback to summary
public void closeIdle(final long idletime, final TimeUnit timeUnit)

Closes connections that have been idle longer than the given period of time and evicts them from the pool.

Parameters
idletime:long

maximum idle time.

timeUnit:TimeUnit

time unit.

createEntryback to summary
protected abstract E createEntry(T route, C conn)

Creates a new entry for the given connection with the given route.

enumAvailableback to summary
protected void enumAvailable(final PoolEntryCallback<T, C> callback)

Enumerates all available connections.

Since
4.3
enumLeasedback to summary
protected void enumLeased(final PoolEntryCallback<T, C> callback)

Enumerates all leased connections.

Since
4.3
getDefaultMaxPerRouteback to summary
public int getDefaultMaxPerRoute()

Implements org.apache.http.pool.ConnPoolControl.getDefaultMaxPerRoute.

Annotations
@Override
getMaxback to summary
private int getMax(final T route)
getMaxPerRouteback to summary
public int getMaxPerRoute(final T route)

Implements org.apache.http.pool.ConnPoolControl.getMaxPerRoute.

Annotations
@Override
getMaxTotalback to summary
public int getMaxTotal()

Implements org.apache.http.pool.ConnPoolControl.getMaxTotal.

Annotations
@Override
getPoolback to summary
private RouteSpecificPool<T, C, E> getPool(final T route)
getPoolEntryBlockingback to summary
private E getPoolEntryBlocking(final T route, final Object state, final long timeout, final TimeUnit timeUnit, final Future<E> future) throws IOException, InterruptedException, ExecutionException, TimeoutException
getRoutesback to summary
public Set<T> getRoutes()

Returns snapshot of all knows routes

Returns:Set<T>

the set of routes

Since
4.4
getStatsback to summary
public PoolStats getStats(final T route)

Implements org.apache.http.pool.ConnPoolControl.getStats.

Annotations
@Override
getTotalStatsback to summary
public PoolStats getTotalStats()

Implements org.apache.http.pool.ConnPoolControl.getTotalStats.

Annotations
@Override
getValidateAfterInactivityback to summary
public int getValidateAfterInactivity()
Returns:int

the number of milliseconds

Since
4.4
isShutdownback to summary
public boolean isShutdown()
leaseback to summary
public Future<E> lease(final T route, final Object state, final FutureCallback<E> callback)

Implements org.apache.http.pool.ConnPool.lease.

Doc from org.apache.http.pool.ConnPool.lease.

Attempts to lease a connection for the given route and with the given state from the pool.

Please note that this class does not maintain its own pool of execution Threads. Therefore, one must call Future#get() or Future#get(long, TimeUnit) method on the Future returned by this method in order for the lease operation to complete.

Parameters
route:T

route of the connection.

state:Object

arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.

callback:FutureCallback<E>

operation completion callback.

Returns:Future<E>

future for a leased pool entry.

Annotations
@Override
leaseback to summary
public Future<E> lease(final T route, final Object state)

Attempts to lease a connection for the given route and with the given state from the pool.

Please note that this class does not maintain its own pool of execution Threads. Therefore, one must call Future#get() or Future#get(long, TimeUnit) method on the Future returned by this method in order for the lease operation to complete.

Parameters
route:T

route of the connection.

state:Object

arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.

Returns:Future<E>

future for a leased pool entry.

onLeaseback to summary
protected void onLease(final E entry)
Since
4.3
onReleaseback to summary
protected void onRelease(final E entry)
Since
4.3
onReuseback to summary
protected void onReuse(final E entry)
Since
4.4
operationAbortedback to summary
private static Exception operationAborted()
purgePoolMapback to summary
private void purgePoolMap()
releaseback to summary
public void release(final E entry, final boolean reusable)

Implements org.apache.http.pool.ConnPool.release.

Doc from org.apache.http.pool.ConnPool.release.

Releases the pool entry back to the pool.

Parameters
entry:E

pool entry leased from the pool

reusable:boolean

flag indicating whether or not the released connection is in a consistent state and is safe for further use.

Annotations
@Override
setDefaultMaxPerRouteback to summary
public void setDefaultMaxPerRoute(final int max)

Implements org.apache.http.pool.ConnPoolControl.setDefaultMaxPerRoute.

Annotations
@Override
setMaxPerRouteback to summary
public void setMaxPerRoute(final T route, final int max)

Implements org.apache.http.pool.ConnPoolControl.setMaxPerRoute.

Annotations
@Override
setMaxTotalback to summary
public void setMaxTotal(final int max)

Implements org.apache.http.pool.ConnPoolControl.setMaxTotal.

Annotations
@Override
setValidateAfterInactivityback to summary
public void setValidateAfterInactivity(final int ms)
Parameters
ms:int

the number of milliseconds

Since
4.4
shutdownback to summary
public void shutdown() throws IOException

Shuts down the pool.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
validateback to summary
protected boolean validate(final E entry)
Since
4.4