net.spy.pool
Class ObjectPool

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.pool.ObjectPool

public class ObjectPool
extends SpyObject

ObjectPool is the entry point for all object pooling facilities in net.spy.pool.*. ObjectPools have a shared reference to a pool, so there is exactly one set of pools per ClassLoader. This can be very useful in consolidating applications' pools into one.

Pools are referenced by name, so as long as two pools have two different names, they will be used independently.

When creating a pool, you must have a PoolFiller that will populate the pool with objects when it needs them.

The following is an example demonstrating how to instantiate a JDBC pool using JDBCPoolFiller:

 SpyConfig conf=new SpyConfig("pool.conf");
 ObjectPool op=new ObjectPool(conf);
 JDBCPoolFiller pf=new JDBCPoolFiller("db", conf);
 op.createPool("db", pf);
 


Constructor Summary
ObjectPool(SpyConfig conf)
           
 
Method Summary
 void createPool(java.lang.String name, PoolFiller pf)
          Create a new object pool.
 void destroyPool(java.lang.String name)
          Destory a pool.
 PooledObject getObject(java.lang.String name)
          Get an object from a pool.
 boolean hasPool(java.lang.String name)
          Find out if the ObjectPool contains the named pool.
 int numPools()
          Get a count of the number of object pools.
 void prune()
          Prune the object pools.
 java.lang.String toString()
          Dump out the object pools.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectPool

public ObjectPool(SpyConfig conf)
Method Detail

createPool

public void createPool(java.lang.String name,
                       PoolFiller pf)
                throws PoolException
Create a new object pool.

Parameters:
name - The name of the object pool.
pf - The PoolFiller object that will be used to create new objects within the pool.
Throws:
PoolException - when bad things happen

destroyPool

public void destroyPool(java.lang.String name)
                 throws PoolException
Destory a pool.

Parameters:
name - The pool to destroy.
Throws:
PoolException - if there's a problem removing the pool
NoSuchPoolException - if the pool we want to remove doesn't exist

hasPool

public boolean hasPool(java.lang.String name)
Find out if the ObjectPool contains the named pool.

Parameters:
name - the name of the pool we're looking for

getObject

public PooledObject getObject(java.lang.String name)
                       throws PoolException
Get an object from a pool.

Parameters:
name - The pool from which we'll get our object.
Returns:
a PooledObject object.
Throws:
PoolException - if it can't get an object
NoSuchPoolException - if there isn't a pool by that name

numPools

public int numPools()
Get a count of the number of object pools.


toString

public java.lang.String toString()
Dump out the object pools.

Overrides:
toString in class java.lang.Object

prune

public void prune()
           throws PoolException
Prune the object pools. This method requests that each individual pool prune itself, removing unusable or unnecessary PoolAbles.

Throws:
PoolException - if something bad happens


Copyright © 1995-2006 SPY Internetworking. All Rights Reserved.