public abstract class AbstractPoolingTargetSource extends AbstractPrototypeBasedTargetSource implements PoolingConfig, org.springframework.beans.factory.DisposableBean
TargetSource
implementations which maintain a pool of target instances, acquiring and
releasing a target object from the pool for each method invocation.
This abstract base class is independent of concrete pooling technology;
see the subclass CommonsPool2TargetSource for a concrete example.
Subclasses must implement the getTarget() and
releaseTarget(java.lang.Object) methods based on their chosen object pool.
The AbstractPrototypeBasedTargetSource.newPrototypeInstance() method inherited from
AbstractPrototypeBasedTargetSource can be used to create objects
in order to put them into the pool.
Subclasses must also implement some of the monitoring methods from the
PoolingConfig interface. The getPoolingConfigMixin() method
makes these stats available on proxied objects through an IntroductionAdvisor.
This class implements the DisposableBean
interface in order to force subclasses to implement a DisposableBean.destroy()
method, closing down their object pool.
getTarget(),
releaseTarget(java.lang.Object),
DisposableBean.destroy(),
Serialized Formlogger| Constructor and Description |
|---|
AbstractPoolingTargetSource() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
createPool()
Create the pool.
|
int |
getMaxSize()
Return the maximum size of the pool.
|
DefaultIntroductionAdvisor |
getPoolingConfigMixin()
Return an IntroductionAdvisor that providing a mixin
exposing statistics about the pool maintained by this object.
|
abstract java.lang.Object |
getTarget()
Acquire an object from the pool.
|
abstract void |
releaseTarget(java.lang.Object target)
Return the given object to the pool.
|
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
Set the owning BeanFactory.
|
void |
setMaxSize(int maxSize)
Set the maximum size of the pool.
|
destroyPrototypeInstance, newPrototypeInstance, writeReplacecopyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, isStatic, setTargetBeanName, setTargetClass, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetActiveCount, getIdleCountpublic void setMaxSize(int maxSize)
public int getMaxSize()
getMaxSize in interface PoolingConfigpublic final void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
throws org.springframework.beans.BeansException
AbstractBeanFactoryBasedTargetSourcegetBean method on every invocation.setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwaresetBeanFactory in class AbstractPrototypeBasedTargetSourceorg.springframework.beans.BeansExceptionprotected abstract void createPool()
throws java.lang.Exception
java.lang.Exception - to avoid placing constraints on pooling APIspublic abstract java.lang.Object getTarget()
throws java.lang.Exception
getTarget in interface TargetSourcejava.lang.Exception - we may need to deal with checked exceptions from pool
APIs, so we're forgiving with our exception signaturepublic abstract void releaseTarget(java.lang.Object target)
throws java.lang.Exception
releaseTarget in interface TargetSourcereleaseTarget in class AbstractBeanFactoryBasedTargetSourcetarget - object that must have been acquired from the pool
via a call to getTarget()java.lang.Exception - to allow pooling APIs to throw exceptiongetTarget()public DefaultIntroductionAdvisor getPoolingConfigMixin()