Package org.apache.hc.core5.pool
Class LaxConnPool<T,C extends ModalCloseable>
- java.lang.Object
-
- org.apache.hc.core5.pool.LaxConnPool<T,C>
-
- Type Parameters:
T- routeC- connection object
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ModalCloseable,ConnPool<T,C>,ConnPoolControl<T>,ConnPoolStats<T>,ManagedConnPool<T,C>
@Contract(threading=SAFE) @Experimental public class LaxConnPool<T,C extends ModalCloseable> extends java.lang.Object implements ManagedConnPool<T,C>
Connection pool with higher concurrency but with lax connection limit guarantees.- Since:
- 5.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classLaxConnPool.LeaseRequest<T,C extends ModalCloseable>(package private) static classLaxConnPool.PerRoutePool<T,C extends ModalCloseable>
-
Field Summary
Fields Modifier and Type Field Description private ConnPoolListener<T>connPoolListenerprivate intdefaultMaxPerRouteprivate DisposalCallback<C>disposalCallbackprivate java.util.concurrent.atomic.AtomicBooleanisShutDownprivate PoolReusePolicypolicyprivate java.util.concurrent.ConcurrentMap<T,LaxConnPool.PerRoutePool<T,C>>routeToPoolprivate TimeValuetimeToLive
-
Constructor Summary
Constructors Constructor Description LaxConnPool(int defaultMaxPerRoute)LaxConnPool(int defaultMaxPerRoute, TimeValue timeToLive, PoolReusePolicy policy, ConnPoolListener<T> connPoolListener)LaxConnPool(int defaultMaxPerRoute, TimeValue timeToLive, PoolReusePolicy policy, DisposalCallback<C> disposalCallback, ConnPoolListener<T> connPoolListener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidclose(CloseMode closeMode)Closes this process or endpoint and releases any system resources associated with it.voidcloseExpired()voidcloseIdle(TimeValue idleTime)voidenumAvailable(Callback<PoolEntry<T,C>> callback)voidenumLeased(Callback<PoolEntry<T,C>> callback)intgetDefaultMaxPerRoute()intgetMaxPerRoute(T route)intgetMaxTotal()private LaxConnPool.PerRoutePool<T,C>getPool(T route)java.util.Set<T>getRoutes()PoolStatsgetStats(T route)PoolStatsgetTotalStats()booleanisShutdown()java.util.concurrent.Future<PoolEntry<T,C>>lease(T route, java.lang.Object state)java.util.concurrent.Future<PoolEntry<T,C>>lease(T route, java.lang.Object state, Timeout requestTimeout, FutureCallback<PoolEntry<T,C>> callback)Attempts to lease a connection for the given route and with the given state from the pool.voidrelease(PoolEntry<T,C> entry, boolean reusable)Releases the pool entry back to the pool.voidsetDefaultMaxPerRoute(int max)voidsetMaxPerRoute(T route, int max)voidsetMaxTotal(int max)java.lang.StringtoString()voidvalidatePendingRequests()
-
-
-
Field Detail
-
timeToLive
private final TimeValue timeToLive
-
policy
private final PoolReusePolicy policy
-
disposalCallback
private final DisposalCallback<C extends ModalCloseable> disposalCallback
-
connPoolListener
private final ConnPoolListener<T> connPoolListener
-
routeToPool
private final java.util.concurrent.ConcurrentMap<T,LaxConnPool.PerRoutePool<T,C extends ModalCloseable>> routeToPool
-
isShutDown
private final java.util.concurrent.atomic.AtomicBoolean isShutDown
-
defaultMaxPerRoute
private volatile int defaultMaxPerRoute
-
-
Constructor Detail
-
LaxConnPool
public LaxConnPool(int defaultMaxPerRoute, TimeValue timeToLive, PoolReusePolicy policy, DisposalCallback<C> disposalCallback, ConnPoolListener<T> connPoolListener)- Since:
- 5.0
-
LaxConnPool
public LaxConnPool(int defaultMaxPerRoute, TimeValue timeToLive, PoolReusePolicy policy, ConnPoolListener<T> connPoolListener)- Since:
- 5.0
-
LaxConnPool
public LaxConnPool(int defaultMaxPerRoute)
-
-
Method Detail
-
isShutdown
public boolean isShutdown()
-
close
public void close(CloseMode closeMode)
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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
getPool
private LaxConnPool.PerRoutePool<T,C> getPool(T route)
-
lease
public java.util.concurrent.Future<PoolEntry<T,C>> lease(T route, java.lang.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.
-
release
public void release(PoolEntry<T,C> entry, boolean reusable)
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.
-
validatePendingRequests
public void validatePendingRequests()
-
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
public void setMaxPerRoute(T route, int max)
- Specified by:
setMaxPerRoutein interfaceConnPoolControl<T>
-
getMaxPerRoute
public int getMaxPerRoute(T route)
- Specified by:
getMaxPerRoutein interfaceConnPoolControl<T>
-
getTotalStats
public PoolStats getTotalStats()
- Specified by:
getTotalStatsin interfaceConnPoolStats<T>
-
getStats
public PoolStats getStats(T route)
- Specified by:
getStatsin interfaceConnPoolStats<T>
-
getRoutes
public java.util.Set<T> getRoutes()
- Specified by:
getRoutesin interfaceConnPoolControl<T>
-
closeIdle
public void closeIdle(TimeValue idleTime)
- Specified by:
closeIdlein interfaceConnPoolControl<T>
-
closeExpired
public void closeExpired()
- Specified by:
closeExpiredin interfaceConnPoolControl<T>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-