edu.vt.middleware.ldap.pool
T
- type of ldap objectpublic abstract class AbstractLdapPool<T extends BaseLdap> extends java.lang.Object implements LdapPool<T>
AbstractLdapPool
contains the basic implementation for pooling
ldap objects. The main design objective for the supplied pooling
implementations is to provide a pool that does not block on object 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 objects and
one for active objects. Objects that are available for LdapPool.checkOut()
exist in the available queue. Objects that are actively in use exist in the
active queue. Note that depending on the implementation an object can exist
in both queues at the same time.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractLdapPool.PooledLdap<T extends BaseLdap>
PooledLdap contains an ldap object that is participating in a
pool. |
Modifier and Type | Field and Description |
---|---|
protected java.util.Queue<AbstractLdapPool.PooledLdap<T>> |
active
List of ldap objects in use.
|
protected java.util.Queue<AbstractLdapPool.PooledLdap<T>> |
available
List of available ldap objects in the pool.
|
protected java.util.concurrent.locks.ReentrantLock |
checkInLock
Lock for check ins.
|
protected java.util.concurrent.locks.ReentrantLock |
checkOutLock
Lock for check outs.
|
protected LdapFactory<T> |
ldapFactory
Factory to create ldap objects.
|
protected org.apache.commons.logging.Log |
logger
Log for this class.
|
protected LdapPoolConfig |
poolConfig
Ldap pool config.
|
protected java.util.concurrent.locks.ReentrantLock |
poolLock
Lock for the entire pool.
|
protected java.util.concurrent.locks.Condition |
poolNotEmpty
Condition for notifying threads that an object was returned.
|
Constructor and Description |
---|
AbstractLdapPool(LdapPoolConfig lpc,
LdapFactory<T> lf)
Creates a new pool with the supplied pool configuration and ldap factory.
|
Modifier and Type | Method and Description |
---|---|
protected void |
activateAndValidate(T t)
Attempts to activate and validate an ldap object.
|
int |
activeCount()
Returns the number of ldap objects in use.
|
int |
availableCount()
Returns the number of ldap objects available for use.
|
void |
close()
Empty this pool, closing all connections, and freeing any resources.
|
protected T |
createActive()
Create a new ldap object and place it in the active pool.
|
protected T |
createAvailable()
Create a new ldap object and place it in the available pool.
|
protected T |
createAvailableAndActive()
Create a new ldap object and place it in both the available and active
pools.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
LdapPoolConfig |
getLdapPoolConfig()
Returns the configuration for this pool.
|
void |
initialize()
Initialize this pool for use.
|
void |
prune()
Attempts to reduce the size of the pool back to it's configured minimum.
|
protected void |
removeActive(T t)
Remove an ldap object from the active pool.
|
protected void |
removeAvailable(T t)
Remove an ldap object from the available pool.
|
protected void |
removeAvailableAndActive(T t)
Remove an ldap object from both the available and active pools.
|
void |
setPoolTimer(java.util.Timer t)
Sets the pool to use an existing timer.
|
void |
validate()
Attempts to validate all objects in the pool.
|
protected boolean |
validateAndPassivate(T t)
Attempts to validate and passivate an ldap object.
|
protected final java.util.concurrent.locks.ReentrantLock poolLock
protected final java.util.concurrent.locks.Condition poolNotEmpty
protected final java.util.concurrent.locks.ReentrantLock checkInLock
protected final java.util.concurrent.locks.ReentrantLock checkOutLock
protected final org.apache.commons.logging.Log logger
protected java.util.Queue<AbstractLdapPool.PooledLdap<T extends BaseLdap>> available
protected java.util.Queue<AbstractLdapPool.PooledLdap<T extends BaseLdap>> active
protected LdapPoolConfig poolConfig
protected LdapFactory<T extends BaseLdap> ldapFactory
public AbstractLdapPool(LdapPoolConfig lpc, LdapFactory<T> lf)
lpc
- LdapPoolConfig
lf
- LdapFactory
public LdapPoolConfig getLdapPoolConfig()
getLdapPoolConfig
in interface LdapPool<T extends BaseLdap>
public void setPoolTimer(java.util.Timer t)
LdapPool.initialize()
.setPoolTimer
in interface LdapPool<T extends BaseLdap>
t
- timer used to schedule pool taskspublic void initialize()
initialize
in interface LdapPool<T extends BaseLdap>
public void close()
protected T createAvailable()
protected T createActive()
protected T createAvailableAndActive()
protected void removeAvailable(T t)
t
- ldap object that exists in the available poolprotected void removeActive(T t)
t
- ldap object that exists in the active poolprotected void removeAvailableAndActive(T t)
t
- ldap object that exists in the both the available and active
poolsprotected void activateAndValidate(T t) throws LdapPoolException
LdapPool.checkOut()
.t
- ldap objectLdapPoolException
- if this method faisLdapActivationException
- if the ldap object cannot be activatedLdapValidateException
- if the ldap object cannot be validatedprotected boolean validateAndPassivate(T t)
LdapPool.checkIn(T)
.t
- ldap objectpublic void prune()
LdapPoolConfig.setMinPoolSize(int)
.public void validate()
LdapPoolConfig.setValidatePeriodically(boolean)
.public int availableCount()
availableCount
in interface LdapPool<T extends BaseLdap>
public int activeCount()
activeCount
in interface LdapPool<T extends BaseLdap>
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- if an exception is thrown by this methodCopyright © 2014. All Rights Reserved.