edu.vt.middleware.ldap.pool
Class AbstractLdapPool<T extends BaseLdap>

java.lang.Object
  extended by 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 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.

Version:
$Revision: 1330 $ $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
Author:
Middleware Services

Nested Class Summary
protected static class AbstractLdapPool.PooledLdap<T extends BaseLdap>
          PooledLdap contains an ldap object that is participating in a pool.
 
Field Summary
protected  Queue<AbstractLdapPool.PooledLdap<T>> active
          List of ldap objects in use.
protected  Queue<AbstractLdapPool.PooledLdap<T>> available
          List of available ldap objects in the pool.
protected  ReentrantLock checkInLock
          Lock for check ins.
protected  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  ReentrantLock poolLock
          Lock for the entire pool.
protected  Condition poolNotEmpty
          Condition for notifying threads that an object was returned.
 
Constructor Summary
AbstractLdapPool(LdapPoolConfig lpc, LdapFactory<T> lf)
          Creates a new pool with the supplied pool configuration and ldap factory.
 
Method Summary
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(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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.vt.middleware.ldap.pool.LdapPool
checkIn, checkOut
 

Field Detail

poolLock

protected final ReentrantLock poolLock
Lock for the entire pool.


poolNotEmpty

protected final Condition poolNotEmpty
Condition for notifying threads that an object was returned.


checkInLock

protected final ReentrantLock checkInLock
Lock for check ins.


checkOutLock

protected final ReentrantLock checkOutLock
Lock for check outs.


logger

protected final org.apache.commons.logging.Log logger
Log for this class.


available

protected Queue<AbstractLdapPool.PooledLdap<T extends BaseLdap>> available
List of available ldap objects in the pool.


active

protected 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 interface LdapPool<T extends BaseLdap>
Returns:
ldap pool config

setPoolTimer

public void setPoolTimer(Timer t)
Sets the pool to use an existing timer. Pool will use an internal timer if none is provided. Must be called before LdapPool.initialize().

Specified by:
setPoolTimer in interface LdapPool<T extends BaseLdap>
Parameters:
t - timer used to schedule pool tasks

initialize

public void initialize()
Initialize this pool for use.

Specified by:
initialize in interface LdapPool<T extends BaseLdap>

close

public void close()
Empty this pool, closing all connections, and freeing any resources.

Specified by:
close in interface LdapPool<T extends BaseLdap>

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 from LdapPool.checkOut().

Parameters:
t - ldap object
Throws:
LdapPoolException - if this method fais
LdapActivationException - if the ldap object cannot be activated
LdapValidateException - 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 to LdapPool.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).

Specified by:
prune in interface LdapPool<T extends BaseLdap>

validate

public void validate()
Attempts to validate all objects in the pool. LdapPoolConfig.setValidatePeriodically(boolean).

Specified by:
validate in interface LdapPool<T extends BaseLdap>

availableCount

public int availableCount()
Returns the number of ldap objects available for use.

Specified by:
availableCount in interface LdapPool<T extends BaseLdap>
Returns:
count

activeCount

public int activeCount()
Returns the number of ldap objects in use.

Specified by:
activeCount in interface LdapPool<T extends BaseLdap>
Returns:
count

finalize

protected void finalize()
                 throws 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 class Object
Throws:
Throwable - if an exception is thrown by this method


Copyright © 2003-2010 Virginia Tech. All Rights Reserved.