org.apache.http.impl.conn.tsccm
Class AbstractConnPool

java.lang.Object
  extended by org.apache.http.impl.conn.tsccm.AbstractConnPool
All Implemented Interfaces:
RefQueueHandler
Direct Known Subclasses:
ConnPoolByRoute

@ThreadSafe
public abstract class AbstractConnPool
extends Object
implements RefQueueHandler

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!

Since:
4.0

Field Summary
protected  IdleConnectionHandler idleConnHandler
          The handler for idle connections.
protected  boolean isShutDown
          Indicates whether this pool is shut down.
protected  Set<BasicPoolEntryRef> issuedConnections
          Deprecated. 
protected  Set<BasicPoolEntry> leasedConnections
          References to issued connections.
protected  int numConnections
          The current total number of connections.
protected  Lock poolLock
          The global lock for this pool.
protected  ReferenceQueue<Object> refQueue
          Deprecated. 
 
Constructor Summary
protected AbstractConnPool()
          Creates a new connection pool.
 
Method Summary
protected  void closeConnection(OperatedClientConnection conn)
          Closes a connection from this pool.
 void closeExpiredConnections()
           
 void closeIdleConnections(long idletime, TimeUnit tunit)
          Closes idle connections.
abstract  void deleteClosedConnections()
          Deletes all entries for closed connections.
 void enableConnectionGC()
          Deprecated. do not sue
abstract  void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit)
          Returns an entry into the pool.
 BasicPoolEntry getEntry(HttpRoute route, Object state, long timeout, TimeUnit tunit)
          Obtains a pool entry with a connection within the given timeout.
protected abstract  void handleLostEntry(HttpRoute route)
          Deprecated. 
 void handleReference(Reference<?> ref)
          Deprecated. 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

poolLock

protected final Lock poolLock
The global lock for this pool.


leasedConnections

@GuardedBy(value="poolLock")
protected Set<BasicPoolEntry> leasedConnections
References to issued connections. Must hold poolLock when accessing.


idleConnHandler

@GuardedBy(value="poolLock")
protected IdleConnectionHandler idleConnHandler
The handler for idle connections. Must hold poolLock when accessing.


numConnections

@GuardedBy(value="poolLock")
protected int numConnections
The current total number of connections.


isShutDown

protected volatile boolean isShutDown
Indicates whether this pool is shut down.


issuedConnections

@Deprecated
protected Set<BasicPoolEntryRef> issuedConnections
Deprecated. 

refQueue

@Deprecated
protected ReferenceQueue<Object> refQueue
Deprecated. 
Constructor Detail

AbstractConnPool

protected AbstractConnPool()
Creates a new connection pool.

Method Detail

enableConnectionGC

@Deprecated
public void enableConnectionGC()
                        throws IllegalStateException
Deprecated. do not sue

Throws:
IllegalStateException

getEntry

public 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.

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

requestPoolEntry

public abstract PoolEntryRequest requestPoolEntry(HttpRoute route,
                                                  Object state)
Returns a new PoolEntryRequest, from which a BasicPoolEntry can be obtained, or the request can be aborted.


freeEntry

public abstract void freeEntry(BasicPoolEntry entry,
                               boolean reusable,
                               long validDuration,
                               TimeUnit timeUnit)
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.

handleReference

@Deprecated
public void handleReference(Reference<?> ref)
Deprecated. 

Description copied from interface: RefQueueHandler
Invoked when a reference is found on the queue.

Specified by:
handleReference in interface RefQueueHandler
Parameters:
ref - the reference to handle

handleLostEntry

@Deprecated
protected abstract void handleLostEntry(HttpRoute route)
Deprecated. 


closeIdleConnections

public void closeIdleConnections(long idletime,
                                 TimeUnit tunit)
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

closeExpiredConnections

public void closeExpiredConnections()

deleteClosedConnections

public abstract void deleteClosedConnections()
Deletes all entries for closed connections.


shutdown

public void shutdown()
Shuts down this pool and all associated resources. Overriding methods MUST call the implementation here!


closeConnection

protected void closeConnection(OperatedClientConnection conn)
Closes a connection from this pool.

Parameters:
conn - the connection to close, or null


Copyright © 1999-2010 Apache Software Foundation. All Rights Reserved.