|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.ldaptive.pool.AbstractPool<Connection>
org.ldaptive.pool.AbstractConnectionPool
public abstract class AbstractConnectionPool
Contains the base implementation for pooling connections. The main design
objective for the supplied pooling implementations is to provide a pool that
does not block on connection creation or destruction. This is what accounts
for the multiple locks available on this class. The pool is backed by two
queues, one for available connections and one for active connections.
Connections that are available via getConnection() exist in the
available queue. Connections that are actively in use exist in the active
queue. This implementation uses FIFO operations for each queue.
| Nested Class Summary | |
|---|---|
protected class |
AbstractConnectionPool.DefaultPooledConnectionProxy
Contains a connection that is participating in this pool. |
| Field Summary | |
|---|---|
protected Queue<PooledConnectionProxy> |
active
List of connections in use. |
protected Queue<PooledConnectionProxy> |
available
List of available connections in the pool. |
protected ReentrantLock |
checkInLock
Lock for check ins. |
protected ReentrantLock |
checkOutLock
Lock for check outs. |
protected ReentrantLock |
poolLock
Lock for the entire pool. |
protected Condition |
poolNotEmpty
Condition for notifying threads that a connection was returned. |
| Fields inherited from class org.ldaptive.pool.AbstractPool |
|---|
logger |
| Constructor Summary | |
|---|---|
AbstractConnectionPool()
|
|
| Method Summary | |
|---|---|
protected void |
activateAndValidateConnection(PooledConnectionProxy pc)
Attempts to activate and validate a connection. |
int |
activeCount()
Returns the number of connections in use. |
int |
availableCount()
Returns the number of connections available for use. |
void |
close()
Empty this pool, freeing any resources. |
protected PooledConnectionProxy |
createActiveConnection()
Create a new connection and place it in the active pool. |
protected PooledConnectionProxy |
createActiveConnection(boolean throwOnFailure)
Create a new connection and place it in the active pool. |
protected PooledConnectionProxy |
createAvailableConnection()
Create a new connection and place it in the available pool. |
protected PooledConnectionProxy |
createAvailableConnection(boolean throwOnFailure)
Create a new connection and place it in the available pool. |
protected PooledConnectionProxy |
createConnection()
Create a new connection. |
protected PooledConnectionProxy |
createConnection(boolean throwOnFailure)
Create a new connection. |
protected Connection |
createConnectionProxy(PooledConnectionProxy pc)
Creates a connection proxy using the supplied pool connection. |
protected void |
finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
abstract Connection |
getConnection()
Returns a connection from the pool. |
DefaultConnectionFactory |
getConnectionFactory()
Returns the connection factory for this pool. |
boolean |
getConnectOnCreate()
Returns whether connections will attempt to connect after creation. |
boolean |
getFailFastInitialize()
Returns whether initialize() should throw if pooling configuration
requirements are not met. |
Set<PooledConnectionStatistics> |
getPooledConnectionStatistics()
Returns the statistics for each connection in the pool. |
QueueType |
getQueueType()
Returns the type of queue used for this connection pool. |
protected void |
grow(int size)
Attempts to grow the pool to the supplied size. |
protected void |
grow(int size,
boolean throwOnFailure)
Attempts to grow the pool to the supplied size. |
void |
initialize()
Initialize this pool for use. |
protected void |
isInitialized()
Used to determine whether initialize() has been invoked for this
pool. |
void |
prune()
Attempts to reduce the size of the pool back to it's configured minimum. |
abstract void |
putConnection(Connection c)
Returns a connection to the pool. |
protected void |
removeActiveConnection(PooledConnectionProxy pc)
Remove a connection from the active pool. |
protected void |
removeAvailableAndActiveConnection(PooledConnectionProxy pc)
Remove a connection from both the available and active pools. |
protected void |
removeAvailableConnection(PooledConnectionProxy pc)
Remove a connection from the available pool. |
protected PooledConnectionProxy |
retrieveConnectionProxy(Connection proxy)
Retrieves the invocation handler from the supplied connection proxy. |
void |
setConnectionFactory(DefaultConnectionFactory cf)
Sets the connection factory for this pool. |
void |
setConnectOnCreate(boolean b)
Sets whether newly created connections will attempt to connect. |
void |
setFailFastInitialize(boolean b)
Sets whether initialize() should throw if pooling configuration
requirements are not met. |
void |
setQueueType(QueueType type)
Sets the type of queue used for this connection pool. |
String |
toString()
|
void |
validate()
Attempts to validate all objects in the pool. |
protected boolean |
validateAndPassivateConnection(PooledConnectionProxy pc)
Attempts to validate and passivate a connection. |
| Methods inherited from class org.ldaptive.pool.AbstractPool |
|---|
activate, getActivator, getName, getPassivator, getPoolConfig, getPruneStrategy, getValidator, passivate, setActivator, setName, setPassivator, setPoolConfig, setPruneStrategy, setValidator, validate |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.ldaptive.pool.ConnectionPool |
|---|
getActivator, getPassivator, getValidator, setActivator, setPassivator, setValidator |
| Field Detail |
|---|
protected final ReentrantLock poolLock
protected final Condition poolNotEmpty
protected final ReentrantLock checkInLock
protected final ReentrantLock checkOutLock
protected Queue<PooledConnectionProxy> available
protected Queue<PooledConnectionProxy> active
| Constructor Detail |
|---|
public AbstractConnectionPool()
| Method Detail |
|---|
public DefaultConnectionFactory getConnectionFactory()
public void setConnectionFactory(DefaultConnectionFactory cf)
cf - connection factorypublic boolean getConnectOnCreate()
public void setConnectOnCreate(boolean b)
b - connect on createpublic QueueType getQueueType()
public void setQueueType(QueueType type)
type - of queuepublic boolean getFailFastInitialize()
initialize() should throw if pooling configuration
requirements are not met.
initialize() should throwpublic void setFailFastInitialize(boolean b)
initialize() should throw if pooling configuration
requirements are not met.
b - whether initialize() should throwprotected void isInitialized()
initialize() has been invoked for this
pool.
IllegalStateException - if this pool has not been initializedpublic void initialize()
AbstractConfig.makeImmutable().
initialize in interface ConnectionPoolIllegalStateException - if this pool has already been initialized,
the pooling configuration is inconsistent or the pool does not contain at
least one connection and it's minimum size is greater than zeroprotected void grow(int size)
size - to grow the pool to
protected void grow(int size,
boolean throwOnFailure)
size - to grow the pool tothrowOnFailure - whether to throw illegal state exception
IllegalStateException - if the pool cannot grow to the supplied
size and createAvailableConnection(boolean) throwspublic void close()
close in interface ConnectionPoolIllegalStateException - if this pool has not been initialized
public abstract Connection getConnection()
throws PoolException
getConnection in interface ConnectionPoolPoolException - if this operation fails
BlockingTimeoutException - if this pool is configured with a block
time and it occurs
PoolInterruptedException - if this pool is configured with a block
time and the current thread is interrupted
IllegalStateException - if this pool has not been initializedpublic abstract void putConnection(Connection c)
c - connection
IllegalStateException - if this pool has not been initializedprotected PooledConnectionProxy createConnection()
connectOnCreate is true, the
connection will be opened.
protected PooledConnectionProxy createConnection(boolean throwOnFailure)
connectOnCreate is true, the
connection will be opened.
throwOnFailure - whether to throw illegal state exception
IllegalStateException - if connectOnCreate is true and the
connection cannot be openedprotected PooledConnectionProxy createAvailableConnection()
protected PooledConnectionProxy createAvailableConnection(boolean throwOnFailure)
throwOnFailure - whether to throw illegal state exception
IllegalStateException - if createConnection(boolean)
throwsprotected PooledConnectionProxy createActiveConnection()
protected PooledConnectionProxy createActiveConnection(boolean throwOnFailure)
throwOnFailure - whether to throw illegal state exception
IllegalStateException - if createConnection(boolean)
throwsprotected void removeAvailableConnection(PooledConnectionProxy pc)
pc - connection that is in the available poolprotected void removeActiveConnection(PooledConnectionProxy pc)
pc - connection that is in the active poolprotected void removeAvailableAndActiveConnection(PooledConnectionProxy pc)
pc - connection that is in both the available and active pools
protected void activateAndValidateConnection(PooledConnectionProxy pc)
throws PoolException
getConnection().
pc - connection
PoolException - if this method fails
ActivationException - if the connection cannot be activated
ValidationException - if the connection cannot be validatedprotected boolean validateAndPassivateConnection(PooledConnectionProxy pc)
putConnection(Connection).
pc - connection
public void prune()
PoolConfig.setMinPoolSize(int).
IllegalStateException - if this pool has not been initializedpublic void validate()
PoolConfig.setValidatePeriodically(boolean).
IllegalStateException - if this pool has not been initializedpublic int availableCount()
availableCount in interface ConnectionPoolpublic int activeCount()
activeCount in interface ConnectionPoolpublic Set<PooledConnectionStatistics> getPooledConnectionStatistics()
getPooledConnectionStatistics in interface ConnectionPoolprotected Connection createConnectionProxy(PooledConnectionProxy pc)
pc - pool connection to create proxy with
protected PooledConnectionProxy retrieveConnectionProxy(Connection proxy)
proxy - connection proxy
protected void finalize()
throws Throwable
finalize in class ObjectThrowable - if an exception is thrown by this methodpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||