org.osesb.objectpools
Class ObjectPool

java.lang.Object
  extended by org.osesb.objectpools.ObjectPool
All Implemented Interfaces:
java.lang.Runnable

public class ObjectPool
extends java.lang.Object
implements java.lang.Runnable

Ancestor of homogeneous object pools, which are pools that contain objects of the same type.

The framework uses the Apache Pool Package (org.apache.commons.pool) to:

Concrete implementations of ObjectPool are returned by factories, such as:

Since:
Version .9

Field Summary
protected  java.util.Date dateTimePoolStarted
          The date-time when this pool was started.
protected static int getObjectCount
          The number of times getObject was called on this ObjectPool.
protected  long heartbeatInterval
          The Heartbeat interval -- see run().
protected static int makeObjectCount
          The number of times makeObject was called by the factory that created this object.
protected  ObjectPoolConfiguration poolConfiguration
          The configuration for the object pool.
protected  XMLConfiguration pooledObjectConfiguration
          The configuration for the objects in the pool.
protected  org.apache.commons.pool.impl.GenericObjectPool poolImplementation
          The pool implementation.
protected  java.lang.String thisClassName
          The full name of this class.
 
Constructor Summary
ObjectPool(org.apache.commons.pool.impl.GenericObjectPool poolImplementation, ObjectPoolConfiguration poolConfiguration, XMLConfiguration pooledObjectConfiguration)
          Creates a new instance of ObjectPool.
 
Method Summary
 void closePool()
          Close down the pool.
 int getGetObjectCount()
          Return getObjectCount, the number of times getObject() was called on this ObjectPool.
 int getMakeObjectCount()
          Return makeObjectCount, the number of times MakeObject() was called by the factory that created this ObjectPool.
 java.lang.Object getObject()
          Borrow an object from the pool.
 ObjectPoolConfiguration getPoolConfiguration()
          Return the configuration for the pool.
 XMLConfiguration getPooledObjectConfiguration()
          Return the configuration for the pooled object.
 void incrementMakeObjectCount()
          Increment the counter for the number of times MakeObject() was called.
 boolean isPoolClosed()
          Test if the pool has been closed.
protected  void objectPoolStartupMessage()
          Startup message for ObjectPools.
 void returnObject(java.lang.Object object)
          Return an object to the pool.
 void run()
          Runnable interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thisClassName

protected java.lang.String thisClassName
The full name of this class.


poolConfiguration

protected ObjectPoolConfiguration poolConfiguration
The configuration for the object pool.


pooledObjectConfiguration

protected XMLConfiguration pooledObjectConfiguration
The configuration for the objects in the pool.


poolImplementation

protected org.apache.commons.pool.impl.GenericObjectPool poolImplementation
The pool implementation.


heartbeatInterval

protected long heartbeatInterval
The Heartbeat interval -- see run().


dateTimePoolStarted

protected java.util.Date dateTimePoolStarted
The date-time when this pool was started.


makeObjectCount

protected static int makeObjectCount
The number of times makeObject was called by the factory that created this object.


getObjectCount

protected static int getObjectCount
The number of times getObject was called on this ObjectPool.

Constructor Detail

ObjectPool

public ObjectPool(org.apache.commons.pool.impl.GenericObjectPool poolImplementation,
                  ObjectPoolConfiguration poolConfiguration,
                  XMLConfiguration pooledObjectConfiguration)
           throws java.lang.Exception
Creates a new instance of ObjectPool.

Parameters:
poolImplementation - A GenericObjectPool object.
poolConfiguration - The configuration for the pool.
pooledObjectConfiguration - The optional configuration for the pooled object.
Throws:
java.lang.Exception - if a null pool implementation is passed.
Method Detail

getObject

public java.lang.Object getObject()
                           throws java.lang.Exception
Borrow an object from the pool.

Returns:
an Object from the pool.
Throws:
java.lang.Exception - if there were problems getting an object from the pool.

returnObject

public void returnObject(java.lang.Object object)
                  throws java.lang.Exception
Return an object to the pool.

Parameters:
object - The object to return to the pool.
Throws:
java.lang.Exception - if there were problems returning the object to the pool.

closePool

public void closePool()
Close down the pool.


isPoolClosed

public boolean isPoolClosed()
Test if the pool has been closed.

Returns:
true if poolImplementation is null, false otherwise.

incrementMakeObjectCount

public void incrementMakeObjectCount()
Increment the counter for the number of times MakeObject() was called. This method is called by the factory that created this ObjectPool.


getGetObjectCount

public int getGetObjectCount()
Return getObjectCount, the number of times getObject() was called on this ObjectPool.

Returns:
the number of times MakeObject() was called by the factory that created this ObjectPool

getMakeObjectCount

public int getMakeObjectCount()
Return makeObjectCount, the number of times MakeObject() was called by the factory that created this ObjectPool.


getPoolConfiguration

public ObjectPoolConfiguration getPoolConfiguration()
Return the configuration for the pool.


getPooledObjectConfiguration

public XMLConfiguration getPooledObjectConfiguration()
Return the configuration for the pooled object.


run

public void run()
Runnable interface.

Logs heartbeat message, if heartbeats are enabled.

Specified by:
run in interface java.lang.Runnable

objectPoolStartupMessage

protected void objectPoolStartupMessage()
Startup message for ObjectPools.