Top Description Fields Constructors Methods
org.springframework.aop.target

public abstract Class AbstractPoolingTargetSource

extends AbstractPrototypeBasedTargetSource
implements PoolingConfig, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.aop.target.PoolingConfig
Known Direct Subclasses
org.springframework.aop.target.CommonsPool2TargetSource
Annotations
@SuppressWarnings:serial
Imports
org.springframework.aop.support.DefaultIntroductionAdvisor, .DelegatingIntroductionInterceptor, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, .BeanInitializationException, .DisposableBean, org.springframework.lang.Nullable

Abstract base class for pooling org.springframework.aop.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 methods based on their chosen object pool. The newPrototypeInstance() method inherited from AbstractPrototypeBasedTargetSource can be used to create objects in order to put them into the pool.

Subclasses must also implement some monitoring methods from the PoolingConfig interface. The getPoolingConfigMixin() method makes these stats available on proxied objects through an IntroductionAdvisor.

This class implements the org.springframework.beans.factory.DisposableBean interface in order to force subclasses to implement a destroy() method, closing down their object pool.

Authors
Rod Johnson, Juergen Hoeller
See Also
getTarget, releaseTarget, destroy

Field Summary

Modifier and TypeField and Description
private int
maxSize

The maximum size of the pool.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected abstract void
createPool()

Create the pool.

public int
getMaxSize()

Implements org.springframework.aop.target.PoolingConfig.getMaxSize.

Return the maximum size of the pool.

public DefaultIntroductionAdvisor
getPoolingConfigMixin()

Return an IntroductionAdvisor that provides a mixin exposing statistics about the pool maintained by this object.

public abstract Object

Returns:

an object from the pool
getTarget
()

Redeclares org.springframework.aop.TargetSource.getTarget.

Acquire an object from the pool.

public abstract void
releaseTarget(Object
object that must have been acquired from the pool via a call to getTarget()
target
)

Redeclares as abstract: org.springframework.aop.TargetSource.releaseTarget.

Return the given object to the pool.

public final void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Overrides org.springframework.aop.target.AbstractPrototypeBasedTargetSource.setBeanFactory.

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Set the owning BeanFactory.

public void
setMaxSize(int maxSize)

Set the maximum size of the pool.

Inherited from org.springframework.aop.target.AbstractPrototypeBasedTargetSource:
destroyPrototypeInstancenewPrototypeInstancewriteReplace

Field Detail

maxSizeback to summary
private int maxSize

The maximum size of the pool.

Constructor Detail

AbstractPoolingTargetSourceback to summary
public AbstractPoolingTargetSource()

Method Detail

createPoolback to summary
protected abstract void createPool() throws Exception

Create the pool.

Exceptions
Exception:
to avoid placing constraints on pooling APIs
getMaxSizeback to summary
public int getMaxSize()

Implements org.springframework.aop.target.PoolingConfig.getMaxSize.

Return the maximum size of the pool.

Annotations
@Override
getPoolingConfigMixinback to summary
public DefaultIntroductionAdvisor getPoolingConfigMixin()

Return an IntroductionAdvisor that provides a mixin exposing statistics about the pool maintained by this object.

getTargetback to summary
public abstract Object getTarget() throws Exception

Redeclares org.springframework.aop.TargetSource.getTarget.

Acquire an object from the pool.

Returns:Object

an object from the pool

Annotations
@Override
@Nullable
Exceptions
Exception:
we may need to deal with checked exceptions from pool APIs, so we're forgiving with our exception signature
releaseTargetback to summary
public abstract void releaseTarget(Object target) throws Exception

Redeclares as abstract: org.springframework.aop.TargetSource.releaseTarget.

Return the given object to the pool.

Parameters
target:Object

object that must have been acquired from the pool via a call to getTarget()

Annotations
@Override
Exceptions
Exception:
to allow pooling APIs to throw exception
See Also
getTarget
setBeanFactoryback to summary
public final void setBeanFactory(BeanFactory beanFactory) throws BeansException

Overrides org.springframework.aop.target.AbstractPrototypeBasedTargetSource.setBeanFactory.

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource.setBeanFactory.

Set the owning BeanFactory. We need to save a reference so that we can use the getBean method on every invocation.

Parameters
beanFactory:BeanFactory

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
Exceptions
BeansException:

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

in case of initialization errors

setMaxSizeback to summary
public void setMaxSize(int maxSize)

Set the maximum size of the pool. Default is -1, indicating no size limit.