• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
ConnPoolByRoute Class Reference

A connection pool that maintains connections by route. More...

Inheritance diagram for ConnPoolByRoute:
AbstractConnPool RefQueueHandler

Description

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 poolLock in the base class, not via synchronized methods.

Author
Roland Weber
Michael Becke
and others

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Public Member Functions

 ConnPoolByRoute (final ClientConnectionOperator operator, final HttpParams params)
 Creates a new connection pool, managed by route.
 
PoolEntryRequest requestPoolEntry (final HttpRoute route, final Object state)
 Returns a new com.good.gd.apache.http.impl.conn.tsccm.PoolEntryRequest, from which a com.good.gd.apache.http.impl.conn.tsccm.BasicPoolEntry can be obtained, or the request can be aborted. More...
 
void freeEntry (BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit)
 Returns an entry into the pool. More...
 
void deleteClosedConnections ()
 Deletes all entries for closed connections.
 
void shutdown ()
 Shuts down this pool and all associated resources. More...
 
- Public Member Functions inherited from AbstractConnPool
void enableConnectionGC () throws IllegalStateException
 Enables connection garbage collection (GC). More...
 
final BasicPoolEntry getEntry (HttpRoute route, Object state, long timeout, TimeUnit tunit) throws ConnectionPoolTimeoutException, InterruptedException
 Obtains a pool entry with a connection within the given timeout. More...
 
void closeIdleConnections (long idletime, TimeUnit tunit)
 Closes idle connections. More...
 
- Public Member Functions inherited from RefQueueHandler
void handleReference (Reference<?> ref)
 Invoked when a reference is found on the queue. More...
 

Protected Member Functions

Queue< BasicPoolEntrycreateFreeConnQueue ()
 Creates the queue for freeConnections. More...
 
Queue< WaitingThreadcreateWaitingThreadQueue ()
 Creates the queue for waitingThreads. More...
 
Map< HttpRoute, RouteSpecificPoolcreateRouteToPoolMap ()
 Creates the map for routeToPool. More...
 
RouteSpecificPool newRouteSpecificPool (HttpRoute route)
 Creates a new route-specific pool. More...
 
WaitingThread newWaitingThread (Condition cond, RouteSpecificPool rospl)
 Creates a new waiting thread. More...
 
RouteSpecificPool getRoutePool (HttpRoute route, boolean create)
 Get a route-specific pool of available connections. More...
 
BasicPoolEntry getEntryBlocking (HttpRoute route, Object state, long timeout, TimeUnit tunit, WaitingThreadAborter aborter) throws ConnectionPoolTimeoutException, InterruptedException
 Obtains a pool entry with a connection within the given timeout. More...
 
BasicPoolEntry getFreeEntry (RouteSpecificPool rospl, Object state)
 If available, get a free pool entry for a route. More...
 
BasicPoolEntry createEntry (RouteSpecificPool rospl, ClientConnectionOperator op)
 Creates a new pool entry. More...
 
void deleteEntry (BasicPoolEntry entry)
 Deletes a given pool entry. More...
 
void deleteLeastUsedEntry ()
 Delete an old, free pool entry to make room for a new one. More...
 
void handleLostEntry (HttpRoute route)
 Handles cleaning up for a lost pool entry with the given route. More...
 
void notifyWaitingThread (RouteSpecificPool rospl)
 Notifies a waiting thread that a connection is available. More...
 
- Protected Member Functions inherited from AbstractConnPool
 AbstractConnPool ()
 Creates a new connection pool.
 
void closeConnection (final OperatedClientConnection conn)
 Closes a connection from this pool. More...
 

Protected Attributes

final ClientConnectionOperator operator
 Connection operator for this pool.
 
Queue< BasicPoolEntryfreeConnections
 The list of free connections.
 
Queue< WaitingThreadwaitingThreads
 The list of WaitingThreads waiting for a connection.
 
final Map< HttpRoute, RouteSpecificPoolrouteToPool
 A map of route-specific pools. More...
 
- Protected Attributes inherited from AbstractConnPool
final Lock poolLock
 The global lock for this pool.
 
Set< BasicPoolEntryRefissuedConnections
 References to issued connections. More...
 
