to top
Android APIs
public class

ConnPoolByRoute

extends AbstractConnPool
java.lang.Object
   ↳ org.apache.http.impl.conn.tsccm.AbstractConnPool
     ↳ org.apache.http.impl.conn.tsccm.ConnPoolByRoute

Class Overview

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:

  • connections are re-used only for the exact same route
  • connection limits are enforced per route rather than per host
Note that access to the pool datastructures is synchronized via the poolLock in the base class, not via synchronized methods.

Summary

Fields
protected Queue<BasicPoolEntry> freeConnections The list of free connections
protected final int maxTotalConnections
protected final ClientConnectionOperator operator Connection operator for this pool
protected final Map<HttpRouteRouteSpecificPool> routeToPool A map of route-specific pools.
protected Queue<WaitingThread> waitingThreads The list of WaitingThreads waiting for a connection
[Expand]
Inherited Fields
From class org.apache.http.impl.conn.tsccm.AbstractConnPool
Public Constructors
ConnPoolByRoute(ClientConnectionOperator operator, HttpParams params)
Creates a new connection pool, managed by route.
Public Methods
void deleteClosedConnections()
Deletes all entries for closed connections.
void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit)
Returns an entry into the pool.
int getConnectionsInPool(HttpRoute route)
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.
Protected Methods
BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op)
Creates a new pool entry.
Queue<BasicPoolEntry> createFreeConnQueue()
Creates the queue for freeConnections.
Map<HttpRouteRouteSpecificPool> createRouteToPoolMap()
Creates the map for routeToPool.
Queue<WaitingThread> createWaitingThreadQueue()
Creates the queue for waitingThreads.
void deleteEntry(BasicPoolEntry entry)
Deletes a given pool entry.
void deleteLeastUsedEntry()
Delete an old, free pool entry to make room for a new one.
BasicPoolEntry getEntryBlocking(HttpRoute route, Object state, long timeout, TimeUnit tunit, WaitingThreadAborter aborter)
Obtains a pool entry with a connection within the given timeout.
BasicPoolEntry getFreeEntry(RouteSpecificPool rospl, Object state)
If available, get a free pool entry for a route.
RouteSpecificPool getRoutePool(HttpRoute route, boolean create)
Get a route-specific pool of available connections.
void handleLostEntry(HttpRoute route)
Handles cleaning up for a lost pool entry with the given route.
RouteSpecificPool newRouteSpecificPool(HttpRoute route)
Creates a new route-specific pool.
WaitingThread newWaitingThread(Condition cond, RouteSpecificPool rospl)
Creates a new waiting thread.
void notifyWaitingThread(RouteSpecificPool rospl)
Notifies a waiting thread that a connection is available.
[Expand]
Inherited Methods
From class org.apache.http.impl.conn.tsccm.AbstractConnPool
From class java.lang.Object
From interface org.apache.http.impl.conn.tsccm.RefQueueHandler

Fields

protected Queue<BasicPoolEntry> freeConnections

Since: API Level 1

The list of free connections

protected final int maxTotalConnections

Since: API Level 1

protected final ClientConnectionOperator operator

Since: API Level 1

Connection operator for this pool

protected final Map<HttpRouteRouteSpecificPool> routeToPool

Since: API Level 1

A map of route-specific pools. Keys are of class HttpRoute, values of class RouteSpecificPool.

protected Queue<WaitingThread> waitingThreads

Since: API Level 1

The list of WaitingThreads waiting for a connection

Public Constructors

public ConnPoolByRoute (ClientConnectionOperator operator, HttpParams params)

Since: API Level 1

Creates a new connection pool, managed by route.

Public Methods

public void deleteClosedConnections ()

Since: API Level 1

Deletes all entries for closed connections.

public void freeEntry (BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit)

Since: API Level 1

Returns an entry into the pool. The connection of the entry is expected to be in a suitable state, either open and re-usable, or closed. The pool will not make any attempt to determine whether it can be re-used or not.

Parameters
entry the entry for the connection to release
reusable 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.

public int getConnectionsInPool (HttpRoute route)

