org.d_haven.mpool
Class FixedSizePool

java.lang.Object
  extended by org.d_haven.mpool.AbstractPool
      extended by org.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

Field Summary
private  java.util.List m_buffer
           
private  boolean m_disposed
           
private  long m_stepTime
           
private  long m_timeout
           
 
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.
private  java.lang.Object popLast()
           
 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
 

Field Detail

m_disposed

private boolean m_disposed

m_buffer

private final java.util.List m_buffer

m_timeout

private final long m_timeout

m_stepTime

private final long m_stepTime
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

popLast

private java.lang.Object popLast()

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()
Overrides:
toString in class java.lang.Object

getTimeout

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

Returns:
the timeout in milliseconds