IdleConnectionHandler idleConnHandler
 The handler for idle connections. More...
 
int numConnections
 The current total number of connections. More...
 
ReferenceQueue< Object > refQueue
 A reference queue to track loss of pool entries to GC. More...
 
volatile boolean isShutDown
 Indicates whether this pool is shut down. More...
 

Member Function Documentation

◆ createFreeConnQueue()

Queue<BasicPoolEntry> createFreeConnQueue ( )
protected

Called once by the constructor.

Returns
a queue

◆ createWaitingThreadQueue()

Queue<WaitingThread> createWaitingThreadQueue ( )
protected

Called once by the constructor.

Returns
a queue

◆ createRouteToPoolMap()

Map<HttpRoute, RouteSpecificPool> createRouteToPoolMap ( )
protected

Called once by the constructor.

Returns
a map

◆ newRouteSpecificPool()

RouteSpecificPool newRouteSpecificPool ( HttpRoute  route)
protected

Called by getRoutePool when necessary.

Parameters
routethe route
Returns
the new pool

◆ newWaitingThread()

WaitingThread newWaitingThread ( Condition  cond,
RouteSpecificPool  rospl 
)
protected

Called by getRoutePool when necessary.

Parameters
condthe condition to wait for
rosplthe route specific pool, or null
Returns
a waiting thread representation

◆ getRoutePool()

RouteSpecificPool getRoutePool ( HttpRoute  route,
boolean  create 
)
protected
Parameters
routethe route
createwhether to create the pool if it doesn't exist
Returns
the pool for the argument route, never null if create is true

◆ requestPoolEntry()

PoolEntryRequest requestPoolEntry ( final HttpRoute  route,
final Object  state 
)
Parameters
route
state

Reimplemented from AbstractConnPool.

◆ getEntryBlocking()

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

If a com.good.gd.apache.http.impl.conn.tsccm.WaitingThread is used to block, #setWaitingThread(WaitingThread) must be called before blocking, to allow the thread to be interrupted.

Parameters
routethe route for which to get the connection
state
timeoutthe timeout, 0 or negative for no timeout
tunitthe unit for the timeout, may be null only if there is no timeout
aborteran object which can abort a com.good.gd.apache.http.impl.conn.tsccm.WaitingThread.
Returns
pool entry holding a connection for the route
Exceptions
ConnectionPoolTimeoutExceptionif the timeout expired
InterruptedExceptionif the calling thread was interrupted

◆ freeEntry()

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

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
entrythe entry for the connection to release
reusabletrue if the entry is deemed reusable, false otherwise.
validDurationThe duration that the entry should remain free and reusable.
timeUnitThe unit of time the duration is measured in.

Reimplemented from AbstractConnPool.

◆ getFreeEntry()

BasicPoolEntry getFreeEntry ( RouteSpecificPool  rospl,
Object  state 
)
protected
Parameters
rosplthe route-specific pool from which to get an entry
state
Returns
an available pool entry for the given route, or null if none is available

◆ createEntry()

BasicPoolEntry createEntry ( RouteSpecificPool  rospl,
ClientConnectionOperator  op 
)
protected

This method assumes that the new connection will be handed out immediately.

Parameters
rosplthe route-specific pool for which to create the entry
opthe operator for creating a connection
Returns
the new pool entry for a new connection

◆ deleteEntry()

void deleteEntry ( BasicPoolEntry  entry)
protected

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.

<!– @@ is that a good idea? or rather fix it? –>

Parameters
entrythe pool entry for the connection to delete

◆ deleteLeastUsedEntry()

void deleteLeastUsedEntry ( )
protected

Used to replace pool entries with ones for a different route.

◆ handleLostEntry()

void handleLostEntry ( HttpRoute  route)
protected

A lost pool entry corresponds to a connection that was garbage collected instead of being properly released.

Parameters
routethe route of the pool entry that was lost

Reimplemented from AbstractConnPool.

◆ notifyWaitingThread()

void notifyWaitingThread ( RouteSpecificPool  rospl)
protected

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
rosplthe pool in which to notify, or null

◆ shutdown()

void shutdown ( )

Overriding methods MUST call the implementation here!

Reimplemented from AbstractConnPool.

Member Data Documentation

◆ routeToPool