org.springframework.aop.target
Class AbstractPoolingTargetSource

java.lang.Object
  extended by org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
      extended by org.springframework.aop.target.AbstractPrototypeBasedTargetSource
          extended by org.springframework.aop.target.AbstractPoolingTargetSource
All Implemented Interfaces:
Serializable, PoolingConfig, TargetSource, BeanFactoryAware, DisposableBean
Direct Known Subclasses:
CommonsPoolTargetSource

public abstract class AbstractPoolingTargetSource
extends AbstractPrototypeBasedTargetSource
implements PoolingConfig, DisposableBean

Abstract superclass for pooling TargetSources that maintains a pool of target instances, acquiring and releasing a target object from the pool for each method invocation. This class is independent of pooling technology.

Subclasses must implement the getTarget() and methods to work with their chosen pool. The newPrototypeInstance() method inherited from AbstractPrototypeBasedTargetSource can be used to create objects to put in the pool.

Subclasses must also implement some of the monitoring methods from the PoolingConfig interface.

This class provides the getPoolingConfigMixin() method to return an IntroductionAdvisor making these stats available on proxied objects.

This class implements DisposableBean to force subclasses to implement a destroy() method to close down their pool.

Author:
Rod Johnson
See Also:
getTarget(), releaseTarget(java.lang.Object), DisposableBean.destroy(), Serialized Form

Field Summary
 
Fields inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
logger
 
Constructor Summary
AbstractPoolingTargetSource()
           
 
Method Summary
protected abstract  void createPool(BeanFactory beanFactory)
          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  Object getTarget()
          Acquire an object from the pool.
abstract  void releaseTarget(Object target)
          Return the given object to the pool.
 void setBeanFactory(BeanFactory beanFactory)
          Set the owning BeanFactory.
 void setMaxSize(int maxSize)
          Set the maximum size of the pool.
 
Methods inherited from class org.springframework.aop.target.AbstractPrototypeBasedTargetSource
newPrototypeInstance
 
Methods inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
copyFrom, getBeanFactory, getTargetBeanName, getTargetClass, isStatic, setTargetBeanName, setTargetClass, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.aop.target.PoolingConfig
getActiveCount, getIdleCount
 
Methods inherited from interface org.springframework.beans.factory.DisposableBean
destroy
 

Constructor Detail

AbstractPoolingTargetSource

public AbstractPoolingTargetSource()
Method Detail

setMaxSize

public void setMaxSize(int maxSize)
Set the maximum size of the pool. Default is -1, indicating no size limit.


getMaxSize

public int getMaxSize()
Return the maximum size of the pool.

Specified by:
getMaxSize in interface PoolingConfig

setBeanFactory

public final void setBeanFactory(BeanFactory beanFactory)
                          throws BeansException
Description copied from class: AbstractBeanFactoryBasedTargetSource
Set the owning BeanFactory. We need to save a reference so that we can use the getBean method on every invocation.

Specified by:
setBeanFactory in interface BeanFactoryAware
Overrides:
setBeanFactory in class AbstractPrototypeBasedTargetSource
Parameters:
beanFactory - owning BeanFactory (may not be null). The bean can immediately call methods on the factory.
Throws:
BeansException - in case of initialization errors
See Also:
BeanInitializationException

createPool

protected abstract void createPool(BeanFactory beanFactory)
                            throws Exception
Create the pool.

Parameters:
beanFactory - owning BeanFactory, in case we need collaborators from it (normally our own properties are sufficient)
Throws:
Exception - to avoid placing constraints on pooling APIs

getTarget

public abstract Object getTarget()
                          throws Exception
Acquire an object from the pool.

Specified by:
getTarget in interface TargetSource
Returns:
an object from the pool
Throws:
Exception - we may need to deal with checked exceptions from pool APIs, so we're forgiving with our exception signature

releaseTarget

public abstract void releaseTarget(Object target)
                            throws Exception
Return the given object to the pool.

Specified by:
releaseTarget in interface TargetSource
Overrides:
releaseTarget in class AbstractBeanFactoryBasedTargetSource
Parameters:
target - object that must have been acquired from the pool via a call to getTarget()
Throws:
Exception - to allow pooling APIs to throw exception
See Also:
getTarget()

getPoolingConfigMixin

public DefaultIntroductionAdvisor getPoolingConfigMixin()
Return an IntroductionAdvisor that providing a mixin exposing statistics about the pool maintained by this object.



Copyright (c) 2002-2006 The Spring Framework Project.