org.d_haven.mpool
Class FixedSizePool

java.lang.Object
  extended byorg.d_haven.mpool.AbstractPool
      extended byorg.d_haven.mpool.FixedSizePool
All Implemented Interfaces:
Pool

public final class FixedSizePool
extends AbstractPool

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

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

Constructor Summary
FixedSizePool(ObjectFactory factory, int size)
          Create a fixed size pool using the object factory and size supplied.
FixedSizePool(ObjectFactory factory, int size, long timeout)
          Create a fixed size pool using the object factory, size, and timeout supplied.
 
Method Summary
 void dispose()
          Dispose this pool and remove all elements.
protected  java.lang.Object doAcquire()
          Perform the actual work of acquiring the object from the pool.
protected  boolean doRelease(java.lang.Object object)
          Perform the actual logic to release the pooled object back to the pool.
 long getTimeout()
          Get the timeout in milliseconds for this pool.
 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
 

Constructor Detail

FixedSizePool

public FixedSizePool(ObjectFactory factory,
                     int size)
              throws java.lang.Exception
Create a fixed size pool using the object factory and size supplied. The pool will use the defuault timeout of -1 (don't block at all) so it will fail early.

Parameters:
factory - the factory to use for the pool
size - the number of items in the pool (hard limit)
Throws:
java.lang.Exception - if there is a problem creating any of the items in the pool

FixedSizePool

public FixedSizePool(ObjectFactory factory,
                     int size,
                     long timeout)
              throws java.lang.Exception
Create a fixed size pool using the object factory, size, and timeout supplied. A timeout of -1 will not block at all. A timeout of 0 will block indefinitely. A timeout of 1 or more will block for that number of milliseconds.

Parameters:
factory - the factory to use for the pool
size - the number of items in the pool (hard limit)
timeout - the timeout in milliseconds to use.
Throws:
java.lang.Exception - if there is a problem creating any of the items in the pool
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 object)
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:
object - the object to release
Returns:
true if we also need to dispose of the object

dispose

public void dispose()
Dispose this pool and remove all elements.


toString

public java.lang.String toString()

getTimeout

public long getTimeout()
Get the timeout in milliseconds for this pool.

Returns:
the timeout in milliseconds


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