org.norther.tammi.core.pool
Interface Pool

All Superinterfaces:
ObjectFactory
All Known Implementing Classes:
DefaultPool

public interface Pool
extends ObjectFactory

Pool extends ObjectFactory by adding support to pool instantiated objects. When a new instance is requested, the factory 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 specified Factory.

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.

Author:
Ilkka Priha

Field Summary
static int DEFAULT_POOL_CAPACITY
          The default pool capacity.
 
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()
          Gets the default capacity of the pool.
 int getCapacity(String className)
          Gets the capacity of the pool for a named class.
 ObjectName getFactoryName()
          Gets the factory of this pool.
 Object getInstance(Class clazz)
          Gets an instance of a specified class either from the pool or by instatiating 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 instatiating 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(int capacity)
          Sets the default capacity of the pool.
 void setCapacity(String className, int capacity)
          Sets the capacity of the pool for a named class.
 void setFactoryName(ObjectName factory)
          Sets the factory of this pool.
 
Methods inherited from interface org.norther.tammi.core.base.ObjectFactory
getInstance, getInstance, getInstance, getInstance, isLoaderSupported
 

Field Detail

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 ConstructionException
Gets an instance of a specified class either from the pool or by instatiating from the class if the pool is empty.

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

getInstance

Object getInstance(Class clazz,
                   Object[] params,
                   String[] signature)
                   throws ConstructionException
Gets an instance of a specified class either from the pool or by instatiating 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:
ConstructionException - 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()
Gets the default capacity of the pool.

Returns:
the default capacity.

setCapacity

void setCapacity(int capacity)
Sets the default capacity of the pool. Note that only pools for classes created after this change will use the new capacity.

Parameters:
capacity - the new capacity.

getCapacity

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

Parameters:
className - the name of the class.
Returns:
the capacity for 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.
Returns:
the size.

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.


getFactoryName

ObjectName getFactoryName()
Gets the factory of this pool.

Returns:
the object name of the factory or a query.

setFactoryName

void setFactoryName(ObjectName factory)
Sets the factory of this pool. If it is not set, the default one will be used.

Parameters:
factory - the object name of the factory or a query.


Copyright © 2004 The Norther Organization. All rights reserved.