Class AbstractConnPool<T,C,E extends PoolEntry<T,C>>
- java.lang.Object
-
- org.apache.http.pool.AbstractConnPool<T,C,E>
-
- 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
@Contract(threading=SAFE_CONDITIONAL) public abstract class AbstractConnPool<T,C,E extends PoolEntry<T,C>> extends java.lang.Object implements ConnPool<T,E>, ConnPoolControl<T>
Abstract synchronous (blocking) pool of connections.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
object returned by thelease(Object, Object, FutureCallback)
method in order for the lease operation to complete.- Since:
- 4.2
-
-
Constructor Summary
Constructors Constructor Description AbstractConnPool(ConnFactory<T,C> connFactory, int defaultMaxPerRoute, int maxTotal)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeExpired()
Closes expired connections and evicts them from the pool.void
closeIdle(long idletime, java.util.concurrent.TimeUnit tunit)
Closes connections that have been idle longer than the given period of time and evicts them from the pool.int
getDefaultMaxPerRoute()
int
getMaxPerRoute(T route)
int
getMaxTotal()
java.util.Set<T>
getRoutes()
Returns snapshot of all knows routesPoolStats
getStats(T route)
PoolStats
getTotalStats()
int
getValidateAfterInactivity()
boolean
isShutdown()
java.util.concurrent.Future<E>
lease(T route, java.lang.Object state)
Attempts to lease a connection for the given route and with the given state from the pool.java.util.concurrent.Future<E>
lease(T route, java.lang.Object state, FutureCallback<E> callback)
Attempts to lease a connection for the given route and with the given state from the pool.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.java.lang.String
toString()
-
-
-
Constructor Detail
-
AbstractConnPool
public AbstractConnPool(ConnFactory<T,C> connFactory, int defaultMaxPerRoute, int maxTotal)
-
-
Method Detail
-
isShutdown
public boolean isShutdown()
-
shutdown
public void shutdown() throws java.io.IOException
Shuts down the pool.- Throws:
java.io.IOException
-
lease
public java.util.concurrent.Future<E> lease(T route, java.lang.Object state, FutureCallback<E> callback)
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
public java.util.concurrent.Future<E> lease(T route, java.lang.Object state)
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.
-
release
public void release(E entry, boolean reusable)
Description copied from interface:ConnPool
Releases the pool entry back to the pool.
-
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 interfaceConnPoolControl<T>
-
getStats
public PoolStats getStats(T route)
- Specified by:
getStats
in interfaceConnPoolControl<T>
-
getRoutes
public java.util.Set<T> getRoutes()
Returns snapshot of all knows routes- Returns:
- the set of routes
- Since:
- 4.4
-
closeIdle
public void closeIdle(long idletime, java.util.concurrent.TimeUnit tunit)
Closes connections that have been idle longer than the given period of time and evicts them from the pool.- Parameters:
idletime
- maximum idle time.tunit
- 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-