to top
Android APIs
public abstract class

AbstractConnPool

extends Object
implements RefQueueHandler
java.lang.Object
   ↳ org.apache.http.impl.conn.tsccm.AbstractConnPool
Known Direct Subclasses

Class Overview

An abstract connection pool. It is used by the ThreadSafeClientConnManager. The abstract pool includes a poolLock, which is used to synchronize access to the internal pool datastructures. Don't use synchronized for that purpose!

Summary

Fields
protected IdleConnectionHandler idleConnHandler The handler for idle connections.
protected boolean isShutDown Indicates whether this pool is shut down.
protected Set<BasicPoolEntryRef> issuedConnections References to issued connections.
protected int numConnections The current total number of connections.
protected final Lock poolLock The global lock for this pool.
protected ReferenceQueue<Object> refQueue A reference queue to track loss of pool entries to GC.
Protected Constructors
AbstractConnPool()
Creates a new connection pool.
Public Methods
void closeExpiredConnections()
void closeIdleConnections(long idletime, TimeUnit tunit)
Closes idle connections.
abstract void deleteClosedConnections()
Deletes all entries for closed connections.
void enableConnectionGC()
Enables connection garbage collection (GC).
abstract void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit)
Returns an entry into the pool.
final BasicPoolEntry getEntry(HttpRoute route, Object state, long timeout, TimeUnit tunit)
Obtains a pool entry with a connection within the given timeout.
void handleReference(Reference ref)
abstract 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
void closeConnection(OperatedClientConnection conn)
Closes a connection from this pool.
abstract void handleLostEntry(HttpRoute route)
Handles cleaning up for a lost pool entry with the given route.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.http.impl.conn.tsccm.RefQueueHandler

Fields

protected IdleConnectionHandler idleConnHandler

Since: API Level 1

The handler for idle connections.

protected boolean isShutDown

Since: API Level 1

Indicates whether this pool is shut down.

protected Set<BasicPoolEntryRef> issuedConnections

Since: API Level 1

References to issued connections. Objects in this set are of class BasicPoolEntryRef, and point to the pool entry for the issued connection. GCed connections are detected by the missing pool entries.

protected int numConnections

Since: API Level 1

The current total number of connections.

protected final Lock poolLock

Since: API Level 1

The global lock for this pool.

protected ReferenceQueue<Object> refQueue

Since: API Level 1

A reference queue to track loss of pool entries to GC. The same queue is used to track loss of the connection manager, so we cannot specialize the type.

Protected Constructors

protected AbstractConnPool ()

Since: API Level 1

Creates a new connection pool.

Public Methods

public void closeExpiredConnections ()

Since: API Level 1

public void closeIdleConnections (long idletime, TimeUnit tunit)

Since: API Level 1

Closes idle connections.

Parameters
idletime the time the connections should have been idle in order to be closed now
tunit the unit for the idletime

public abstract void deleteClosedConnections ()

Since: API Level 1

Deletes all entries for closed connections.

public void enableConnectionGC ()

Since: API Level 1

Enables connection garbage collection (GC). This method must be called immediately after creating the connection pool. It is not possible to enable connection GC after pool entries have been created. Neither is it possible to disable connection GC.

Throws
IllegalStateException if connection GC is already enabled, or if it cannot be enabled because there already are pool entries

public abstract 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 final BasicPoolEntry getEntry (HttpRoute route, Object state, long timeout, TimeUnit tunit)

Since: API Level 1

Obtains a pool entry with a connection within the given timeout.

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
Returns
  • pool entry holding a connection for the route
Throws
ConnectionPoolTimeoutException if the timeout expired
InterruptedException if the calling thread was interrupted

public void handleReference (Reference ref)

Since: API Level 1

public abstract 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 void closeConnection (OperatedClientConnection conn)

Since: API Level 1

Closes a connection from this pool.

Parameters
conn the connection to close, or null

protected abstract 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