|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.avalon.framework.logger.AbstractLogEnabled | +--org.apache.avalon.excalibur.pool.ResourceLimitingPool
General Pool implementation which supports; weak and strong pool size limits, optional blocking gets when poolables are not available, and automatic pool trimming of unused poolables. Whenever get() is called, the pool tests to see whether it is time to trim old poolables from the pool. If any old poolables exist then they are removed at this time. This means that old poolables will not be removed if get() is never called. Applications can optionally call trim() to force old objects to be trimmed. See the trim() method for details of how trimming works.
Field Summary | |
protected java.lang.Object |
m_semaphore
Object used to synchronize access to the get and put methods |
Constructor Summary | |
ResourceLimitingPool(ObjectFactory factory,
int max,
boolean maxStrict,
boolean blocking,
long blockTimeout,
long trimInterval)
Creates a new ResourceLimitingPool |
Method Summary | |
void |
dispose()
The dispose operation is called at the end of a components lifecycle. |
Poolable |
get()
Gets a Poolable from the pool. |
int |
getReadySize()
Returns the number of available Poolables waiting in the pool. |
int |
getSize()
Returns the total number of Poolables created by the pool. |
protected Poolable |
newPoolable()
Create a new poolable instance by by calling the newInstance method on the pool's ObjectFactory. |
protected void |
permanentlyRemovePoolable(Poolable poolable)
Permanently removes a poolable from the pool's active list and destroys it so that it will not ever be reused. |
void |
put(Poolable poolable)
Returns a poolable to the pool and notifies any thread blocking. |
protected void |
removePoolable(Poolable poolable)
Called when an object is being removed permanently from the pool. |
int |
trim()
Forces the pool to trim, remove, old Poolables from the pool. |
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 |
protected final java.lang.Object m_semaphore
Constructor Detail |
public ResourceLimitingPool(ObjectFactory factory, int max, boolean maxStrict, boolean blocking, long blockTimeout, long trimInterval)
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 in 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.Method Detail |
public Poolable get() throws java.lang.Exception
get
in interface Pool
java.lang.Exception
- An exception may be thrown as described above or if there is an exception
thrown by the ObjectFactory's newInstance() method.public void put(Poolable poolable)
put
in interface Pool
poolable
- Poolable to return to the pool.public void dispose()
dispose
in interface org.apache.avalon.framework.activity.Disposable
protected void permanentlyRemovePoolable(Poolable poolable)
public int getSize()
public int getReadySize()
protected Poolable newPoolable() throws java.lang.Exception
protected void removePoolable(Poolable poolable)
poolable
- Poolable to be completely removed from the pool.public int trim()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |