org.norther.tammi.core.pool
Class DefaultPool

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.pool.DefaultPool
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, ObjectFactory, Pool

public class DefaultPool
extends Adaptee
implements Pool

A default implementation of Pool.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.pool.Pool
DEFAULT_POOL_CAPACITY
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultPool()
          Constructs a Pool Service.
 
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.
 Object getInstance(String className)
          Gets an instance of a named class.
 Object getInstance(String className, Object[] params, String[] signature)
          Gets an instance of a named class.
 Object getInstance(String className, ObjectName loader)
          Gets an instance of a named class using a specified class loader.
 Object getInstance(String className, ObjectName loader, Object[] params, String[] signature)
          Gets an instance of a named class using a specified class loader.
protected static Class getPrimitiveClass(String type)
          Gets the class of a primitive type.
 int getSize(String className)
          Gets the current size of the pool for a named class.
 boolean isLoaderSupported(String className)
          Checks if specified class loaders are supported for a named class.
 void postmanaged()
          This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.
 boolean putInstance(Object object)
          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 executor)
          Sets the factory of this pool.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPool

public DefaultPool()
Constructs a Pool Service.

Method Detail

getPrimitiveClass

protected static Class getPrimitiveClass(String type)
Gets the class of a primitive type.

Parameters:
type - a primitive type.
Returns:
the corresponding class, or null.

postmanaged

public void postmanaged()
Description copied from interface: Manageable
This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.

Specified by:
postmanaged in interface Manageable
Overrides:
postmanaged in class Adaptee

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

getInstance

public Object getInstance(String className)
                   throws ConstructionException
Description copied from interface: ObjectFactory
Gets an instance of a named class.

Specified by:
getInstance in interface ObjectFactory
Parameters:
className - the name of the class.
Returns:
the instance.
Throws:
ConstructionException - if construction fails.

getInstance

public Object getInstance(String className,
                          ObjectName loader)
                   throws ConstructionException
Description copied from interface: ObjectFactory
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.

Specified by:
getInstance in interface ObjectFactory
Parameters:
className - the name of the class.
loader - the class loader.
Returns:
the instance.
Throws:
ConstructionException - if construction fails.

getInstance

public Object getInstance(String className,
                          Object[] params,
                          String[] signature)
                   throws ConstructionException
Description copied from interface: ObjectFactory
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.

Specified by:
getInstance in interface ObjectFactory
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:
ConstructionException - if construction fails.

getInstance

public Object getInstance(String className,
                          ObjectName loader,
                          Object[] params,
                          String[] signature)
                   throws ConstructionException
Description copied from interface: ObjectFactory
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.

Specified by:
getInstance in interface ObjectFactory
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:
ConstructionException - if construction fails.

isLoaderSupported

public boolean isLoaderSupported(String className)
Description copied from interface: ObjectFactory
Checks if specified class loaders are supported for a named class.

Specified by:
isLoaderSupported in interface ObjectFactory
Parameters:
className - the name of the class.
Returns:
true if class loaders are supported, false otherwise.

getInstance

public Object getInstance(Class clazz)
                   throws ConstructionException
Description copied from interface: Pool
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 Pool
Parameters:
clazz - the class.
Returns:
the instance.
Throws:
ConstructionException - if recycling fails.

getInstance

public Object getInstance(Class clazz,
                          Object[] params,
                          String[] signature)
                   throws ConstructionException
Description copied from interface: Pool
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 Pool
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

public boolean putInstance(Object object)
Description copied from interface: Pool
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 Pool
Parameters:
object - the object instance to recycle.
Returns:
true if the instance was accepted.

getCapacity

public int getCapacity()
Description copied from interface: Pool
Gets the default capacity of the pool.

Specified by:
getCapacity in interface Pool
Returns:
the default capacity.

setCapacity

public void setCapacity(int capacity)
Description copied from interface: Pool
Sets the default capacity of the pool. Note that only pools for classes created after this change will use the new capacity.

Specified by:
setCapacity in interface Pool
Parameters:
capacity - the new capacity.

getCapacity

public int getCapacity(String className)
Description copied from interface: Pool
Gets the capacity of the pool for a named class.

Specified by:
getCapacity in interface Pool
Parameters:
className - the name of the class.
Returns:
the capacity for the class.

setCapacity

public void setCapacity(String className,
                        int capacity)
Description copied from interface: Pool
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 Pool
Parameters:
className - the name of the class.
capacity - the new capacity.

getSize

public int getSize(String className)
Description copied from interface: Pool
Gets the current size of the pool for a named class.

Specified by:
getSize in interface Pool
Parameters:
className - the name of the class.
Returns:
the size.

clearPool

public void clearPool(String className)
Description copied from interface: Pool
Clears instances of a named class from the pool.

Specified by:
clearPool in interface Pool
Parameters:
className - the name of the class.

clearPool

public void clearPool()
Description copied from interface: Pool
Clears all instances from the pool.

Specified by:
clearPool in interface Pool

getFactoryName

public ObjectName getFactoryName()
Description copied from interface: Pool
Gets the factory of this pool.

Specified by:
getFactoryName in interface Pool
Returns:
the object name of the factory or a query.

setFactoryName

public void setFactoryName(ObjectName executor)
Description copied from interface: Pool
Sets the factory of this pool. If it is not set, the default one will be used.

Specified by:
setFactoryName in interface Pool
Parameters:
executor - the object name of the factory or a query.


Copyright © 2004 The Norther Organization. All rights reserved.