org.apache.fulcrum.pool
Interface PoolService

All Known Implementing Classes:
DefaultPoolService

public interface PoolService

The Pool Service extends the Factory Service by adding support for pooling instantiated objects. When a new instance is requested, the service first checks its pool if one is available. If the the pool is empty, a new object will be instantiated from the specified class. If only class name is given, the request to create an instance will be forwarded to the Factory Service.

For objects implementing the Recyclable interface, a recycle method will be called, when they are taken from the pool, and a dispose method, when they are returned to the pool.

Version:
$Id: PoolService.java 542061 2007-05-28 00:26:58Z seade $
Author:
Ilkka Priha, Stephen McConnell

Field Summary
static int DEFAULT_POOL_CAPACITY
          The default pool capacity.
static String ROLE
          Avalon role - used to id the component within the manager
 
Method Summary
 void clearPool()
          Clears all instances from the pool.
 void clearPool(String className)
          Clears instances of a named class from the pool.
 int getCapacity(String className)
          Gets the capacity of the pool for a named class.
 Object getInstance(Class clazz)
          Gets an instance of a specified class either from the pool or by instantiating from the class if the pool is empty.
 Object getInstance(Class clazz, Object[] params, String[] signature)
          Gets an instance of a specified class either from the pool or by instantiating from the class if the pool is empty.
 int getSize(String className)
          Gets the current size of the pool for a named class.
 boolean putInstance(Object instance)
          Puts a used object back to the pool.
 void setCapacity(String className, int capacity)
          Sets the capacity of the pool for a named class.
 

Field Detail

ROLE

static final String ROLE
Avalon role - used to id the component within the manager


DEFAULT_POOL_CAPACITY

static final int DEFAULT_POOL_CAPACITY
The default pool capacity.

See Also:
Constant Field Values
Method Detail

getInstance

Object getInstance(Class clazz)
                   throws PoolException
Gets an instance of a specified class either from the pool or by instantiating from the class if the pool is empty.

Parameters:
clazz - the class.
Returns:
the instance.
Throws:
PoolException - if recycling fails.

getInstance

Object getInstance(Class clazz,
                   Object[] params,
                   String[] signature)
                   throws PoolException
Gets an instance of a specified class either from the pool or by instantiating from the class if the pool is empty.

Parameters:
clazz - the class.
params - an array containing the parameters of the constructor.
signature - an array containing the signature of the constructor.
Returns:
the instance.
Throws:
PoolException - if recycling fails.

putInstance

boolean putInstance(Object instance)
Puts a used object back to the pool. Objects implementing the Recyclable interface can provide a recycle method to be called when they are reused and a dispose method to be called when they are returned to the pool.

Parameters:
instance - the object instance to recycle.
Returns:
true if the instance was accepted.

getCapacity

int getCapacity(String className)
Gets the capacity of the pool for a named class.

Parameters:
className - the name of the class.

setCapacity

void setCapacity(String className,
                 int capacity)
Sets the capacity of the pool for a named class. Note that the pool will be cleared after the change.

Parameters:
className - the name of the class.
capacity - the new capacity.

getSize

int getSize(String className)
Gets the current size of the pool for a named class.

Parameters:
className - the name of the class.

clearPool

void clearPool(String className)
Clears instances of a named class from the pool.

Parameters:
className - the name of the class.

clearPool

void clearPool()
Clears all instances from the pool.



Copyright © 2005-2009 The Apache Software Foundation. All Rights Reserved.