org.d_haven.mpool
Class VariableSizePool

java.lang.Object
  extended byorg.d_haven.mpool.AbstractPool
      extended byorg.d_haven.mpool.VariableSizePool
All Implemented Interfaces:
ManagablePool, Pool

public final class VariableSizePool
extends AbstractPool
implements ManagablePool

This is an Pool that caches Poolable objects for reuse. Please note that this pool offers no resource limiting whatsoever.

Version:
CVS $Revision: 1.9 $ $Date: 2004/06/21 17:03:46 $
Author:
Berin Loritsch

Constructor Summary
VariableSizePool(ObjectFactory factory, int size)
          Create a VariableSizePool with the supplied factory and initial size.
 
Method Summary
 void dispose()
          Dispose of this pool so that it is empty an no longer used.
protected  java.lang.Object doAcquire()
          Perform the actual work of acquiring the object from the pool.
protected  boolean doRelease(java.lang.Object pooledObject)
          Perform the actual logic to release the pooled object back to the pool.
 void grow(int byNum)
          Grow by the specified amount.
 void shrink(int byNum)
          Shrink the pool by the specified amount.
 int size()
          Determine the pool's current size.
 java.lang.String toString()
           
 
Methods inherited from class org.d_haven.mpool.AbstractPool
acquire, addPoolListener, disposeInstance, fireAquiredEvent, fireCreatedEvent, fireCreationFailedEvent, fireDisposedEvent, fireDisposeFailedEvent, fireReleasedEvent, getPoolListeners, newInstance, release, removePoolListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.d_haven.mpool.Pool
acquire, addPoolListener, release, removePoolListener
 

Constructor Detail

VariableSizePool

public VariableSizePool(ObjectFactory factory,
                        int size)
                 throws java.lang.Exception
Create a VariableSizePool with the supplied factory and initial size.

Parameters:
factory - the factory to use to create objects
size - the initial number of elements to create
Throws:
java.lang.Exception - if there is a problem creating the pooled objects
Method Detail

doAcquire

protected java.lang.Object doAcquire()
                              throws java.lang.Exception
Description copied from class: AbstractPool
Perform the actual work of acquiring the object from the pool.

Specified by:
doAcquire in class AbstractPool
Returns:
the acquired object or null if there are none left
Throws:
java.lang.Exception - if there was a problem acquiring the object

doRelease

protected boolean doRelease(java.lang.Object pooledObject)
Description copied from class: AbstractPool
Perform the actual logic to release the pooled object back to the pool.

Specified by:
doRelease in class AbstractPool
Parameters:
pooledObject - the object to release
Returns:
true if we also need to dispose of the object

dispose

public void dispose()
Dispose of this pool so that it is empty an no longer used.


shrink

public void shrink(int byNum)
Description copied from interface: ManagablePool
Shrink the pool by the specified amount. The pool should trust the Controller, but be smart enough not to achieve a negative pool size. In other words, you should clip the shrink amount so that the pool does not go below 0.

Specified by:
shrink in interface ManagablePool
Parameters:
byNum - an integer amount to decrease the pool size by.

grow

public void grow(int byNum)
Description copied from interface: ManagablePool
Grow by the specified amount. The pool should trust the Controller for the Grow size.

Specified by:
grow in interface ManagablePool
Parameters:
byNum - an integer amount to increase the pool size by.

size

public int size()
Description copied from interface: ManagablePool
Determine the pool's current size. The size is defined as the number of Poolable objects in reserve.

Specified by:
size in interface ManagablePool
Returns:
size of pool's reserve.

toString

public java.lang.String toString()


Copyright © 2004-2005 D-Haven.org. All Rights Reserved.