Package org.apache.hc.core5.pool
Class RouteSegmentedConnPool<R,C extends ModalCloseable>
java.lang.Object
org.apache.hc.core5.pool.RouteSegmentedConnPool<R,C>
- Type Parameters:
R- route key typeC- connection type (must beModalCloseable)
- All Implemented Interfaces:
Closeable,AutoCloseable,ModalCloseable,ConnPool<R,,C> ConnPoolControl<R>,ConnPoolStats<R>,ManagedConnPool<R,C>
@Contract(threading=SAFE_CONDITIONAL)
@Experimental
public final class RouteSegmentedConnPool<R,C extends ModalCloseable>
extends Object
implements ManagedConnPool<R,C>
Lock-free, route-segmented connection pool with tiny, conditional round-robin assistance.
Per-route state is kept in independent segments. Disposal of connections is offloaded to a bounded executor so slow closes do not block threads leasing on other routes. A minimal round-robin drainer is engaged only when there are many pending routes and there is global headroom; it never scans all routes.
- Since:
- 5.4
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRouteSegmentedConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy reusePolicy, DisposalCallback<C> disposal) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidCloses this process or endpoint and releases any system resources associated with it.voidvoidintintgetMaxPerRoute(R route) intAttempts to lease a connection for the given route and with the given state from the pool.voidReleases the pool entry back to the pool.voidsetDefaultMaxPerRoute(int max) voidsetMaxPerRoute(R route, int max) voidsetMaxTotal(int max)
-
Constructor Details
-
RouteSegmentedConnPool
public RouteSegmentedConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy reusePolicy, DisposalCallback<C> disposal)
-
-
Method Details
-
lease
public Future<PoolEntry<R,C>> lease(R route, Object state, Timeout requestTimeout, FutureCallback<PoolEntry<R, 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<R,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
Description copied from interface:ConnPoolReleases the pool entry back to the pool.- Specified by:
releasein interfaceConnPool<R,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.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
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.
-
closeIdle
- Specified by:
closeIdlein interfaceConnPoolControl<R>
-
closeExpired
public void closeExpired()- Specified by:
closeExpiredin interfaceConnPoolControl<R>
-
getRoutes
- Specified by:
getRoutesin interfaceConnPoolControl<R>
-
getMaxTotal
public int getMaxTotal()- Specified by:
getMaxTotalin interfaceConnPoolControl<R>
-
setMaxTotal
public void setMaxTotal(int max) - Specified by:
setMaxTotalin interfaceConnPoolControl<R>
-
getDefaultMaxPerRoute
public int getDefaultMaxPerRoute()- Specified by:
getDefaultMaxPerRoutein interfaceConnPoolControl<R>
-
setDefaultMaxPerRoute
public void setDefaultMaxPerRoute(int max) - Specified by:
setDefaultMaxPerRoutein interfaceConnPoolControl<R>
-
getMaxPerRoute
- Specified by:
getMaxPerRoutein interfaceConnPoolControl<R>
-
setMaxPerRoute
- Specified by:
setMaxPerRoutein interfaceConnPoolControl<R>
-
getTotalStats
- Specified by:
getTotalStatsin interfaceConnPoolStats<R>
-
getStats
- Specified by:
getStatsin interfaceConnPoolStats<R>
-