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:
java.io.Closeable,java.lang.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 java.lang.Object implements ManagedConnPool<R,C>
Route-segmented connection pool with reduced contention and a small, conditional round-robin helper for busy multi-route scenarios.Per-route state is kept in independent segments. Disposal of connections is offloaded to a bounded executor so slow graceful closes do not block threads leasing on other routes. A minimal round-robin helper is engaged for pending routes. When the global capacity is exhausted, reusable idle entries can be reclaimed across segments without a global lock.
- Since:
- 5.4
- See Also:
ManagedConnPool,PoolReusePolicy,DisposalCallback
-
-
Constructor Summary
Constructors Constructor Description RouteSegmentedConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy reusePolicy, DisposalCallback<C> disposal)RouteSegmentedConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy reusePolicy, DisposalCallback<C> disposal, ConnPoolListener<R> 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)intgetDefaultMaxPerRoute()intgetMaxPerRoute(R route)intgetMaxTotal()java.util.Set<R>getRoutes()PoolStatsgetStats(R route)PoolStatsgetTotalStats()java.util.concurrent.Future<PoolEntry<R,C>>lease(R route, java.lang.Object state, Timeout requestTimeout, FutureCallback<PoolEntry<R,C>> callback)Attempts to lease a connection for the given route and with the given state from the pool.voidrelease(PoolEntry<R,C> entry, boolean reusable)Releases the pool entry back to the pool.voidsetDefaultMaxPerRoute(int max)voidsetMaxPerRoute(R route, int max)voidsetMaxTotal(int max)
-
-
-
Constructor Detail
-
RouteSegmentedConnPool
public RouteSegmentedConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy reusePolicy, DisposalCallback<C> disposal)
-
RouteSegmentedConnPool
public RouteSegmentedConnPool(int defaultMaxPerRoute, int maxTotal, TimeValue timeToLive, PoolReusePolicy reusePolicy, DisposalCallback<C> disposal, ConnPoolListener<R> connPoolListener)
-
-
Method Detail
-
lease
public java.util.concurrent.Future<PoolEntry<R,C>> lease(R route, java.lang.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
public void release(PoolEntry<R,C> entry, boolean reusable)
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
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
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.
-
closeIdle
public void closeIdle(TimeValue idleTime)
- Specified by:
closeIdlein interfaceConnPoolControl<R>
-
closeExpired
public void closeExpired()
- Specified by:
closeExpiredin interfaceConnPoolControl<R>
-
getRoutes
public java.util.Set<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
public int getMaxPerRoute(R route)
- Specified by:
getMaxPerRoutein interfaceConnPoolControl<R>
-
setMaxPerRoute
public void setMaxPerRoute(R route, int max)
- Specified by:
setMaxPerRoutein interfaceConnPoolControl<R>
-
getTotalStats
public PoolStats getTotalStats()
- Specified by:
getTotalStatsin interfaceConnPoolStats<R>
-
getStats
public PoolStats getStats(R route)
- Specified by:
getStatsin interfaceConnPoolStats<R>
-
-