org.apache.avalon.excalibur.pool
Class TraceableResourceLimitingPool

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.avalon.excalibur.pool.InstrumentedResourceLimitingPool
          extended by org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool
All Implemented Interfaces:
org.apache.avalon.excalibur.pool.Pool, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.thread.ThreadSafe, org.apache.excalibur.instrument.Instrumentable
Direct Known Subclasses:
ValidatedResourceLimitingPool

public class TraceableResourceLimitingPool
extends InstrumentedResourceLimitingPool

A ResourceLimitingPool which can be configured so that it will trace the where get is being called fron. The pool can then be queried for its status.

Since:
4.1
Version:
CVS $Revision: 1.6 $ $Date: 2004/03/31 08:07:28 $
Author:
Avalon Development Team

Nested Class Summary
private static class TraceableResourceLimitingPool.PoolElement
           
static class TraceableResourceLimitingPool.State
           
static class TraceableResourceLimitingPool.TraceException
           
 
Field Summary
private  java.util.Map m_elementMap
          Map of elements describing each poolable.
private  boolean m_tracing
          True if tracing is enabled for the pool.
 
Fields inherited from class org.apache.avalon.excalibur.pool.InstrumentedResourceLimitingPool
DEFAULT_INSTRUMENTABLE_NAME, INSTRUMENT_BLOCKS_NAME, INSTRUMENT_CREATES_NAME, INSTRUMENT_DECOMMISSIONS_NAME, INSTRUMENT_GETS_NAME, INSTRUMENT_PUTS_NAME, INSTRUMENT_READY_SIZE_NAME, INSTRUMENT_SIZE_NAME, m_semaphore
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
TraceableResourceLimitingPool(org.apache.avalon.excalibur.pool.ObjectFactory factory, int max, boolean maxStrict, boolean blocking, long blockTimeout, long trimInterval, boolean trace)
          Creates a new TraceableResourceLimitingPool
 
Method Summary
 org.apache.avalon.excalibur.pool.Poolable get()
          Gets a Poolable from the pool.
 TraceableResourceLimitingPool.State getState()
          Returns a snapshot of the current state of the pool.
 void put(org.apache.avalon.excalibur.pool.Poolable poolable)
          Returns a poolable to the pool and notifies any thread blocking.
protected  void removePoolable(org.apache.avalon.excalibur.pool.Poolable poolable)
          Called when an object is being removed permanently from the pool.
 
Methods inherited from class org.apache.avalon.excalibur.pool.InstrumentedResourceLimitingPool
dispose, getChildInstrumentables, getInstrumentableName, getInstruments, getReadySize, getSize, newPoolable, permanentlyRemovePoolable, setInstrumentableName, trim
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled
enableLogging
 

Field Detail

m_tracing

private boolean m_tracing
True if tracing is enabled for the pool.


m_elementMap

private java.util.Map m_elementMap
Map of elements describing each poolable.

Constructor Detail

TraceableResourceLimitingPool

public TraceableResourceLimitingPool(org.apache.avalon.excalibur.pool.ObjectFactory factory,
                                     int max,
                                     boolean maxStrict,
                                     boolean blocking,
                                     long blockTimeout,
                                     long trimInterval,
                                     boolean trace)
Creates a new TraceableResourceLimitingPool

Parameters:
factory - The ObjectFactory which will be used to create new Poolables as needed by the pool.
max - Maximum number of Poolables which can be stored in the pool, 0 implies no limit.
maxStrict - true if the pool should never allow more than max Poolable to be created. Will cause an exception to be thrown if more than max Poolables are requested and blocking is false.
blocking - true if the pool should cause a thread calling get() to block when Poolables are not currently available on the pool.
blockTimeout - The maximum amount of time, in milliseconds, that a call to get() will block before an exception is thrown. A value of 0 implies an indefinate wait.
trimInterval - The minimum interval with which old unused poolables will be removed from the pool. A value of 0 will cause the pool to never trim poolables.
trace - True if tracing of gets is enabled for the pool.
Method Detail

get

public org.apache.avalon.excalibur.pool.Poolable get()
                                              throws java.lang.Exception
Gets a Poolable from the pool. If there is room in the pool, a new Poolable will be created. Depending on the parameters to the constructor, the method may block or throw an exception if a Poolable is not available on the pool.

Specified by:
get in interface org.apache.avalon.excalibur.pool.Pool
Overrides:
get in class InstrumentedResourceLimitingPool
Returns:
Always returns a Poolable. Contract requires that put must always be called with the Poolable returned.
Throws:
java.lang.Exception - An exception may be thrown as described above or if there is an exception thrown by the ObjectFactory's newInstance() method.

put

public void put(org.apache.avalon.excalibur.pool.Poolable poolable)
Returns a poolable to the pool and notifies any thread blocking.

Specified by:
put in interface org.apache.avalon.excalibur.pool.Pool
Overrides:
put in class InstrumentedResourceLimitingPool
Parameters:
poolable - Poolable to return to the pool.

removePoolable

protected void removePoolable(org.apache.avalon.excalibur.pool.Poolable poolable)
Called when an object is being removed permanently from the pool. This is the method to override when you need to enforce destructional policies.

This method is only called by threads that have m_semaphore locked.

Overrides:
removePoolable in class InstrumentedResourceLimitingPool
Parameters:
poolable - Poolable to be completely removed from the pool.

getState

public TraceableResourceLimitingPool.State getState()
Returns a snapshot of the current state of the pool.

Returns:
A snapshot of the current pool state.