org.apache.turbine.services.pool
Class TurbinePoolService
java.lang.Object
|
+--org.apache.turbine.services.BaseInitable
|
+--org.apache.turbine.services.BaseService
|
+--org.apache.turbine.services.TurbineBaseService
|
+--org.apache.turbine.services.factory.TurbineFactoryService
|
+--org.apache.turbine.services.pool.TurbinePoolService
- All Implemented Interfaces:
- FactoryService, Initable, PoolService, Service
- public class TurbinePoolService
- extends TurbineFactoryService
- implements 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 instance will be requested
from the FactoryService.
For objects implementing the Recyclable interface, a recycle
method will be called, when they taken from the pool, and
a dispose method, when they are returned to the pool.
- Version:
- $Id: TurbinePoolService.java,v 1.4 2002/07/11 16:53:25 mpoeschl Exp $
- Author:
- Ilkka Priha
Field Summary |
static java.lang.String |
POOL_CAPACITY
The property specifying the pool capacity. |
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 either from the pool
or by calling the Factory Service if the pool is empty. |
java.lang.Object |
getInstance(java.lang.String className,
java.lang.ClassLoader loader)
Gets an instance of a named class either from the pool
or by calling the Factory Service if the pool is empty. |
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 either from the pool
or by calling the Factory Service if the pool is empty. |
java.lang.Object |
getInstance(java.lang.String className,
java.lang.Object[] params,
java.lang.String[] signature)
Gets an instance of a named class either from the pool
or by calling the Factory Service if the pool is empty. |
int |
getSize(java.lang.String className)
Gets the current size of the pool for a named class. |
void |
init()
Initializes the service by setting the pool capacity. |
boolean |
isLoaderSupported(java.lang.String className)
Tests if specified class loaders are supported for a named class. |
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 class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
POOL_CAPACITY
public static final java.lang.String POOL_CAPACITY
- The property specifying the pool capacity.
TurbinePoolService
public TurbinePoolService()
- Constructs a Pool Service.
init
public void init()
throws InitializationException
- Initializes the service by setting the pool capacity.
- Specified by:
init
in interface Initable
- Overrides:
init
in class TurbineFactoryService
- Parameters:
config
- initialization configuration.- Throws:
InitializationException
- if initialization fails.
getInstance
public java.lang.Object getInstance(java.lang.String className)
throws TurbineException
- Gets an instance of a named class either from the pool
or by calling the Factory Service if the pool is empty.
- Specified by:
getInstance
in interface FactoryService
- Overrides:
getInstance
in class TurbineFactoryService
- Parameters:
className
- the name of the class.- Returns:
- the instance.
- Throws:
TurbineException
- if recycling fails.
getInstance
public java.lang.Object getInstance(java.lang.String className,
java.lang.ClassLoader loader)
throws TurbineException
- Gets an instance of a named class either from the pool
or by calling the Factory Service if the pool is empty.
The specified class loader will be passed to the Factory Service.
- Specified by:
getInstance
in interface FactoryService
- Overrides:
getInstance
in class TurbineFactoryService
- Parameters:
className
- the name of the class.loader
- the class loader.- Returns:
- the instance.
- Throws:
TurbineException
- if recycling 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 either from the pool
or by calling the Factory Service if the pool is empty.
Parameters for its constructor are given as an array of objects,
primitive types must be wrapped with a corresponding class.
- Specified by:
getInstance
in interface FactoryService
- Overrides:
getInstance
in class TurbineFactoryService
- 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 recycling 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 either from the pool
or by calling the Factory Service if the pool is empty.
Parameters for its constructor are given as an array of objects,
primitive types must be wrapped with a corresponding class.
The specified class loader will be passed to the Factory Service.
- Specified by:
getInstance
in interface FactoryService
- Overrides:
getInstance
in class TurbineFactoryService
- 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 recycling fails.
isLoaderSupported
public boolean isLoaderSupported(java.lang.String className)
throws TurbineException
- Tests if specified class loaders are supported for a named class.
- Specified by:
isLoaderSupported
in interface FactoryService
- Overrides:
isLoaderSupported
in class TurbineFactoryService
- 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.
- Specified by:
getInstance
in interface PoolService
- Overrides:
getInstance
in class TurbineFactoryService
- 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.
- Specified by:
getInstance
in interface PoolService
- Overrides:
getInstance
in class TurbineFactoryService
- 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.
- Specified by:
putInstance
in interface PoolService
- 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.
- Specified by:
getCapacity
in interface PoolService
- 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.
- Specified by:
setCapacity
in interface PoolService
- 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.
- Specified by:
getSize
in interface PoolService
- Parameters:
className
- the name of the class.
clearPool
public void clearPool(java.lang.String className)
- Clears instances of a named class from the pool.
- Specified by:
clearPool
in interface PoolService
- Parameters:
className
- the name of the class.
clearPool
public void clearPool()
- Clears all instances from the pool.
- Specified by:
clearPool
in interface PoolService
Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.