com.sun.ejb.containers.util.pool
Class AbstractPool

java.lang.Object
  extended by com.sun.ejb.containers.util.pool.AbstractPool
All Implemented Interfaces:
Pool, EJBPoolStatsProvider, StatsProvider
Direct Known Subclasses:
BoundedPool, NonBlockingPool

public abstract class AbstractPool
extends Object
implements Pool, EJBPoolStatsProvider

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 Summary
protected static Logger _logger
           
protected  String appName
           
protected  long beanId
           
protected  String configData
           
protected  ClassLoader containerClassLoader
           
protected  int createdCount
           
protected  int destroyedCount
           
protected  String ejbName
           
protected  ObjectFactory factory
           
protected  int idleTimeoutInSeconds
           
protected  ArrayList list
           
protected  int maxPoolSize
           
protected  long maxWaitTimeInMillis
           
protected  String modName
           
protected  String poolName
           
protected  EjbPoolProbeProvider poolProbeNotifier
           
protected  int poolReturned
           
protected  int poolSuccess
           
protected  int resizeQuantity
           
protected  int steadyPoolSize
           
protected  int waitCount
           
 
Constructor Summary
protected AbstractPool()
           
protected AbstractPool(ObjectFactory factory, long beanId, int steadyPoolSize, int resizeQuantity, int maxPoolsize, long maxWaitTimeInMillis, int idleTimeoutInSeconds, ClassLoader loader)
           
 
Method Summary
 void appendStats(StringBuffer sbuf)
           
 void close()
          Close the pool
 void destroyObject(Object object)
          Destroys an Object.
 String getAllAttrValues()
           
 String getAllMonitoredAttrbuteValues()
           
 int getCreatedCount()
           
 int getDestroyedCount()
           
 int getIdleTimeoutInSeconds()
           
 int getJmsMaxMessagesLoad()
           
 int getMaxPoolSize()
           
 long getMaxWaitTimeInMillis()
           
 int getNumBeansInPool()
           
 int getNumThreadsWaiting()
           
 Object getObject(boolean canWait, Object param)
          Get an object.
 Object getObject(long maxWaitTime, Object param)
           
 Object getObject(Object param)
          Get an object from the pool within the specified time.
 int getPoolSuccess()
           
 int getResizeQuantity()
           
 int getSize()
           
 int getSteadyPoolSize()
           
 int getTotalBeansCreated()
           
 int getTotalBeansDestroyed()
           
 int getWaitCount()
           
protected  void initializePool(ObjectFactory factory, long beanId, int steadyPoolSize, int resizeQuantity, int maxPoolsize, long maxWaitTimeInMillis, int idleTimeoutInSeconds, ClassLoader loader)
           
protected  void preload(int count)
          Preload the pool with objects.
protected  void remove(int count)
           
protected abstract  void removeIdleObjects()
           
 void returnObject(Object object)
          Return an object back to the pool.
 void setConfigData(String configData)
           
 void setContainerClassLoader(ClassLoader loader)
           
 void setInfo(String appName, String modName, String ejbName)
           
protected  void unregisterProbeProvider()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_logger

protected static final Logger _logger

list

protected ArrayList list

factory

protected ObjectFactory factory

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

poolProbeNotifier

protected EjbPoolProbeProvider poolProbeNotifier

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)

setInfo

public void setInfo(String appName,
                    String modName,
                    String ejbName)

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(long maxWaitTime,
                        Object param)
                 throws PoolException
Specified by:
getObject in interface Pool
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()
Specified by:
getSteadyPoolSize in interface EJBPoolStatsProvider

getResizeQuantity

public int getResizeQuantity()

getMaxPoolSize

public int getMaxPoolSize()
Specified by:
getMaxPoolSize in interface EJBPoolStatsProvider

getMaxWaitTimeInMillis

public long getMaxWaitTimeInMillis()

getIdleTimeoutInSeconds

public int getIdleTimeoutInSeconds()

setConfigData

public void setConfigData(String configData)

appendStats

public void appendStats(StringBuffer sbuf)
Specified by:
appendStats in interface StatsProvider

getJmsMaxMessagesLoad

public int getJmsMaxMessagesLoad()
Specified by:
getJmsMaxMessagesLoad in interface EJBPoolStatsProvider

getNumBeansInPool

public int getNumBeansInPool()
Specified by:
getNumBeansInPool in interface EJBPoolStatsProvider

getNumThreadsWaiting

public int getNumThreadsWaiting()
Specified by:
getNumThreadsWaiting in interface EJBPoolStatsProvider

getTotalBeansCreated

public int getTotalBeansCreated()
Specified by:
getTotalBeansCreated in interface EJBPoolStatsProvider

getTotalBeansDestroyed

public int getTotalBeansDestroyed()
Specified by:
getTotalBeansDestroyed in interface EJBPoolStatsProvider

getAllMonitoredAttrbuteValues

public String getAllMonitoredAttrbuteValues()

getAllAttrValues

public String getAllAttrValues()

unregisterProbeProvider

protected void unregisterProbeProvider()


Copyright © 2012 GlassFish Community. All Rights Reserved.