org.apache.cocoon.core.container.handler
Class NonThreadSafePoolableComponentHandler

java.lang.Object
  extended byorg.apache.cocoon.core.container.handler.AbstractComponentHandler
      extended byorg.apache.cocoon.core.container.handler.AbstractFactoryHandler
          extended byorg.apache.cocoon.core.container.handler.NonThreadSafePoolableComponentHandler
All Implemented Interfaces:
ComponentHandler
Direct Known Subclasses:
PoolableComponentHandler

public class NonThreadSafePoolableComponentHandler
extends AbstractFactoryHandler

The PoolableComponentHandler to make sure that poolable components are initialized destroyed and pooled correctly.

Components which implement Poolable may be configured to be pooled using the following example configuration. This example assumes that the user component class MyComp implements Poolable.

Configuration Example:

   <my-comp pool-max="8"/>
 

Roles Example:

   <role name="com.mypkg.MyComponent"
         shorthand="my-comp"
         default-class="com.mypkg.DefaultMyComponent"/>
 

Configuration Attributes:

Since:
2.2
Version:
$Id: NonThreadSafePoolableComponentHandler.java 312637 2005-10-10 13:00:42Z cziegeler $

Field Summary
static int DEFAULT_MAX_POOL_SIZE
          The default max size of the pool
protected  Object semaphore
          Object used to synchronize access to the get and put methods
 
Fields inherited from class org.apache.cocoon.core.container.handler.AbstractFactoryHandler
factory
 
Fields inherited from class org.apache.cocoon.core.container.handler.AbstractComponentHandler
disposed, logger
 
Constructor Summary
NonThreadSafePoolableComponentHandler(ComponentInfo info, Logger logger, ComponentFactory factory, Configuration config)
          Create a PoolableComponentHandler which manages a pool of Components created by the specified factory object.
 
Method Summary
 void dispose()
          Dispose of the ComponentHandler and any associated Pools and Factories.
protected  Object doGet()
          Concrete implementation of getting a component.
protected  void doInitialize()
           
protected  void doPut(Object component)
          Concrete implementation of putting back a component.
protected  Object getFromPool()
          Gets a Poolable from the pool.
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.
protected  void putIntoPool(Object poolable)
          Returns a poolable to the pool
 
Methods inherited from class org.apache.cocoon.core.container.handler.AbstractFactoryHandler
decommission
 
Methods inherited from class org.apache.cocoon.core.container.handler.AbstractComponentHandler
canBeDisposed, get, getComponentHandler, getComponentHandler, getInfo, initialize, isSingleton, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_POOL_SIZE

public static final int DEFAULT_MAX_POOL_SIZE
The default max size of the pool

See Also:
Constant Field Values

semaphore

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

Constructor Detail

NonThreadSafePoolableComponentHandler

public NonThreadSafePoolableComponentHandler(ComponentInfo info,
                                             Logger logger,
                                             ComponentFactory factory,
                                             Configuration config)
                                      throws Exception
Create a PoolableComponentHandler which manages a pool of Components created by the specified factory object.

Parameters:
factory - The factory object which is responsible for creating the components managed by the ComponentHandler.
config - The configuration to use to configure the pool.
Method Detail

dispose

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

Specified by:
dispose in interface ComponentHandler
Overrides:
dispose in class AbstractComponentHandler

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

protected 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

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

Parameters:
poolable - Poolable to return to the pool.

doInitialize

protected void doInitialize()
Specified by:
doInitialize in class AbstractComponentHandler

doGet

protected Object doGet()
                throws Exception
Description copied from class: AbstractComponentHandler
Concrete implementation of getting a component.

Specified by:
doGet in class AbstractComponentHandler
Returns:
a service
Throws:
Exception - if an error occurs

doPut

protected void doPut(Object component)
              throws Exception
Description copied from class: AbstractComponentHandler
Concrete implementation of putting back a component.

Specified by:
doPut in class AbstractComponentHandler
Parameters:
component - a Component value
Throws:
Exception - if an error occurs


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.