Package edu.vt.middleware.ldap.pool
Class AbstractLdapPool<T extends BaseLdap>
- java.lang.Object
-
- edu.vt.middleware.ldap.pool.AbstractLdapPool<T>
-
- Type Parameters:
T
- type of ldap object
- All Implemented Interfaces:
LdapPool<T>
- Direct Known Subclasses:
BlockingLdapPool
,SharedLdapPool
public 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 forLdapPool.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.- Version:
- $Revision: 2241 $ $Date: 2012-02-07 21:08:51 +0100 (Tue, 07 Feb 2012) $
- Author:
- Middleware Services
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractLdapPool.PooledLdap<T extends BaseLdap>
PooledLdap
contains an ldap object that is participating in a pool.
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description AbstractLdapPool(LdapPoolConfig lpc, LdapFactory<T> lf)
Creates a new pool with the supplied pool configuration and ldap factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
poolLock
protected final java.util.concurrent.locks.ReentrantLock poolLock
Lock for the entire pool.
-
poolNotEmpty
protected final java.util.concurrent.locks.Condition poolNotEmpty
Condition for notifying threads that an object was returned.
-
checkInLock
protected final java.util.concurrent.locks.ReentrantLock checkInLock
Lock for check ins.
-
checkOutLock
protected final java.util.concurrent.locks.ReentrantLock checkOutLock
Lock for check outs.
-
logger
protected final org.apache.commons.logging.Log logger
Log for this class.
-
available
protected java.util.Queue<AbstractLdapPool.PooledLdap<T extends BaseLdap>> available
List of available ldap objects in the pool.
-
active
protected java.util.Queue<AbstractLdapPool.PooledLdap<T extends BaseLdap>> active
List of ldap objects in use.
-
poolConfig
protected LdapPoolConfig poolConfig
Ldap pool config.
-
ldapFactory
protected LdapFactory<T extends BaseLdap> ldapFactory
Factory to create ldap objects.
-
-
Constructor Detail
-
AbstractLdapPool
public AbstractLdapPool(LdapPoolConfig lpc, LdapFactory<T> lf)
Creates a new pool with the supplied pool configuration and ldap factory. The pool configuration will be marked as immutable by this pool.- Parameters:
lpc
-LdapPoolConfig
lf
-LdapFactory
-
-
Method Detail
-
getLdapPoolConfig
public LdapPoolConfig getLdapPoolConfig()
Returns the configuration for this pool.- Specified by:
getLdapPoolConfig
in interfaceLdapPool<T extends BaseLdap>
- Returns:
- ldap pool config
-
setPoolTimer
public void setPoolTimer(java.util.Timer t)
Sets the pool to use an existing timer. Pool will use an internal timer if none is provided. Must be called beforeLdapPool.initialize()
.- Specified by:
setPoolTimer
in interfaceLdapPool<T extends BaseLdap>
- Parameters:
t
- timer used to schedule pool tasks
-
initialize
public void initialize()
Initialize this pool for use.- Specified by:
initialize
in interfaceLdapPool<T extends BaseLdap>
-
close
public void close()
Empty this pool, closing all connections, and freeing any resources.
-
createAvailable
protected T createAvailable()
Create a new ldap object and place it in the available pool.- Returns:
- ldap object that was placed in the available pool
-
createActive
protected T createActive()
Create a new ldap object and place it in the active pool.- Returns:
- ldap object that was placed in the active pool
-
createAvailableAndActive
protected T createAvailableAndActive()
Create a new ldap object and place it in both the available and active pools.- Returns:
- ldap object that was placed in the available and active pools
-
removeAvailable
protected void removeAvailable(T t)
Remove an ldap object from the available pool.- Parameters:
t
- ldap object that exists in the available pool
-
removeActive
protected void removeActive(T t)
Remove an ldap object from the active pool.- Parameters:
t
- ldap object that exists in the active pool
-
removeAvailableAndActive
protected void removeAvailableAndActive(T t)
Remove an ldap object from both the available and active pools.- Parameters:
t
- ldap object that exists in the both the available and active pools
-
activateAndValidate
protected void activateAndValidate(T t) throws LdapPoolException
Attempts to activate and validate an ldap object. Performed before an object is returned fromLdapPool.checkOut()
.- Parameters:
t
- ldap object- Throws:
LdapPoolException
- if this method faisLdapActivationException
- if the ldap object cannot be activatedLdapValidateException
- if the ldap object cannot be validated
-
validateAndPassivate
protected boolean validateAndPassivate(T t)
Attempts to validate and passivate an ldap object. Performed when an object is given toLdapPool.checkIn(T)
.- Parameters:
t
- ldap object- Returns:
- whether both validate and passivation succeeded
-
prune
public void prune()
Attempts to reduce the size of the pool back to it's configured minimum.LdapPoolConfig.setMinPoolSize(int)
.
-
validate
public void validate()
Attempts to validate all objects in the pool.LdapPoolConfig.setValidatePeriodically(boolean)
.
-
availableCount
public int availableCount()
Returns the number of ldap objects available for use.- Specified by:
availableCount
in interfaceLdapPool<T extends BaseLdap>
- Returns:
- count
-
activeCount
public int activeCount()
Returns the number of ldap objects in use.- Specified by:
activeCount
in interfaceLdapPool<T extends BaseLdap>
- Returns:
- count
-
finalize
protected void finalize() throws java.lang.Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
- if an exception is thrown by this method
-
-