public abstract class AbstractPool extends java.lang.Object implements Pool
| Modifier and Type | Field and Description |
|---|---|
private ObjectFactory |
m_factory |
private java.util.Collection |
m_listeners |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractPool(ObjectFactory factory)
Initialize this instance of an AbstractPool using the supplied
ObjectFactory. |
| Modifier and Type | Method and Description |
|---|---|
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.
|
private final java.util.Collection m_listeners
private final ObjectFactory m_factory
protected AbstractPool(ObjectFactory factory)
ObjectFactory.factory - the ObjectFactory used to create new instances.public void addPoolListener(PoolListener listener)
addPoolListener in interface Poollistener - the listener to add.public void removePoolListener(PoolListener listener)
removePoolListener in interface Poollistener - the listener to removepublic java.util.Collection getPoolListeners()
public java.lang.Object acquire()
throws java.lang.Exception
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)
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 releasetrue 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