|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.http.impl.conn.tsccm.AbstractConnPool
org.apache.http.impl.conn.tsccm.ConnPoolByRoute
public class ConnPoolByRoute
A connection pool that maintains connections by route.
This class is derived from MultiThreadedHttpConnectionManager
in HttpClient 3.x, see there for original authors. It implements the same
algorithm for connection re-use and connection-per-host enforcement:
poolLock
in the base class,
not via synchronized
methods.
Field Summary | |
---|---|
protected Queue<BasicPoolEntry> |
freeConnections
The list of free connections |
protected ClientConnectionOperator |
operator
Connection operator for this pool |
protected Map<HttpRoute,RouteSpecificPool> |
routeToPool
A map of route-specific pools. |
protected Queue<WaitingThread> |
waitingThreads
The list of WaitingThreads waiting for a connection |
Fields inherited from class org.apache.http.impl.conn.tsccm.AbstractConnPool |
---|
idleConnHandler, isShutDown, issuedConnections, leasedConnections, numConnections, poolLock, refQueue |
Constructor Summary | |
---|---|
ConnPoolByRoute(ClientConnectionOperator operator,
HttpParams params)
Creates a new connection pool, managed by route. |
Method Summary | |
---|---|
protected BasicPoolEntry |
createEntry(RouteSpecificPool rospl,
ClientConnectionOperator op)
Creates a new pool entry. |
protected Queue<BasicPoolEntry> |
createFreeConnQueue()
Creates the queue for freeConnections . |
protected Map<HttpRoute,RouteSpecificPool> |
createRouteToPoolMap()
Creates the map for routeToPool . |
protected Queue<WaitingThread> |
createWaitingThreadQueue()
Creates the queue for waitingThreads . |
void |
deleteClosedConnections()
Deletes all entries for closed connections. |
protected void |
deleteEntry(BasicPoolEntry entry)
Deletes a given pool entry. |
protected void |
deleteLeastUsedEntry()
Delete an old, free pool entry to make room for a new one. |
void |
freeEntry(BasicPoolEntry entry,
boolean reusable,
long validDuration,
TimeUnit timeUnit)
Returns an entry into the pool. |
int |
getConnectionsInPool(HttpRoute route)
|
protected BasicPoolEntry |
getEntryBlocking(HttpRoute route,
Object state,
long timeout,
TimeUnit tunit,
WaitingThreadAborter aborter)
Obtains a pool entry with a connection within the given timeout. |
protected BasicPoolEntry |
getFreeEntry(RouteSpecificPool rospl,
Object state)
If available, get a free pool entry for a route. |
protected RouteSpecificPool |
getRoutePool(HttpRoute route,
boolean create)
Get a route-specific pool of available connections. |
protected void |
handleLostEntry(HttpRoute route)
|
protected RouteSpecificPool |
newRouteSpecificPool(HttpRoute route)
Creates a new route-specific pool. |
protected WaitingThread |
newWaitingThread(Condition cond,
RouteSpecificPool rospl)
Creates a new waiting thread. |
protected void |
notifyWaitingThread(RouteSpecificPool rospl)
Notifies a waiting thread that a connection is available. |
PoolEntryRequest |
requestPoolEntry(HttpRoute route,
Object state)
Returns a new PoolEntryRequest , from which a BasicPoolEntry
can be obtained, or the request can be aborted. |
void |
shutdown()
Shuts down this pool and all associated resources. |
Methods inherited from class org.apache.http.impl.conn.tsccm.AbstractConnPool |
---|
closeConnection, closeExpiredConnections, closeIdleConnections, enableConnectionGC, getEntry, handleReference |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final ClientConnectionOperator operator
protected final Queue<BasicPoolEntry> freeConnections
protected final Queue<WaitingThread> waitingThreads
protected final Map<HttpRoute,RouteSpecificPool> routeToPool
HttpRoute
,
values of class RouteSpecificPool
.
Constructor Detail |
---|
public ConnPoolByRoute(ClientConnectionOperator operator, HttpParams params)
Method Detail |
---|
protected Queue<BasicPoolEntry> createFreeConnQueue()
freeConnections
.
Called once by the constructor.
protected Queue<WaitingThread> createWaitingThreadQueue()
waitingThreads
.
Called once by the constructor.
protected Map<HttpRoute,RouteSpecificPool> createRouteToPoolMap()
routeToPool
.
Called once by the constructor.
protected RouteSpecificPool newRouteSpecificPool(HttpRoute route)
getRoutePool(org.apache.http.conn.routing.HttpRoute, boolean)
when necessary.
route
- the route
protected WaitingThread newWaitingThread(Condition cond, RouteSpecificPool rospl)
getRoutePool(org.apache.http.conn.routing.HttpRoute, boolean)
when necessary.
cond
- the condition to wait forrospl
- the route specific pool, or null
protected RouteSpecificPool getRoutePool(HttpRoute route, boolean create)
route
- the routecreate
- whether to create the pool if it doesn't exist
null
if create
is true
public int getConnectionsInPool(HttpRoute route)
public PoolEntryRequest requestPoolEntry(HttpRoute route, Object state)
AbstractConnPool
PoolEntryRequest
, from which a BasicPoolEntry
can be obtained, or the request can be aborted.
requestPoolEntry
in class AbstractConnPool
protected BasicPoolEntry getEntryBlocking(HttpRoute route, Object state, long timeout, TimeUnit tunit, WaitingThreadAborter aborter) throws ConnectionPoolTimeoutException, InterruptedException
WaitingThread
is used to block, WaitingThreadAborter.setWaitingThread(WaitingThread)
must be called before blocking, to allow the thread to be interrupted.
route
- the route for which to get the connectiontimeout
- the timeout, 0 or negative for no timeouttunit
- the unit for the timeout
,
may be null
only if there is no timeoutaborter
- an object which can abort a WaitingThread
.
ConnectionPoolTimeoutException
- if the timeout expired
InterruptedException
- if the calling thread was interruptedpublic void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit)
AbstractConnPool
freeEntry
in class AbstractConnPool
entry
- the entry for the connection to releasereusable
- true
if the entry is deemed
reusable, false
otherwise.validDuration
- The duration that the entry should remain free and reusable.timeUnit
- The unit of time the duration is measured in.protected BasicPoolEntry getFreeEntry(RouteSpecificPool rospl, Object state)
rospl
- the route-specific pool from which to get an entry
null
if none is availableprotected BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op)
rospl
- the route-specific pool for which to create the entryop
- the operator for creating a connection
protected void deleteEntry(BasicPoolEntry entry)
Note: Does not remove the entry from the freeConnections list. It is assumed that the caller has already handled this step.
entry
- the pool entry for the connection to deleteprotected void deleteLeastUsedEntry()
protected void handleLostEntry(HttpRoute route)
handleLostEntry
in class AbstractConnPool
protected void notifyWaitingThread(RouteSpecificPool rospl)
rospl
- the pool in which to notify, or null
public void deleteClosedConnections()
AbstractConnPool
deleteClosedConnections
in class AbstractConnPool
public void shutdown()
AbstractConnPool
shutdown
in class AbstractConnPool
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |