org.springframework.aop.target
Class AbstractPoolingTargetSource

org.springframework.aop.target.AbstractPrototypeTargetSource
  |
  +--org.springframework.aop.target.AbstractPoolingTargetSource
Direct Known Subclasses:
CommonsPoolTargetSource

public abstract class AbstractPoolingTargetSource
extends AbstractPrototypeTargetSource
implements DisposableBean, PoolingConfig

Abstract uperclass 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 releaseTarget() methods to work with their chosen pool. The newPrototypeInstance() method inherited from AbstractPrototypeTargetSource 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
Version: $Id: AbstractPoolingTargetSource.java,v 1.5 2004/01/21 20:21:35 johnsonr Exp $

Method Summary
 intgetMaxSize()
          Return the maximum size of the pool.
 DefaultInterceptionIntroductionAdvisorgetPoolingConfigMixin()
           
 abstract ObjectgetTarget()
          Acquire an object from the pool.
 abstract voidreleaseTarget(Object target)
          Return the given object to the pool.
 final voidsetBeanFactory(BeanFactory beanFactory)
           
 voidsetMaxSize(int maxSize)
          Set the maximum size of the pool.

Methods inherited from class org.springframework.aop.target.AbstractPrototypeTargetSource
afterPropertiesSet, getTargetBeanName, getTargetClass, isStatic, setTargetBeanName

Method Detail

getMaxSize

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

getPoolingConfigMixin

public DefaultInterceptionIntroductionAdvisor getPoolingConfigMixin()
Returns: an IntroductionAdvisor that providing a mixin exposing statistics about the pool maintained by this object

getTarget

public abstract Object getTarget()
throws java.lang.Exception
Acquire an object from the pool.
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, although we don't like APIs that throw Exception

releaseTarget

public abstract void releaseTarget(Object target)
throws java.lang.Exception
Return the given object to the pool.
Parameters:
target - object that must have been acquired from the pool via a call to acquireTarget()
Throws:
Exception - to allow pooling APIs to throw exception

setBeanFactory

public final void setBeanFactory(BeanFactory beanFactory)
throws org.springframework.beans.BeansException

setMaxSize

public void setMaxSize(int maxSize)
Set the maximum size of the pool.
Parameters:
maxSize - the size for the pool