com.primix.tapestry.util.pool
Class Pool

java.lang.Object
  |
  +--com.primix.tapestry.util.pool.Pool
All Implemented Interfaces:
ICleanable, IRenderDescription

public class Pool
extends java.lang.Object
implements ICleanable, IRenderDescription

A Pool is used to pool instances of a useful class. It uses keys, much like a Map, to identify a list of pooled objects. Retrieving an object from the Pool atomically removes it from the pool. It can then be stored again later.

The implementation of Pool is threadsafe.

Pool implements ICleanable, with a goal of only keeping pooled objects that have been needed within a recent time frame. A generational system is used, where each pooled object is assigned a generation count. executeCleanup() culls objects whose generation count is too old (outside of a window).

Version:
$Id: Pool.java,v 1.14 2001/09/11 21:41:12 hship Exp $
Author:
Howard Ship

Constructor Summary
Pool()
          Creates a new Pool using the default map size.
Pool(boolean useSharedJanitor)
           
Pool(int mapSize)
          Creates a new Pool using the specified map size.
Pool(int mapSize, boolean useSharedJanitor)
          Standard constructor.
 
Method Summary
 void clear()
          Removes all previously pooled objects from this Pool.
 void executeCleanup()
          Peforms culling of unneeded pooled objects.
 int getKeyCount()
          Returns the number of keys within the pool.
 int getPooledCount()
          Returns the number of object pooled, the sum of the number of objects in pooled under each key.
 int getWindow()
          Returns the window used to cull pooled objects during a cleanup.
 void renderDescription(IResponseWriter writer)
          Object should render a description of itself to the writer.
 java.lang.Object retrieve(java.lang.Object key)
          Returns a previously pooled object with the given key, or null if no such object exists.
 void setWindow(int value)
          Sets the window, or number of generations that an object may stay in the pool before being culled.
 void store(java.lang.Object key, java.lang.Object object)
          Stores an object in the pool for later retrieval.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pool

public Pool()
Creates a new Pool using the default map size. Creation of the map is deferred.

Pool

public Pool(int mapSize)
Creates a new Pool using the specified map size. The map is created immediately.

Pool

public Pool(boolean useSharedJanitor)
Parameters:
useSharedJanitor - if true, then the Pool is added to the shared janitor.
Since:
1.0.5

Pool

public Pool(int mapSize,
            boolean useSharedJanitor)
Standard constructor.
Parameters:
mapSize - initial size of the map.
useSharedJanitor - if true, then the Pool is added to the shared janitor.
Since:
1.0.5
Method Detail

getWindow

public int getWindow()
Returns the window used to cull pooled objects during a cleanup. The default is 10, which works out to about five minutes with a standard janitor (on a 30 second cycle).
Since:
1.0.5

setWindow

public void setWindow(int value)
Sets the window, or number of generations that an object may stay in the pool before being culled.
Throws:
java.lang.IllegalArgumentException - if value is less than 1.
Since:
1.0.5

retrieve

public java.lang.Object retrieve(java.lang.Object key)
Returns a previously pooled object with the given key, or null if no such object exists. Getting an object from a Pool removes it from the Pool, but it can later be re-added with store(Object,Object).

store

public void store(java.lang.Object key,
                  java.lang.Object object)
Stores an object in the pool for later retrieval. Invokes IPoolable.resetForPool(), if the object implements the IPoolable interface.

clear

public void clear()
Removes all previously pooled objects from this Pool.

getPooledCount

public int getPooledCount()
Returns the number of object pooled, the sum of the number of objects in pooled under each key. This number should be treated as approximate, since there are a few minor windows where, under load, it may not be properly synchronized.
Since:
1.0.2

getKeyCount

public int getKeyCount()
Returns the number of keys within the pool.
Since:
1.0.2

executeCleanup

public void executeCleanup()
Peforms culling of unneeded pooled objects.
Specified by:
executeCleanup in interface ICleanable
Since:
1.0.5

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

renderDescription

public void renderDescription(IResponseWriter writer)
Description copied from interface: IRenderDescription
Object should render a description of itself to the writer.
Specified by:
renderDescription in interface IRenderDescription
Since:
1.0.6