public abstract class AbstractConnPool extends java.lang.Object implements RefQueueHandler
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!Modifier and Type | Field and Description |
---|---|
protected IdleConnectionHandler |
idleConnHandler
The handler for idle connections.
|
protected boolean |
isShutDown
Indicates whether this pool is shut down.
|
protected java.util.Set |
issuedConnections |
protected java.util.Set |
leasedConnections
References to issued connections.
|
protected int |
numConnections
The current total number of connections.
|
Lock |
poolLock
The global lock for this pool.
|
protected java.lang.ref.ReferenceQueue |
refQueue |
Modifier | Constructor and Description |
---|---|
protected |
AbstractConnPool()
Creates a new connection pool.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeConnection(OperatedClientConnection conn)
Closes a connection from this pool.
|
void |
closeExpiredConnections() |
void |
closeIdleConnections(long idletime)
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)
Returns an entry into the pool.
|
BasicPoolEntry |
getEntry(HttpRoute route,
java.lang.Object state,
long timeout)
Obtains a pool entry with a connection within the given timeout.
|
protected abstract void |
handleLostEntry(HttpRoute route) |
void |
handleReference(java.lang.ref.Reference ref)
Invoked when a reference is found on the queue.
|
abstract 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.
|
public final Lock poolLock
protected java.util.Set leasedConnections
protected IdleConnectionHandler idleConnHandler
protected int numConnections
protected volatile boolean isShutDown
protected java.util.Set issuedConnections
protected java.lang.ref.ReferenceQueue refQueue
public void enableConnectionGC() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public final BasicPoolEntry getEntry(HttpRoute route, java.lang.Object state, long timeout) throws ConnectionPoolTimeoutException, java.lang.InterruptedException
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 timeoutConnectionPoolTimeoutException
- if the timeout expiredjava.lang.InterruptedException
- if the calling thread was interruptedpublic abstract PoolEntryRequest requestPoolEntry(HttpRoute route, java.lang.Object state)
PoolEntryRequest
, from which a BasicPoolEntry
can be obtained, or the request can be aborted.public abstract void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration)
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.timeUnit
- The unit of time the duration is measured in.public void handleReference(java.lang.ref.Reference ref)
RefQueueHandler
handleReference
in interface RefQueueHandler
ref
- the reference to handleprotected abstract void handleLostEntry(HttpRoute route)
public void closeIdleConnections(long idletime)
idletime
- the time the connections should have been idle
in order to be closed nowtunit
- the unit for the idletime
public void closeExpiredConnections()
public abstract void deleteClosedConnections()
public void shutdown()
protected void closeConnection(OperatedClientConnection conn)
conn
- the connection to close, or null