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:
java.io.Closeable
,java.lang.AutoCloseable
,ModalCloseable
,ConnPool<T,C>
,ConnPoolControl<T>
,ConnPoolStats<T>
,ManagedConnPool<T,C>
@Contract(threading=SAFE) public class StrictConnPool<T,C extends ModalCloseable> extends java.lang.Object implements ManagedConnPool<T,C>
Connection pool with strict connection limit guarantees.- Since:
- 4.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
StrictConnPool.LeaseRequest<T,C extends ModalCloseable>
(package private) static class
StrictConnPool.PerRoutePool<T,C extends ModalCloseable>
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<PoolEntry<T,C>>
available
private java.util.concurrent.ConcurrentLinkedQueue<StrictConnPool.LeaseRequest<T,C>>
completedRequests
private ConnPoolListener<T>
connPoolListener
private int
defaultMaxPerRoute
private DisposalCallback<C>
disposalCallback
private java.util.concurrent.atomic.AtomicBoolean
isShutDown
private java.util.Set<PoolEntry<T,C>>
leased
private java.util.concurrent.locks.Lock
lock
private java.util.Map<T,java.lang.Integer>
maxPerRoute
private int
maxTotal
private java.util.LinkedList<StrictConnPool.LeaseRequest<T,C>>
pendingRequests
private PoolReusePolicy
policy
private java.util.Map<T,StrictConnPool.PerRoutePool<T,C>>
routeToPool
private TimeValue
timeToLive
-
Constructor Summary
Constructors Constructor Description StrictConnPool(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
close(CloseMode closeMode)
Closes this process or endpoint and releases any system resources associated with it.void
closeExpired()
void
closeIdle(TimeValue idleTime)
void
enumAvailable(Callback<PoolEntry<T,C>> callback)
Enumerates all available connections.void
enumLeased(Callback<PoolEntry<T,C>> callback)
Enumerates all leased connections.private void
fireCallbacks()
int
getDefaultMaxPerRoute()
private int
getMax(T route)
int
getMaxPerRoute(T route)
int
getMaxTotal()
private StrictConnPool.PerRoutePool<T,C>
getPool(T route)
java.util.Set<T>
getRoutes()
Returns snapshot of all knows routesPoolStats
getStats(T route)
PoolStats
getTotalStats()
boolean
isShutdown()
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.private void
processNextPendingRequest()
private boolean
processPendingRequest(StrictConnPool.LeaseRequest<T,C> request)
private void
processPendingRequests()
private void
purgePoolMap()
void
release(PoolEntry<T,C> entry, boolean reusable)
Releases the pool entry back to the pool.void
setDefaultMaxPerRoute(int max)
void
setMaxPerRoute(T route, int max)
void
setMaxTotal(int max)
java.lang.String
toString()
void
validatePendingRequests()
-
-
-
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.Map<T,StrictConnPool.PerRoutePool<T,C extends ModalCloseable>> routeToPool
-
pendingRequests
private final java.util.LinkedList<StrictConnPool.LeaseRequest<T,C extends ModalCloseable>> pendingRequests
-
leased
private final java.util.Set<PoolEntry<T,C extends ModalCloseable>> leased
-
available
private final java.util.LinkedList<PoolEntry<T,C extends ModalCloseable>> available
-
completedRequests
private final java.util.concurrent.ConcurrentLinkedQueue<StrictConnPool.LeaseRequest<T,C extends ModalCloseable>> completedRequests
-
maxPerRoute
private final java.util.Map<T,java.lang.Integer> maxPerRoute
-
lock
private final java.util.concurrent.locks.Lock lock
-
isShutDown
private final java.util.concurrent.atomic.AtomicBoolean isShutDown
-
defaultMaxPerRoute
private volatile int defaultMaxPerRoute
-
maxTotal
private volatile int maxTotal
-
-
Constructor Detail
-
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 Detail
-
isShutdown
public boolean isShutdown()
-
close
public void close(CloseMode closeMode)
Description copied from interface:ModalCloseable
Closes 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:
close
in interfaceModalCloseable
- Parameters:
closeMode
- How to close the receiver.
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
getPool
private StrictConnPool.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:ConnPool
Attempts 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:
lease
in 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:ConnPool
Releases the pool entry back to the pool.- Specified by:
release
in 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
private boolean processPendingRequest(StrictConnPool.LeaseRequest<T,C> request)
-
fireCallbacks
private void fireCallbacks()
-
validatePendingRequests
public void validatePendingRequests()
-
getMax
private int getMax(T route)
-
setMaxTotal
public void setMaxTotal(int max)
- Specified by:
setMaxTotal
in interfaceConnPoolControl<T>
-
getMaxTotal
public int getMaxTotal()
- Specified by:
getMaxTotal
in interfaceConnPoolControl<T>
-
setDefaultMaxPerRoute
public void setDefaultMaxPerRoute(int max)
- Specified by:
setDefaultMaxPerRoute
in interfaceConnPoolControl<T>
-
getDefaultMaxPerRoute
public int getDefaultMaxPerRoute()
- Specified by:
getDefaultMaxPerRoute
in interfaceConnPoolControl<T>
-
setMaxPerRoute
public void setMaxPerRoute(T route, int max)
- Specified by:
setMaxPerRoute
in interfaceConnPoolControl<T>
-
getMaxPerRoute
public int getMaxPerRoute(T route)
- Specified by:
getMaxPerRoute
in interfaceConnPoolControl<T>
-
getTotalStats
public PoolStats getTotalStats()
- Specified by:
getTotalStats
in interfaceConnPoolStats<T>
-
getStats
public PoolStats getStats(T route)
- Specified by:
getStats
in interfaceConnPoolStats<T>
-
getRoutes
public java.util.Set<T> getRoutes()
Returns snapshot of all knows routes- Specified by:
getRoutes
in interfaceConnPoolControl<T>
- Since:
- 4.4
-
enumAvailable
public void enumAvailable(Callback<PoolEntry<T,C>> callback)
Enumerates all available connections.- Since:
- 4.3
-
enumLeased
public void enumLeased(Callback<PoolEntry<T,C>> callback)
Enumerates all leased connections.- Since:
- 4.3
-
purgePoolMap
private void purgePoolMap()
-
closeIdle
public void closeIdle(TimeValue idleTime)
- Specified by:
closeIdle
in interfaceConnPoolControl<T>
-
closeExpired
public void closeExpired()
- Specified by:
closeExpired
in interfaceConnPoolControl<T>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-