org.apache.turbine.services.pool
Interface PoolService

All Superinterfaces:
Initable, Service
All Known Implementing Classes:
TurbinePoolService

public interface PoolService
extends Service

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 intance 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 534527 2007-05-02 16:10:59Z tv $
Author:
Ilkka Priha

Field Summary
static int DEFAULT_POOL_CAPACITY
          The default pool capacity.
static java.lang.String POOL_CAPACITY_KEY
          The name of the pool capacity property
static boolean POOL_DEBUG_DEFAULT
          Default Value for debug mode
static java.lang.String POOL_DEBUG_KEY
          Are we running in debug mode?
static java.lang.String SERVICE_NAME
          The key under which this service is stored in TurbineServices.
 
Method Summary
 void clearPool()
          Clears all instances from the pool.
 void clearPool(java.lang.String className)
          Clears instances of a named class from the pool.
 int getCapacity(java.lang.String className)
          Gets the capacity of the pool for a named class.
 java.lang.Object getInstance(java.lang.Class clazz)
          Gets an instance of a specified class either from the pool or by instatiating from the class if the pool is empty.
 java.lang.Object getInstance(java.lang.Class clazz, java.lang.Object[] params, java.lang.String[] signature)
          Gets an instance of a specified class either from the pool or by instatiating from the class if the pool is empty.
 java.lang.Object getInstance(java.lang.String className)
          Gets an instance of a named class.
 java.lang.Object getInstance(java.lang.String className, java.lang.ClassLoader loader)
          Gets an instance of a named class using a specified class loader.
 java.lang.Object getInstance(java.lang.String className, java.lang.ClassLoader loader, java.lang.Object[] params, java.lang.String[] signature)
          Gets an instance of a named class using a specified class loader.
 java.lang.Object getInstance(java.lang.String className, java.lang.Object[] params, java.lang.String[] signature)
          Gets an instance of a named class.
 int getSize(java.lang.String className)
          Gets the current size of the pool for a named class.
 boolean isLoaderSupported(java.lang.String className)
          Deprecated. Use TurbineFactory.isLoaderSupported(className)
 boolean putInstance(java.lang.Object instance)
          Puts a used object back to the pool.
 void setCapacity(java.lang.String className, int capacity)
          Sets the capacity of the pool for a named class.
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, init, setInitableBroker, shutdown
 

Field Detail

SERVICE_NAME

public static final java.lang.String SERVICE_NAME
The key under which this service is stored in TurbineServices.

See Also:
Constant Field Values

DEFAULT_POOL_CAPACITY

public static final int DEFAULT_POOL_CAPACITY
The default pool capacity.

See Also:
Constant Field Values

POOL_CAPACITY_KEY

public static final java.lang.String POOL_CAPACITY_KEY
The name of the pool capacity property

See Also:
Constant Field Values

POOL_DEBUG_KEY

public static final java.lang.String POOL_DEBUG_KEY
Are we running in debug mode?

See Also:
Constant Field Values

POOL_DEBUG_DEFAULT

public static final boolean POOL_DEBUG_DEFAULT
Default Value for debug mode

See Also:
Constant Field Values
Method Detail

getInstance

public java.lang.Object getInstance(java.lang.String className)
                             throws TurbineException
Gets an instance of a named class.

Parameters:
className - the name of the class.
Returns:
the instance.
Throws:
TurbineException - if instantiation fails.

getInstance

public java.lang.Object getInstance(java.lang.String className,
                                    java.lang.ClassLoader loader)
                             throws TurbineException
Gets an instance of a named class using a specified class loader.

Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.

Parameters:
className - the name of the class.
loader - the class loader.
Returns:
the instance.
Throws:
TurbineException - if instantiation fails.

getInstance

public java.lang.Object getInstance(java.lang.String className,
                                    java.lang.Object[] params,
                                    java.lang.String[] signature)
                             throws TurbineException
Gets an instance of a named class. Parameters for its constructor are given as an array of objects, primitive types must be wrapped with a corresponding class.

Parameters:
className - the name of the class.
params - an array containing the parameters of the constructor.
signature - an array containing the signature of the constructor.
Returns:
the instance.
Throws:
TurbineException - if instantiation fails.

getInstance

public java.lang.Object getInstance(java.lang.String className,
                                    java.lang.ClassLoader loader,
                                    java.lang.Object[] params,
                                    java.lang.String[] signature)
                             throws TurbineException
Gets an instance of a named class using a specified class loader. Parameters for its constructor are given as an array of objects, primitive types must be wrapped with a corresponding class.

Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.

Parameters:
className - the name of the class.
loader - the class loader.
params - an array containing the parameters of the constructor.
signature - an array containing the signature of the constructor.
Returns:
the instance.
Throws:
TurbineException - if instantiation fails.

isLoaderSupported

public boolean isLoaderSupported(java.lang.String className)
                          throws TurbineException
Deprecated. Use TurbineFactory.isLoaderSupported(className)

Tests if specified class loaders are supported for a named class.

Parameters:
className - the name of the class.
Returns:
true if class loaders are supported, false otherwise.
Throws:
TurbineException - if test fails.

getInstance

public java.lang.Object getInstance(java.lang.Class clazz)
                             throws TurbineException
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:
TurbineException - if recycling fails.

getInstance

public java.lang.Object getInstance(java.lang.Class clazz,
                                    java.lang.Object[] params,
                                    java.lang.String[] signature)
                             throws TurbineException
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:
TurbineException - if recycling fails.

putInstance

public boolean putInstance(java.lang.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

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

Parameters:
className - the name of the class.

setCapacity

public void setCapacity(java.lang.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

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

Parameters:
className - the name of the class.

clearPool

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

Parameters:
className - the name of the class.

clearPool

public void clearPool()
Clears all instances from the pool.



Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.