org.apache.cocoon.core.container.spring.avalon
Class PoolableFactoryBean

java.lang.Object
  extended byorg.apache.cocoon.core.container.spring.avalon.PoolableFactoryBean
All Implemented Interfaces:
BeanFactoryAware, FactoryBean

public class PoolableFactoryBean
extends Object
implements FactoryBean, BeanFactoryAware

This factory bean adds simple pooling support to Spring.

Since:
2.2
Version:
$Id: PoolableFactoryBean.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  Class beanClass
          The class.
protected  BeanFactory beanFactory
          The corresponding bean factory.
static String DEFAULT_MAX_POOL_SIZE
          The default max size of the pool.
protected  Class[] interfaces
          All the interfaces for the proxy.
protected  Log log
          Logger (we use the same logging mechanism as Spring!)
protected  String name
          The pooled component.
protected  Method poolInMethod
           
protected  String poolInMethodName
          Pool-in-method-name.
protected  Method poolOutMethod
           
protected  String poolOutMethodName
          Pool-out-method-name.
protected  Object semaphore
          Object used to synchronize access to the get and put methods
 
Constructor Summary
PoolableFactoryBean(String name, String className)
          Create a PoolableComponentHandler which manages a pool of Components created by the specified factory object.
PoolableFactoryBean(String name, String className, String poolMaxString, org.apache.cocoon.configuration.Settings settings)
          Create a PoolableComponentHandler which manages a pool of Components created by the specified factory object.
 
Method Summary
 void dispose()
          Dispose of associated Pools and Factories.
protected  void enteringPool(Object component)
          Handle service specific methods for putting it into the pool
protected  void exitingPool(Object component)
          Handle service specific methods for getting it out of the pool
 Object getFromPool()
          Gets a Poolable from the pool.
 Object getObject()
           
 Class getObjectType()
           
 void initialize()
           
 boolean isSingleton()
           
protected  void permanentlyRemovePoolable(Object poolable)
          Permanently removes a poolable from the pool's active list and destroys it so that it will not ever be reused.
 void putIntoPool(Object poolable)
          Returns a poolable to the pool
 void setBeanFactory(BeanFactory beanFactory)
           
 void setPoolInMethodName(String poolInMethodName)
           
 void setPoolOutMethodName(String poolOutMethodName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final Log log
Logger (we use the same logging mechanism as Spring!)


DEFAULT_MAX_POOL_SIZE

public static final String DEFAULT_MAX_POOL_SIZE
The default max size of the pool.

See Also:
Constant Field Values

interfaces

protected final Class[] interfaces
All the interfaces for the proxy.


name

protected final String name
The pooled component.


beanClass

protected final Class beanClass
The class.


beanFactory

protected BeanFactory beanFactory
The corresponding bean factory.


semaphore

protected final Object semaphore
Object used to synchronize access to the get and put methods


poolInMethodName

protected String poolInMethodName
Pool-in-method-name.


poolOutMethodName

protected String poolOutMethodName
Pool-out-method-name.


poolInMethod

protected Method poolInMethod

poolOutMethod

protected Method poolOutMethod
Constructor Detail

PoolableFactoryBean

public PoolableFactoryBean(String name,
                           String className)
                    throws Exception
Create a PoolableComponentHandler which manages a pool of Components created by the specified factory object.

Parameters:
name - The name of the bean which should be pooled.

PoolableFactoryBean

public PoolableFactoryBean(String name,
                           String className,
                           String poolMaxString,
                           org.apache.cocoon.configuration.Settings settings)
                    throws Exception
Create a PoolableComponentHandler which manages a pool of Components created by the specified factory object.

Parameters:
name - The name of the bean which should be pooled.
Method Detail

setPoolInMethodName

public void setPoolInMethodName(String poolInMethodName)

setPoolOutMethodName

public void setPoolOutMethodName(String poolOutMethodName)

initialize

public void initialize()
                throws Exception
Throws:
Exception

dispose

public void dispose()
Dispose of associated Pools and Factories.


permanentlyRemovePoolable

protected void permanentlyRemovePoolable(Object poolable)
Permanently removes a poolable from the pool's active list and destroys it so that it will not ever be reused.

This method is only called by threads that have m_semaphore locked.


getFromPool

public Object getFromPool()
                   throws Exception
Gets a Poolable from the pool. If there is room in the pool, a new Poolable will be created. Depending on the parameters to the constructor, the method may block or throw an exception if a Poolable is not available on the pool.

Returns:
Always returns a Poolable. Contract requires that put must always be called with the Poolable returned.
Throws:
Exception - An exception may be thrown as described above or if there is an exception thrown by the ObjectFactory's newInstance() method.

putIntoPool

public void putIntoPool(Object poolable)
Returns a poolable to the pool

Parameters:
poolable - Poolable to return to the pool.

exitingPool

protected void exitingPool(Object component)
                    throws Exception
Handle service specific methods for getting it out of the pool

Throws:
Exception

enteringPool

protected void enteringPool(Object component)
Handle service specific methods for putting it into the pool


setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
                    throws BeansException
Specified by:
setBeanFactory in interface BeanFactoryAware
Throws:
BeansException
See Also:
BeanFactoryAware.setBeanFactory(org.springframework.beans.factory.BeanFactory)

getObject

public Object getObject()
                 throws Exception
Specified by:
getObject in interface FactoryBean
Throws:
Exception
See Also:
FactoryBean.getObject()

getObjectType

public Class getObjectType()
Specified by:
getObjectType in interface FactoryBean
See Also:
FactoryBean.getObjectType()

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface FactoryBean
See Also:
FactoryBean.isSingleton()


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.