net.jackofalltrades.util
Class PoolHouse

java.lang.Object
  extended bynet.jackofalltrades.util.PoolHouse

public class PoolHouse
extends java.lang.Object

Provides a means maintaining ObjectPool instances in memory for use by components in a non-web environment. The method provides a means to allow multiple components access to the same ObjectPool without keeping a separate pool, or passing it like a ball.

 // determine if an ObjectPool for java.lang.Integer can be used.
 // if not, then create one and add it to the PoolHouse.
 if (PoolHouse.getObjectPool(Integer.class) == null) {
     PoolHouse.setObjectPool(Integer.class,
 	           new IntegerPool(new PoolableIntegerFactory()));
 }
 

Later on in another class.
 // grab the ObjectPool and borrow and object from it.
 if (PoolHouse.getObjectPool(Integer.class) != null) {
     Integer pooledInteger 
             = PoolHouse.getObjectPool(Integer.class).borrowObject();
 } else {
     throw new IllegalStateException("IntegerPool is not initialized.");
 }
 

NOTE: All operations against the ObjectPool store are synchronzied.

Since:
0.5-alpha
Version:
$Revision: 1.4 $ $Date: 2003/07/05 15:02:50 $
Author:
Bradley M. Handy

Method Summary
static void addObjectPool(java.lang.Class clazz, org.apache.commons.pool.ObjectPool objectPool)
          Adds a new ObjectPool to the current Map.
static org.apache.commons.pool.ObjectPool getObjectPool(java.lang.Class clazz)
          Returns the ObjectPool instance associated with the clazz key.
static void removeObjectPool(java.lang.Class clazz)
          Removes an ObjectPool from the Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addObjectPool

public static void addObjectPool(java.lang.Class clazz,
                                 org.apache.commons.pool.ObjectPool objectPool)
Adds a new ObjectPool to the current Map. If an entry for a Class->ObjectPool relationship exists, then the new ObjectPool overrides the old.

Parameters:
clazz - the Class object representing the type of objects stored in the ObjectPool.
objectPool - an instance of a class implementing the org.apache.commons.pool.ObjectPool interface, which produces instances of the type represented by clazz.

removeObjectPool

public static void removeObjectPool(java.lang.Class clazz)
Removes an ObjectPool from the Map.

Parameters:
clazz - a Class object representing the type of objects stored in the ObjectPool to be removed.

getObjectPool

public static org.apache.commons.pool.ObjectPool getObjectPool(java.lang.Class clazz)
Returns the ObjectPool instance associated with the clazz key.

Parameters:
clazz - the Class object key used to map the ObjectPool returned.
Returns:
the ObjectPool instance mapped to clazz, or null if not such pool is exists.


Copyright © 2002-2003 Jack-of-all-trades Programming Services. All Rights Reserved.