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.@Contract(threading=SAFE_CONDITIONAL) public abstract class AbstractConnPool<T,C,E extends PoolEntry<T,C>> extends Object implements ConnPool<T,E>, ConnPoolControl<T>
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.
Constructor and Description |
---|
AbstractConnPool(ConnFactory<T,C> connFactory,
int defaultMaxPerRoute,
int maxTotal) |
Modifier and Type | Method and Description |
---|---|
void |
closeExpired()
Closes expired connections and evicts them from the pool.
|
void |
closeIdle(long idletime,
TimeUnit timeUnit)
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 |
getDefaultMaxPerRoute() |
int |
getMaxPerRoute(T route) |
int |
getMaxTotal() |
Set<T> |
getRoutes()
Returns snapshot of all knows routes
|
PoolStats |
getStats(T route) |
PoolStats |
getTotalStats() |
int |
getValidateAfterInactivity() |
boolean |
isShutdown() |
Future<E> |
lease(T route,
Object state)
Attempts to lease a connection for the given route and with the given
state from the pool.
|
Future<E> |
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 |
onLease(E entry) |
protected void |
onRelease(E entry) |
protected void |
onReuse(E entry) |
void |
release(E 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) |
void |
setValidateAfterInactivity(int ms) |
void |
shutdown()
Shuts down the pool.
|
String |
toString() |
protected boolean |
validate(E entry) |
public AbstractConnPool(ConnFactory<T,C> connFactory, int defaultMaxPerRoute, int maxTotal)
protected abstract E createEntry(T route, C conn)
protected void onLease(E entry)
protected void onRelease(E entry)
protected void onReuse(E entry)
protected boolean validate(E entry)
public boolean isShutdown()
public void shutdown() throws IOException
IOException
public Future<E> lease(T route, Object state, FutureCallback<E> callback)
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
returned by this method in order for the lease operation to complete.
lease
in interface ConnPool<T,E extends PoolEntry<T,C>>
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 be null
.callback
- operation completion callback.public Future<E> lease(T route, Object state)
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
returned by this method in order for the lease operation to complete.
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 be null
.public void release(E entry, boolean reusable)
ConnPool
public void setMaxTotal(int max)
setMaxTotal
in interface ConnPoolControl<T>
public int getMaxTotal()
getMaxTotal
in interface ConnPoolControl<T>
public void setDefaultMaxPerRoute(int max)
setDefaultMaxPerRoute
in interface ConnPoolControl<T>
public int getDefaultMaxPerRoute()
getDefaultMaxPerRoute
in interface ConnPoolControl<T>
public void setMaxPerRoute(T route, int max)
setMaxPerRoute
in interface ConnPoolControl<T>
public int getMaxPerRoute(T route)
getMaxPerRoute
in interface ConnPoolControl<T>
public PoolStats getTotalStats()
getTotalStats
in interface ConnPoolControl<T>
public PoolStats getStats(T route)
getStats
in interface ConnPoolControl<T>
public Set<T> getRoutes()
protected void enumAvailable(PoolEntryCallback<T,C> callback)
protected void enumLeased(PoolEntryCallback<T,C> callback)
public void closeIdle(long idletime, TimeUnit timeUnit)
idletime
- maximum idle time.timeUnit
- time unit.public void closeExpired()
public int getValidateAfterInactivity()
public void setValidateAfterInactivity(int ms)
ms
- the number of millisecondsCopyright © 2005–2022 The Apache Software Foundation. All rights reserved.