public class ConnPoolByRoute extends AbstractConnPool
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.Modifier and Type | Field and Description |
---|---|
protected java.util.LinkedList |
freeConnections
The list of free connections
|
protected ClientConnectionOperator |
operator
Connection operator for this pool
|
protected java.util.Map |
routeToPool
A map of route-specific pools.
|
protected java.util.LinkedList |
waitingThreads
The list of WaitingThreads waiting for a connection
|
idleConnHandler, isShutDown, issuedConnections, leasedConnections, numConnections, poolLock, refQueue
Constructor and Description |
---|
ConnPoolByRoute(ClientConnectionOperator operator,
HttpParams params)
Creates a new connection pool, managed by route.
|
Modifier and Type | Method and Description |
---|---|
protected BasicPoolEntry |
createEntry(RouteSpecificPool rospl,
ClientConnectionOperator op)
Creates a new pool entry.
|
protected java.util.LinkedList |
createFreeConnQueue()
Creates the queue for
freeConnections . |
protected java.util.Map |
createRouteToPoolMap()
Creates the map for
routeToPool . |
protected java.util.LinkedList |
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)
Returns an entry into the pool.
|
int |
getConnectionsInPool(HttpRoute route) |
protected BasicPoolEntry |
getEntryBlocking(HttpRoute route,
java.lang.Object state,
long timeout,
WaitingThreadAborter aborter)
Obtains a pool entry with a connection within the given timeout.
|
protected BasicPoolEntry |
getFreeEntry(RouteSpecificPool rospl,
java.lang.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,
java.lang.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.
|
closeConnection, closeExpiredConnections, closeIdleConnections, enableConnectionGC, getEntry, handleReference
protected final ClientConnectionOperator operator
protected final java.util.LinkedList freeConnections
protected final java.util.LinkedList waitingThreads
protected final java.util.Map routeToPool
HttpRoute
,
values of class RouteSpecificPool
.public ConnPoolByRoute(ClientConnectionOperator operator, HttpParams params)
protected java.util.LinkedList createFreeConnQueue()
freeConnections
.
Called once by the constructor.protected java.util.LinkedList createWaitingThreadQueue()
waitingThreads
.
Called once by the constructor.protected java.util.Map createRouteToPoolMap()
routeToPool
.
Called once by the constructor.protected RouteSpecificPool newRouteSpecificPool(HttpRoute route)
getRoutePool(org.apache.http.conn.routing.HttpRoute, boolean)
when necessary.route
- the routeprotected 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 existnull
if create
is true
public int getConnectionsInPool(HttpRoute route)
public PoolEntryRequest requestPoolEntry(HttpRoute route, java.lang.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, java.lang.Object state, long timeout, WaitingThreadAborter aborter) throws ConnectionPoolTimeoutException, java.lang.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 expiredjava.lang.InterruptedException
- if the calling thread was interruptedpublic void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration)
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.protected BasicPoolEntry getFreeEntry(RouteSpecificPool rospl, java.lang.Object state)
rospl
- the route-specific pool from which to get an entrynull
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 connectionprotected 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