Protomatter Classes v1.1.6

com.protomatter.pool
Class GrowingObjectPool

java.lang.Object
  |
  +--com.protomatter.pool.SimpleObjectPool
        |
        +--com.protomatter.pool.GrowingObjectPool
All Implemented Interfaces:
ObjectPool
Direct Known Subclasses:
BlockingQueue, JdbcConnectionPool, WorkQueue

public abstract class GrowingObjectPool
extends SimpleObjectPool

An ObjectPool implementation that has an initial size and an optional max size. The pool will grow as needed by blocks until the max size is reached.

See Also:
ObjectPool, SimpleObjectPool

Fields inherited from class com.protomatter.pool.SimpleObjectPool
sync
 
Constructor Summary
GrowingObjectPool()
          Initialize the object pool.
GrowingObjectPool(boolean monitorCheckedOutObjects)
          Initialize the object pool.
 
Method Summary
protected  void checkinPoolObject(ObjectPoolObject o)
          This method needs to be implemented by sub-classes.
 int getCreateWaitTime()
          Get the number of milliseconds to sleep between creates of new objects for the pool.
 int getCurrentPoolSize()
          Get the current size of the pool.
 int getInitialObjectPoolSize()
          Get the initial size of the pool.
 int getMaxObjectPoolSize()
          Get the maximum number of objects this pool will hold.
protected  ObjectPoolObject getNextPoolObject()
          Gets the next object from the pool.
 int getObjectPoolGrowSize()
          Get the number of objects the pool should grow by when it needs to grow.
 int getObjectPoolSize()
          Get the number of objects in the pool that are available.
protected  java.util.List getPool()
          Get the pool.
 void init(java.util.Hashtable ht)
          Initialize the pool.
 void reInitializeObjectPool()
          Calls deleteObjectPoolObject() on all objects currently in the pool, and then re-creates the initial number of them.
 void setMaxObjectPoolSize(int size)
          Change the maximum size of the object pool.
 
Methods inherited from class com.protomatter.pool.SimpleObjectPool
checkin, checkout, createObjectPoolObject, getCheckedOutObjects, getNumWaiters, getObjectsInUse, getSyncObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GrowingObjectPool

public GrowingObjectPool()
Initialize the object pool. Checked out objects will be monitored.

GrowingObjectPool

public GrowingObjectPool(boolean monitorCheckedOutObjects)
Initialize the object pool. Checked out objects will be monitored if monitorCheckedOutObjects is true.
Method Detail

getPool

protected java.util.List getPool()
Get the pool.

getObjectPoolSize

public int getObjectPoolSize()
Get the number of objects in the pool that are available.

getCurrentPoolSize

public int getCurrentPoolSize()
Get the current size of the pool. Returns (objects available + objects in use)

getNextPoolObject

protected ObjectPoolObject getNextPoolObject()
                                      throws java.lang.Exception
Gets the next object from the pool. If the pool is empty, it is grown by not more than poolGrowBlock elements up to maxPoolSize total.
Overrides:
getNextPoolObject in class SimpleObjectPool
Throws:
java.lang.Exception - If there is a problem getting the next object from the pool -- could be caused by the createObjectPoolObject() method throwing an exception.

setMaxObjectPoolSize

public void setMaxObjectPoolSize(int size)
                          throws PoolException
Change the maximum size of the object pool. The pool will be shrunk unless the number of objects in use (checked out of the pool) is larger than the new desired size of the pool or the desired size is smaller than the initial size of this pool.
Throws:
PoolException - If the number of objects in use is greater than the desired size of the pool, or if the desired size is smaller than the initial size for this pool.

init

public void init(java.util.Hashtable ht)
          throws java.lang.Exception
Initialize the pool. Reads the following from the Hashtable:

pool.initialSize (Integer)
The initial pool size (default is 0).
pool.maxSize (Integer)
The max pool size (default is -1). If the max pool size is -1, the pool grows infinitely.
pool.growBlock (Integer)
The grow size (default is 1). When a new object is needed, this many are created.
pool.createWaitTime (Integer)
The time (in ms) to sleep between pool object creates (default is 0). This is useful for database connection pools where it's possible to overload the database by trying to make too many connections too quickly.

Throws:
java.lang.Exception - If there is an exception initializing the pool.

reInitializeObjectPool

public void reInitializeObjectPool()
                            throws java.lang.Exception
Calls deleteObjectPoolObject() on all objects currently in the pool, and then re-creates the initial number of them.
Throws:
java.lang.Exception - If there is an exception re-initializing the pool.

checkinPoolObject

protected void checkinPoolObject(ObjectPoolObject o)
Description copied from class: SimpleObjectPool
This method needs to be implemented by sub-classes. It should add the given ObjectPoolObject to the pool.
Overrides:
checkinPoolObject in class SimpleObjectPool
See Also:
SimpleObjectPool

getInitialObjectPoolSize

public int getInitialObjectPoolSize()
Get the initial size of the pool.

getMaxObjectPoolSize

public int getMaxObjectPoolSize()
Get the maximum number of objects this pool will hold.

getObjectPoolGrowSize

public int getObjectPoolGrowSize()
Get the number of objects the pool should grow by when it needs to grow.

getCreateWaitTime

public int getCreateWaitTime()
Get the number of milliseconds to sleep between creates of new objects for the pool.

Protomatter Classes v1.1.6
Copyright 1998-2001 Nate Sammons

Protomatter Classes v1.1.6 http://protomatter.sourceforge.net/1.1.6