org.springframework.aop.target
Class AbstractPoolingTargetSource

java.lang.Object
  extended byorg.springframework.aop.target.AbstractPrototypeTargetSource
      extended byorg.springframework.aop.target.AbstractPoolingTargetSource
All Implemented Interfaces:
BeanFactoryAware, DisposableBean, InitializingBean, PoolingConfig, TargetSource
Direct Known Subclasses:
CommonsPoolTargetSource

public abstract class AbstractPoolingTargetSource
extends AbstractPrototypeTargetSource
implements PoolingConfig, DisposableBean

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.

Version:
$Id: AbstractPoolingTargetSource.java,v 1.7 2004/03/18 02:46:13 trisberg Exp $
Author:
Rod Johnson

Field Summary
 
Fields inherited from class org.springframework.aop.target.AbstractPrototypeTargetSource
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()
           
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(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.AbstractPrototypeTargetSource
afterPropertiesSet, getTargetBeanName, getTargetClass, isStatic, newPrototypeInstance, setTargetBeanName
 
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
getActive, getFree
 
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.

Parameters:
maxSize - the size for the pool

getMaxSize

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

Specified by:
getMaxSize in interface PoolingConfig
Returns:
the size of the pool

setBeanFactory

public final void setBeanFactory(BeanFactory beanFactory)
                          throws BeansException
Description copied from class: AbstractPrototypeTargetSource
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 AbstractPrototypeTargetSource
Throws:
BeansException

createPool

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

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

getTarget

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

Specified by:
getTarget in interface TargetSource
Returns:
an object from the pool
Throws:
java.lang.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(java.lang.Object target)
                            throws java.lang.Exception
Return the given object to the pool.

Specified by:
releaseTarget in interface TargetSource
Parameters:
target - object that must have been acquired from the pool via a call to acquireTarget()
Throws:
java.lang.Exception - to allow pooling APIs to throw exception

getPoolingConfigMixin

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


Copyright (C) 2003-2004 The Spring Framework Project.