org.osesb.objectpools
Class KeyedObjectPool

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

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

Ancestor of heterogeneous object pools, which are pools that contain objects of different types.

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

Concrete implementations of KeyedObjectPool 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  int getObjectCount
          The number of times getObject was called on this ObjectPool.
protected  long heartbeatInterval
          The Heartbeat interval -- see run().
protected  KeyedObjectPoolConfiguration keyedObjectPoolConfiguration
          The pool configuration as a whole including the ObjectPoolConfiguration and the pooled object configuration(s).
protected  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, which is part of keyedObjectPoolConfiguration, but is extracted for convenience.
protected  org.apache.commons.pool.impl.GenericKeyedObjectPool poolImplementation
          The pool implementation.
protected  java.lang.String thisClassName
          The full name of this class.
 
Constructor Summary
KeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool poolImplementation, KeyedObjectPoolConfiguration keyedObjectPoolConfiguration)
          Creates a new instance of KeyedObjectPool.
 
Method Summary
 void closePool()
          Close down the pool.
 int getGetObjectCount()
          Return getObjectCount, the number of times getObject() was called on this ObjectPool.
 KeyedObjectPoolConfiguration getKeyedObjectPoolConfiguration()
          Return the pool configuration as a whole including the ObjectPoolConfiguration* and the pooled object configuration(s).
 int getMakeObjectCount()
          Return makeObjectCount, the number of times MakeObject() was called by the factory that created this ObjectPool.
 java.lang.Object getObject(java.lang.Object poolKey)
          Borrow an object from the pool by poolKey.
 java.lang.Object getObject(java.lang.String poolKey)
          Borrow an object from the pool by poolKey.
 ObjectPoolConfiguration getPoolConfiguration()
          Return the configuration for the pool.
 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 poolKey, java.lang.Object object)
          Return an object to the pool.
 void returnObject(java.lang.String poolKey, 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.


keyedObjectPoolConfiguration

protected KeyedObjectPoolConfiguration keyedObjectPoolConfiguration
The pool configuration as a whole including the ObjectPoolConfiguration and the pooled object configuration(s).


poolConfiguration

protected ObjectPoolConfiguration poolConfiguration
The configuration for the object pool, which is part of keyedObjectPoolConfiguration, but is extracted for convenience. These are the Apache Pool properties.


poolImplementation

protected org.apache.commons.pool.impl.GenericKeyedObjectPool 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 int makeObjectCount
The number of times makeObject was called by the factory that created this object.


getObjectCount

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

Constructor Detail

KeyedObjectPool

public KeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool poolImplementation,
                       KeyedObjectPoolConfiguration keyedObjectPoolConfiguration)
                throws java.lang.Exception
Creates a new instance of KeyedObjectPool.

Parameters:
poolImplementation - A GenericKeyedObjectPool object.
keyedObjectPoolConfiguration - The configuration for the pool and the pooled objects.
Throws:
java.lang.Exception - if incorrect parameters are passed.
Method Detail

getObject

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

Parameters:
poolKey - The key for one of the object types in the pool as a String.
Returns:
an Object from the pool.
Throws:
java.lang.Exception - if there was an error getting an object from the pool.

getObject

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

Parameters:
poolKey - The key for one of the object types in the pool.
Returns:
an Object from the pool.
Throws:
java.lang.Exception - if there was an error getting an object from the pool.

returnObject

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

Parameters:
poolKey - The key for one of the object types in the pool as a String.
object - The object to return to the pool.
Throws:
java.lang.Exception - if there was an error returning an object to the pool.

returnObject

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

Parameters:
poolKey - The key for one of the object types in the pool.
object - The object to return to the pool.
Throws:
java.lang.Exception - if there was an error returning an 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 KeyedObjectPool.


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. These are the Apache Pool properties.


getKeyedObjectPoolConfiguration

public KeyedObjectPoolConfiguration getKeyedObjectPoolConfiguration()
Return the pool configuration as a whole including the ObjectPoolConfiguration* and the pooled object configuration(s).


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.