Since: API Level 1

public PoolEntryRequest requestPoolEntry (HttpRoute route, Object state)

Since: API Level 1

Returns a new PoolEntryRequest, from which a BasicPoolEntry can be obtained, or the request can be aborted.

public void shutdown ()

Since: API Level 1

Shuts down this pool and all associated resources. Overriding methods MUST call the implementation here!

Protected Methods

protected BasicPoolEntry createEntry (RouteSpecificPool rospl, ClientConnectionOperator op)

Since: API Level 1

Creates a new pool entry. This method assumes that the new connection will be handed out immediately.

Parameters
rospl the route-specific pool for which to create the entry
op the operator for creating a connection
Returns
  • the new pool entry for a new connection

protected Queue<BasicPoolEntry> createFreeConnQueue ()

Since: API Level 1

Creates the queue for freeConnections. Called once by the constructor.

Returns
  • a queue

protected Map<HttpRouteRouteSpecificPool> createRouteToPoolMap ()

Since: API Level 1

Creates the map for routeToPool. Called once by the constructor.

Returns
  • a map

protected Queue<WaitingThread> createWaitingThreadQueue ()

Since: API Level 1

Creates the queue for waitingThreads. Called once by the constructor.

Returns
  • a queue

protected void deleteEntry (BasicPoolEntry entry)

Since: API Level 1

Deletes a given pool entry. This closes the pooled connection and removes all references, so that it can be GCed.

Note: Does not remove the entry from the freeConnections list. It is assumed that the caller has already handled this step.

Parameters
entry the pool entry for the connection to delete

protected void deleteLeastUsedEntry ()

Since: API Level 1

Delete an old, free pool entry to make room for a new one. Used to replace pool entries with ones for a different route.

protected BasicPoolEntry getEntryBlocking (HttpRoute route, Object state, long timeout, TimeUnit tunit, WaitingThreadAborter aborter)

Since: API Level 1

Obtains a pool entry with a connection within the given timeout. If a WaitingThread is used to block, setWaitingThread(WaitingThread) must be called before blocking, to allow the thread to be interrupted.

Parameters
route the route for which to get the connection
timeout the timeout, 0 or negative for no timeout
tunit the unit for the timeout, may be null only if there is no timeout
aborter an object which can abort a WaitingThread.
Returns
  • pool entry holding a connection for the route
Throws
ConnectionPoolTimeoutException if the timeout expired
InterruptedException if the calling thread was interrupted

protected BasicPoolEntry getFreeEntry (RouteSpecificPool rospl, Object state)

Since: API Level 1

If available, get a free pool entry for a route.

Parameters
rospl the route-specific pool from which to get an entry
Returns
  • an available pool entry for the given route, or null if none is available

protected RouteSpecificPool getRoutePool (HttpRoute route, boolean create)

Since: API Level 1

Get a route-specific pool of available connections.

Parameters
route the route
create whether to create the pool if it doesn't exist
Returns
  • the pool for the argument route, never null if create is true

protected void handleLostEntry (HttpRoute route)

Since: API Level 1

Handles cleaning up for a lost pool entry with the given route. A lost pool entry corresponds to a connection that was garbage collected instead of being properly released.

Parameters
route the route of the pool entry that was lost

protected RouteSpecificPool newRouteSpecificPool (HttpRoute route)

Since: API Level 1

Creates a new route-specific pool. Called by getRoutePool(HttpRoute, boolean) when necessary.

Parameters
route the route
Returns
  • the new pool

protected WaitingThread newWaitingThread (Condition cond, RouteSpecificPool rospl)

Since: API Level 1

Creates a new waiting thread. Called by getRoutePool(HttpRoute, boolean) when necessary.

Parameters
cond the condition to wait for
rospl the route specific pool, or null
Returns
  • a waiting thread representation

protected void notifyWaitingThread (RouteSpecificPool rospl)

Since: API Level 1

Notifies a waiting thread that a connection is available. This will wake a thread waiting in the specific route pool, if there is one. Otherwise, a thread in the connection pool will be notified.

Parameters
rospl the pool in which to notify, or null