|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.d_haven.mpool.AbstractPool
public abstract class AbstractPool
The AbstractPool is the base class for all the pool types. It handles the interaction with the pool listeners to make it easier to focus on the core issues of storing the pooled objects in the final implementations.
Field Summary | |
---|---|
private ObjectFactory |
m_factory
|
private java.util.Collection |
m_listeners
|
Constructor Summary | |
---|---|
protected |
AbstractPool(ObjectFactory factory)
Initialize this instance of an AbstractPool using the supplied ObjectFactory . |
Method Summary | |
---|---|
java.lang.Object |
acquire()
Acquire an instance of the pooled object. |
void |
addPoolListener(PoolListener listener)
Add a pool listener to the pool. |
protected void |
disposeInstance(java.lang.Object pooledObject)
Dispose an instance of a pooled object. |
protected abstract java.lang.Object |
doAcquire()
Perform the actual work of acquiring the object from the pool. |
protected abstract boolean |
doRelease(java.lang.Object pooledObject)
Perform the actual logic to release the pooled object back to the pool. |
protected void |
fireAquiredEvent(java.lang.Object pooledObject)
Fire the PoolListener.objectAquired(Object) event to all
the listeners. |
protected void |
fireCreatedEvent(java.lang.Object pooledObject)
Fire the PoolListener.objectCreated(Object) event to all
the listeners. |
protected void |
fireCreationFailedEvent(java.lang.Exception exception)
Fire the PoolListener.objectCreationFailed(Exception)
event to all the listeners. |
protected void |
fireDisposedEvent(java.lang.Object pooledObject)
Fire the PoolListener.objectDisposed(Object) event to all
the listeners. |
protected void |
fireDisposeFailedEvent(java.lang.Object pooledObject,
java.lang.Exception exception)
Fire the PoolListener.objectDisposalFailed(Object,
Exception) event to all the listeners. |
protected void |
fireReleasedEvent(java.lang.Object pooledObject)
Fire the PoolListener.objectReleased(Object) event to all
the listeners. |
java.util.Collection |
getPoolListeners()
Get the list of pool listeners. |
private java.util.Iterator |
listenerIterator()
|
java.lang.Object |
newInstance()
Create a new instance of the object being pooled. |
void |
release(java.lang.Object pooledObject)
Release the instance of the pooled object. |
void |
removePoolListener(PoolListener listener)
Remove a pool listener from the pool. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.util.Collection m_listeners
private final ObjectFactory m_factory
Constructor Detail |
---|
protected AbstractPool(ObjectFactory factory)
ObjectFactory
.
factory
- the ObjectFactory used to create new instances.Method Detail |
---|
public void addPoolListener(PoolListener listener)
addPoolListener
in interface Pool
listener
- the listener to add.public void removePoolListener(PoolListener listener)
removePoolListener
in interface Pool
listener
- the listener to removepublic java.util.Collection getPoolListeners()
public java.lang.Object acquire() throws java.lang.Exception
acquire
in interface Pool
java.lang.Exception
- if the Pool is not able to return an object.protected void fireCreationFailedEvent(java.lang.Exception exception)
PoolListener.objectCreationFailed(Exception)
event to all the listeners.
exception
- the exception causing the failureprivate java.util.Iterator listenerIterator()
protected void fireAquiredEvent(java.lang.Object pooledObject)
PoolListener.objectAquired(Object)
event to all
the listeners.
pooledObject
- the object acquired from the poolprotected void fireReleasedEvent(java.lang.Object pooledObject)
PoolListener.objectReleased(Object)
event to all
the listeners.
pooledObject
- the object released to the poolprotected void fireDisposeFailedEvent(java.lang.Object pooledObject, java.lang.Exception exception)
PoolListener.objectDisposalFailed(Object,
Exception)
event to all the listeners.
pooledObject
- the object disposedexception
- the exception thrown during disposalprotected void fireCreatedEvent(java.lang.Object pooledObject)
PoolListener.objectCreated(Object)
event to all
the listeners.
pooledObject
- the object createdprotected abstract java.lang.Object doAcquire() throws java.lang.Exception
java.lang.Exception
- if there was a problem acquiring the objectpublic void release(java.lang.Object pooledObject)
release
in interface Pool
pooledObject
- The pooled object to release to the pool.protected void disposeInstance(java.lang.Object pooledObject)
ManagablePool.shrink(int)
call.
pooledObject
- the object to dispose ofprotected void fireDisposedEvent(java.lang.Object pooledObject)
PoolListener.objectDisposed(Object)
event to all
the listeners.
pooledObject
- the object disposedprotected abstract boolean doRelease(java.lang.Object pooledObject)
pooledObject
- the object to release
true
if we also need to dispose of the
objectpublic java.lang.Object newInstance() throws java.lang.Exception
java.lang.Exception
- if the instance cannot be created
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |