toolbox.pooling
Class ResourcePoolImpl

Package class diagram package ResourcePoolImpl
java.lang.Object
  extended by toolbox.pooling.ResourcePoolImpl
All Implemented Interfaces:
ResourcePool
Direct Known Subclasses:
JDBCResourcePool, SocketResourcePool

public abstract class ResourcePoolImpl
extends java.lang.Object
implements ResourcePool

A generic implementation of ResourcePool interface. Provides abstract methods that must be overridden to do resource specific creation,validation and cleanup.


Field Summary
protected  java.util.Properties m_customProps
          Custom properties configured for specific pool implementation.
 
Constructor Summary
ResourcePoolImpl()
           
 
Method Summary
protected abstract  java.lang.Object createResource(XMLProperties xmlProps, int count)
          Subclasses of this class must implement this method with resource specific initialisation code.
 void destroy()
          Destroy this pool
protected abstract  void destroyResource(java.lang.Object resource)
          Subclasses of this class must implement this method with resource specific cleanup code.
protected  java.lang.String getName()
          Returns the name of this pool.
 java.lang.Object getResource()
          Returns a resource from this pool.
 java.lang.String getStatus()
          Returns the current status of this pool.
protected  java.lang.String getStatusString()
          Return the status of the pool
 void init(java.lang.String name, XMLProperties xmlProps)
          Initialises the lists, sizes, custom properties and initial resources for this pool.
protected abstract  boolean isResourceValid(java.lang.Object resource)
          Validates the resource and returns a state indicator.
protected abstract  void preInit(XMLProperties xmlProps)
          Subclasses may choose to override this method to perform custom initialisation before the init() method of this class starts calling the createResource() method.
 void releaseResource(java.lang.Object resource)
          Releases a resource back to this pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_customProps

protected java.util.Properties m_customProps
Custom properties configured for specific pool implementation.

Constructor Detail

ResourcePoolImpl

public ResourcePoolImpl()
Method Detail

preInit

protected abstract void preInit(XMLProperties xmlProps)
                         throws ResourcePoolException
Subclasses may choose to override this method to perform custom initialisation before the init() method of this class starts calling the createResource() method.

Parameters:
xmlProps - XML configuration properties.
Throws:
ResourcePoolException - if the custom initialisation fails.

createResource

protected abstract java.lang.Object createResource(XMLProperties xmlProps,
                                                   int count)
                                            throws ResourcePoolException
Subclasses of this class must implement this method with resource specific initialisation code. This method will be called from init and get methods to create resources.

Parameters:
xmlProps - XML configuration properties.
count - int indicating how many times this method has been called. Will be context specific.
Throws:
ResourcePoolException - if an exception occurs while creating a resource.

destroyResource

protected abstract void destroyResource(java.lang.Object resource)
                                 throws ResourcePoolException
Subclasses of this class must implement this method with resource specific cleanup code. This method will called from the destroy method.

Parameters:
resource - Resource to destroy.
Throws:
ResourcePoolException - if the given resource cannot be destroyed.

isResourceValid

protected abstract boolean isResourceValid(java.lang.Object resource)
                                    throws ResourcePoolException
Validates the resource and returns a state indicator. Subclasses must implement this method to do resource specific validation.

Parameters:
resource - Resource to validate.
Returns:
boolean indicating the state of the resource.
Throws:
ResourcePoolException - if the resource cannot be validated.

getStatus

public java.lang.String getStatus()
Returns the current status of this pool.

Specified by:
getStatus in interface ResourcePool
Returns:
String containing the status of this pool.

getStatusString

protected java.lang.String getStatusString()
Return the status of the pool

Returns:
String containing the status of the pool.

getName

protected java.lang.String getName()
Returns the name of this pool. returns the name of this pool.


init

public void init(java.lang.String name,
                 XMLProperties xmlProps)
          throws ResourcePoolException
Initialises the lists, sizes, custom properties and initial resources for this pool.

Specified by:
init in interface ResourcePool
Parameters:
name - Name of this pool.
xmlProps - XML configuration properties.
Throws:
ResourcePoolException - if the pool cannot be initialised.

getResource

public java.lang.Object getResource()
                             throws ResourcePoolException
Returns a resource from this pool. A resource is returned in the following manner:

The available list is checked for resources. If none are available a new resource is created if the maximum number of resources have not yet been reached.

If the maximum number of resources have been reached this call blocks until a resource becomes available.

Specified by:
getResource in interface ResourcePool
Returns:
Object containing resource.
Throws:
ResourcePoolException - if the a resource could not be returned.

releaseResource

public void releaseResource(java.lang.Object resource)
Releases a resource back to this pool.

Specified by:
releaseResource in interface ResourcePool
Parameters:
resource - Resource to release back to the pool.

destroy

public void destroy()
             throws ResourcePoolException
Destroy this pool

Specified by:
destroy in interface ResourcePool
Throws:
ResourcePoolException - if this pool cannot be destroyed.