Package org.apache.hc.core5.pool
Class StrictConnPool<T,C extends ModalCloseable>
java.lang.Object
org.apache.hc.core5.pool.StrictConnPool<T,C>
- Type Parameters:
T- routeC- connection object
- All Implemented Interfaces:
Closeable,AutoCloseable,ModalCloseable,ConnPool<T,,C> ConnPoolControl<T>,ConnPoolStats<T>,ManagedConnPool<T,C>
@Contract(threading=SAFE)
public class StrictConnPool<T,C extends ModalCloseable>
extends Object
implements ManagedConnPool<T,C>
Connection pool with strict connection limit guarantees.
- Since:
- 4.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classStrictConnPool.LeaseRequest<T,C extends ModalCloseable> (package private) static classStrictConnPool.PerRoutePool<T,C extends ModalCloseable> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LinkedList<PoolEntry<T, C>> private final ConcurrentLinkedQueue<StrictConnPool.LeaseRequest<T, C>> private final ConnPoolListener<T> private intprivate final DisposalCallback<C> private final AtomicBooleanprivate final Lockprivate intprivate final LinkedList<StrictConnPool.LeaseRequest<T, C>> private final PoolReusePolicyprivate final Map<T, StrictConnPool.PerRoutePool<T, C>> private final TimeValue -
Constructor Summary
ConstructorsConstructorDescriptionStrictConnPool(int defaultMaxPerRoute, int maxTotal) StrictConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy policy, ConnPoolListener<T> connPoolListener) StrictConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy policy, DisposalCallback<C> disposalCallback, ConnPoolListener<T> connPoolListener) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidCloses this process or endpoint and releases any system resources associated with it.voidvoidvoidenumAvailable(Callback<PoolEntry<T, C>> callback) Enumerates all available connections.voidenumLeased(Callback<PoolEntry<T, C>> callback) Enumerates all leased connections.private voidintprivate intintgetMaxPerRoute(T route) intprivate StrictConnPool.PerRoutePool<T, C> Returns snapshot of all knows routesbooleanAttempts to lease a connection for the given route and with the given state from the pool.private voidprivate booleanprocessPendingRequest(StrictConnPool.LeaseRequest<T, C> request) private voidprivate voidvoidReleases the pool entry back to the pool.voidsetDefaultMaxPerRoute(int max) voidsetMaxPerRoute(T route, int max) voidsetMaxTotal(int max) toString()void
-
Field Details
-
timeToLive
-
policy
-
disposalCallback
-
connPoolListener
-
routeToPool
-
pendingRequests
-
leased
-
available
-
completedRequests
private final ConcurrentLinkedQueue<StrictConnPool.LeaseRequest<T,C extends ModalCloseable>> completedRequests -
maxPerRoute
-
lock
-
isShutDown
-
defaultMaxPerRoute
private volatile int defaultMaxPerRoute -
maxTotal
private volatile int maxTotal
-
-
Constructor Details
-
StrictConnPool
public StrictConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy policy, DisposalCallback<C> disposalCallback, ConnPoolListener<T> connPoolListener) - Since:
- 5.0
-
StrictConnPool
public StrictConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy policy, ConnPoolListener<T> connPoolListener) - Since:
- 5.0
-
StrictConnPool
public StrictConnPool(int defaultMaxPerRoute, int maxTotal)
-
-
Method Details
-
isShutdown
public boolean isShutdown() -
close
Description copied from interface:ModalCloseableCloses this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.- Specified by:
closein interfaceModalCloseable- Parameters:
closeMode- How to close the receiver.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getPool
-
lease
public Future<PoolEntry<T,C>> lease(T route, Object state, Timeout requestTimeout, FutureCallback<PoolEntry<T, C>> callback) Description copied from interface:ConnPoolAttempts to lease a connection for the given route and with the given state from the pool.Please note the connection request can get automatically cancelled by the pool in case of a request timeout.
- Specified by:
leasein interfaceConnPool<T,C extends ModalCloseable> - Parameters:
route- route of the connection.state- 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 benull.requestTimeout- request timeout. In case of a timeout the request can get automatically cancelled by the pool.callback- operation completion callback.- Returns:
- future for a leased pool entry.
-
lease
-
release
Description copied from interface:ConnPoolReleases the pool entry back to the pool.- Specified by:
releasein interfaceConnPool<T,C extends ModalCloseable> - Parameters:
entry- pool entry leased from the poolreusable- flag indicating whether or not the released connection is in a consistent state and is safe for further use.
-
processPendingRequests
private void processPendingRequests() -
processNextPendingRequest
private void processNextPendingRequest() -
processPendingRequest
-
fireCallbacks
private void fireCallbacks() -
validatePendingRequests
public void validatePendingRequests() -
getMax
-
setMaxTotal
public void setMaxTotal(int max) - Specified by:
setMaxTotalin interfaceConnPoolControl<T>
-
getMaxTotal
public int getMaxTotal()- Specified by:
getMaxTotalin interfaceConnPoolControl<T>
-
setDefaultMaxPerRoute
public void setDefaultMaxPerRoute(int max) - Specified by:
setDefaultMaxPerRoutein interfaceConnPoolControl<T>
-
getDefaultMaxPerRoute
public int getDefaultMaxPerRoute()- Specified by:
getDefaultMaxPerRoutein interfaceConnPoolControl<T>
-
setMaxPerRoute
- Specified by:
setMaxPerRoutein interfaceConnPoolControl<T>
-
getMaxPerRoute
- Specified by:
getMaxPerRoutein interfaceConnPoolControl<T>
-
getTotalStats
- Specified by:
getTotalStatsin interfaceConnPoolStats<T>
-
getStats
- Specified by:
getStatsin interfaceConnPoolStats<T>
-
getRoutes
Returns snapshot of all knows routes- Specified by:
getRoutesin interfaceConnPoolControl<T>- Since:
- 4.4
-
enumAvailable
Enumerates all available connections.- Since:
- 4.3
-
enumLeased
Enumerates all leased connections.- Since:
- 4.3
-
purgePoolMap
private void purgePoolMap() -
closeIdle
- Specified by:
closeIdlein interfaceConnPoolControl<T>
-
closeExpired
public void closeExpired()- Specified by:
closeExpiredin interfaceConnPoolControl<T>
-
toString
-