Class AbstractLdapPool<T extends BaseLdap>

  • 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 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: 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.
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • 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

      • 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 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
      • 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 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 class java.lang.Object
        Throws:
        java.lang.Throwable - if an exception is thrown by this method