Class AbstractConnPool<T,C,E extends PoolEntry<T,C>>
- Type Parameters:
T
- the route type that represents the opposite endpoint of a pooled connection.C
- the connection type.E
- the type of the pool entry containing a pooled connection.
- All Implemented Interfaces:
ConnPool<T,
,E> ConnPoolControl<T>
- Direct Known Subclasses:
BasicConnPool
Please note that this class does not maintain its own pool of execution Thread
s.
Therefore, one must call Future.get()
or Future.get(long, TimeUnit)
method on the Future
object returned by the
lease(Object, Object, FutureCallback)
method in order for the lease operation
to complete.
- Since:
- 4.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LinkedList
<E> private final Condition
private final ConnFactory
<T, C> private int
private boolean
private final Lock
private int
private final LinkedList
<Future<E>> private int
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractConnPool
(ConnFactory<T, C> connFactory, int defaultMaxPerRoute, int maxTotal) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Closes expired connections and evicts them from the pool.void
Closes connections that have been idle longer than the given period of time and evicts them from the pool.protected abstract E
createEntry
(T route, C conn) Creates a new entry for the given connection with the given route.protected void
enumAvailable
(PoolEntryCallback<T, C> callback) Enumerates all available connections.protected void
enumLeased
(PoolEntryCallback<T, C> callback) Enumerates all leased connections.int
private int
int
getMaxPerRoute
(T route) int
private RouteSpecificPool
<T, C, E> private E
Returns snapshot of all knows routesint
boolean
Attempts to lease a connection for the given route and with the given state from the pool.lease
(T route, Object state, FutureCallback<E> callback) Attempts to lease a connection for the given route and with the given state from the pool.protected void
protected void
protected void
private static Exception
private void
void
Releases the pool entry back to the pool.void
setDefaultMaxPerRoute
(int max) void
setMaxPerRoute
(T route, int max) void
setMaxTotal
(int max) void
setValidateAfterInactivity
(int ms) void
shutdown()
Shuts down the pool.toString()
protected boolean
-
Field Details
-
lock
-
condition
-
connFactory
-
routeToPool
-
leased
-
available
-
pending
-
maxPerRoute
-
isShutDown
private volatile boolean isShutDown -
defaultMaxPerRoute
private volatile int defaultMaxPerRoute -
maxTotal
private volatile int maxTotal -
validateAfterInactivity
private volatile int validateAfterInactivity
-
-
Constructor Details
-
AbstractConnPool
-
-
Method Details
-
createEntry
Creates a new entry for the given connection with the given route. -
onLease
- Since:
- 4.3
-
onRelease
- Since:
- 4.3
-
onReuse
- Since:
- 4.4
-
validate
- Since:
- 4.4
-
isShutdown
public boolean isShutdown() -
shutdown
Shuts down the pool.- Throws:
IOException
-
getPool
-
operationAborted
-
lease
Attempts to lease a connection for the given route and with the given state from the pool.Please note that this class does not maintain its own pool of execution
Thread
s. Therefore, one must callFuture.get()
orFuture.get(long, TimeUnit)
method on theFuture
returned by this method in order for the lease operation to complete.- Specified by:
lease
in interfaceConnPool<T,
C> - 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
.callback
- operation completion callback.- Returns:
- future for a leased pool entry.
-
lease
Attempts to lease a connection for the given route and with the given state from the pool.Please note that this class does not maintain its own pool of execution
Thread
s. Therefore, one must callFuture.get()
orFuture.get(long, TimeUnit)
method on theFuture
returned by this method in order for the lease operation to complete.- 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
.- Returns:
- future for a leased pool entry.
-
getPoolEntryBlocking
private E getPoolEntryBlocking(T route, Object state, long timeout, TimeUnit timeUnit, Future<E> future) throws IOException, InterruptedException, ExecutionException, TimeoutException -
release
Description copied from interface:ConnPool
Releases the pool entry back to the pool. -
getMax
-
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
- Specified by:
setMaxPerRoute
in interfaceConnPoolControl<T>
-
getMaxPerRoute
- Specified by:
getMaxPerRoute
in interfaceConnPoolControl<T>
-
getTotalStats
- Specified by:
getTotalStats
in interfaceConnPoolControl<T>
-
getStats
- Specified by:
getStats
in interfaceConnPoolControl<T>
-
getRoutes
Returns snapshot of all knows routes- Returns:
- the set of routes
- Since:
- 4.4
-
enumAvailable
Enumerates all available connections.- Since:
- 4.3
-
enumLeased
Enumerates all leased connections.- Since:
- 4.3
-
purgePoolMap
private void purgePoolMap() -
closeIdle
Closes connections that have been idle longer than the given period of time and evicts them from the pool.- Parameters:
idletime
- maximum idle time.timeUnit
- time unit.
-
closeExpired
public void closeExpired()Closes expired connections and evicts them from the pool. -
getValidateAfterInactivity
public int getValidateAfterInactivity()- Returns:
- the number of milliseconds
- Since:
- 4.4
-
setValidateAfterInactivity
public void setValidateAfterInactivity(int ms) - Parameters:
ms
- the number of milliseconds- Since:
- 4.4
-
toString
-