Class AbstractPool

  • All Implemented Interfaces:
    Pool
    Direct Known Subclasses:
    NonBlockingPool

    public abstract class AbstractPool
    extends Object
    implements Pool

    Abstract pool provides the basic implementation of an object pool. The implementation uses a linked list to maintain a list of (available) objects. If the pool is empty it simply creates one using the ObjectFactory instance. Subclasses can change this behaviour by overriding getObject(...) and returnObject(....) methods. This class provides basic support for synchronization, event notification, pool shutdown and pool object recycling. It also does some very basic bookkeeping like the number of objects created, number of threads waiting for object.

    Subclasses can make use of these book-keeping data to provide complex pooling mechanism like LRU / MRU / Random. Also, note that AbstractPool does not have a notion of pool limit. It is upto to the derived classes to implement these features.

    • Field Detail

      • _logger

        protected static final Logger _logger
      • waitCount

        protected int waitCount
      • createdCount

        protected int createdCount
      • steadyPoolSize

        protected int steadyPoolSize
      • resizeQuantity

        protected int resizeQuantity
      • maxPoolSize

        protected int maxPoolSize
      • maxWaitTimeInMillis

        protected long maxWaitTimeInMillis
      • idleTimeoutInSeconds

        protected int idleTimeoutInSeconds
      • containerClassLoader

        protected ClassLoader containerClassLoader
      • destroyedCount

        protected int destroyedCount
      • poolSuccess

        protected int poolSuccess
      • poolName

        protected String poolName
      • poolReturned

        protected int poolReturned
      • configData

        protected String configData
      • appName

        protected String appName
      • modName

        protected String modName
      • ejbName

        protected String ejbName
      • beanId

        protected long beanId
    • Constructor Detail

      • AbstractPool

        protected AbstractPool()
      • AbstractPool

        protected AbstractPool​(ObjectFactory factory,
                               long beanId,
                               int steadyPoolSize,
                               int resizeQuantity,
                               int maxPoolsize,
                               long maxWaitTimeInMillis,
                               int idleTimeoutInSeconds,
                               ClassLoader loader)
    • Method Detail

      • initializePool

        protected void initializePool​(ObjectFactory factory,
                                      long beanId,
                                      int steadyPoolSize,
                                      int resizeQuantity,
                                      int maxPoolsize,
                                      long maxWaitTimeInMillis,
                                      int idleTimeoutInSeconds,
                                      ClassLoader loader)
      • setContainerClassLoader

        public void setContainerClassLoader​(ClassLoader loader)
      • getObject

        public Object getObject​(boolean canWait,
                                Object param)
                         throws PoolException
        Get an object. Application can use pool.getObject() to get an object instead of using new XXX().
        Specified by:
        getObject in interface Pool
        Parameters:
        canWait - Must be true if the calling thread is willing to wait for infinite time to get an object, false if the calling thread does not want to wait at all.
        Throws:
        PoolException
      • getObject

        public Object getObject​(Object param)
                         throws PoolException
        Description copied from interface: Pool
        Get an object from the pool within the specified time.
        Specified by:
        getObject in interface Pool
        Returns:
        an Object or null if an object could not be returned in 'waitForMillis' millisecond.
        Throws:
        PoolException
      • returnObject

        public void returnObject​(Object object)
        Return an object back to the pool. An object that is obtained through getObject() must always be returned back to the pool using either returnObject(obj) or through destroyObject(obj).
        Specified by:
        returnObject in interface Pool
      • destroyObject

        public void destroyObject​(Object object)
        Destroys an Object. Note that applications should not ignore the reference to the object that they got from getObject(). An object that is obtained through getObject() must always be returned back to the pool using either returnObject(obj) or through destroyObject(obj). This method tells that the object should be destroyed and cannot be reused.
        Specified by:
        destroyObject in interface Pool
      • preload

        protected void preload​(int count)
        Preload the pool with objects.
        Parameters:
        count - the number of objects to be added.
      • close

        public void close()
        Close the pool
      • remove

        protected void remove​(int count)
      • removeIdleObjects

        protected abstract void removeIdleObjects()
      • getCreatedCount

        public int getCreatedCount()
      • getDestroyedCount

        public int getDestroyedCount()
      • getPoolSuccess

        public int getPoolSuccess()
      • getSize

        public int getSize()
      • getWaitCount

        public int getWaitCount()
      • getSteadyPoolSize

        public int getSteadyPoolSize()
      • getResizeQuantity

        public int getResizeQuantity()
      • getMaxPoolSize

        public int getMaxPoolSize()
      • getMaxWaitTimeInMillis

        public long getMaxWaitTimeInMillis()
      • getIdleTimeoutInSeconds

        public int getIdleTimeoutInSeconds()
      • setConfigData

        public void setConfigData​(String configData)
      • appendStats

        public void appendStats​(StringBuffer sbuf)
      • getJmsMaxMessagesLoad

        public int getJmsMaxMessagesLoad()
      • getNumBeansInPool

        public int getNumBeansInPool()
      • getNumThreadsWaiting

        public int getNumThreadsWaiting()
      • getTotalBeansCreated

        public int getTotalBeansCreated()
      • getTotalBeansDestroyed

        public int getTotalBeansDestroyed()
      • getAllMonitoredAttrbuteValues

        public String getAllMonitoredAttrbuteValues()
      • getAllAttrValues

        public String getAllAttrValues()
      • unregisterProbeProvider

        protected void unregisterProbeProvider()