org.cementj.pool
Class AbstractResourcePool

java.lang.Object
  extended by java.lang.Thread
      extended by org.cementj.pool.AbstractResourcePool
All Implemented Interfaces:
java.lang.Runnable, ResourcePool
Direct Known Subclasses:
DatabaseConnectionPool

public abstract class AbstractResourcePool
extends java.lang.Thread
implements ResourcePool

Abstract class providing basic resource pool functionality. Provides a default implementation for all ResourcePool interface methods except for createResource(). The easiest way to create a ResourcePool implementation is to extend this class.

Copyright: Delta Vortex Technologies, 2003.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int DEFAULT_POOL_SIZE
          Default number of resources allocated to pool
static long DEFAULT_SLEEP_TIME
          Default sleep time in milliseconds
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractResourcePool(java.lang.String poolName, java.util.Properties creationProperties)
           
AbstractResourcePool(java.lang.String poolName, java.util.Properties creationProperties, int poolSize)
           
AbstractResourcePool(java.lang.String poolName, java.util.Properties creationProperties, int poolSize, long sleepIntervalInMillis)
           
 
Method Summary
 void closeAll()
          Closes all resources in the pool.
abstract  Resource createResource(java.util.Properties props)
          Defines how a resource is created.
 java.util.Properties getCreationProperties()
          Gets the used to start resources in the pool.
static ResourcePool getPool(java.lang.String poolName)
          Gets the singleton instance of the resource pool.
 java.lang.String getPoolName()
          Provides name of the resoruce pool.
 int getPoolSize()
          Gets the number of resources allocated to pool.
 Resource getResource()
          Obtains resource from the pool.
 long getSleepTimeInMillis()
          Gets the sleep interval time in milliseconds.
 void initPool()
          Allocates initial resources for pool.
 void logStatus()
          Provides pool status information.
 void logStatus(Logger out)
          Provides pool status information.
 void recycleResource(Resource resource)
          Validates and puts a resource back in the resource pool.
 void run()
          Validates idle resources in the pool, replaces them if necessary.
 void setCreationProperties(java.util.Properties props)
          Sets properties used to create resources for the pool.
 void setPoolSize(int size)
          Sets the number of resources that should be allocated to the pool.
 void setSleepTimeInMillis(long millis)
          Sets the sleep time.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SLEEP_TIME

public static final long DEFAULT_SLEEP_TIME
Default sleep time in milliseconds

See Also:
Constant Field Values

DEFAULT_POOL_SIZE

public static final int DEFAULT_POOL_SIZE
Default number of resources allocated to pool

See Also:
Constant Field Values
Constructor Detail

AbstractResourcePool

public AbstractResourcePool(java.lang.String poolName,
                            java.util.Properties creationProperties)
                     throws ResourceException
Throws:
ResourceException

AbstractResourcePool

public AbstractResourcePool(java.lang.String poolName,
                            java.util.Properties creationProperties,
                            int poolSize)
                     throws ResourceException
Throws:
ResourceException

AbstractResourcePool

public AbstractResourcePool(java.lang.String poolName,
                            java.util.Properties creationProperties,
                            int poolSize,
                            long sleepIntervalInMillis)
                     throws ResourceException
Throws:
ResourceException
Method Detail

initPool

public void initPool()
              throws ResourceException
Allocates initial resources for pool.

Throws:
ResourceException
Since:
0.5

createResource

public abstract Resource createResource(java.util.Properties props)
                                 throws ResourceException
Description copied from interface: ResourcePool
Defines how a resource is created.

Specified by:
createResource in interface ResourcePool
Throws:
ResourceException

logStatus

public void logStatus()
Provides pool status information.

Since:
0.5

logStatus

public void logStatus(Logger out)
Provides pool status information.

Since:
0.5

setCreationProperties

public void setCreationProperties(java.util.Properties props)
Sets properties used to create resources for the pool.

Parameters:
Properties - needed by resource at startup.
Since:
0.5

getResource

public Resource getResource()
                     throws ResourceException
Obtains resource from the pool. Creates a new one if necessary.

Specified by:
getResource in interface ResourcePool
Returns:
Resource Valid and usable resource.
Throws:
ResourceException
Since:
0.5

setSleepTimeInMillis

public void setSleepTimeInMillis(long millis)
Sets the sleep time. This thread will validate all resources in the pool at the interval specified here. If invalid resources are found, they will be terminated and replaced by valid resources.

Parameters:
Interval - time in milliseconds.
Since:
0.5

getSleepTimeInMillis

public long getSleepTimeInMillis()
Gets the sleep interval time in milliseconds.

Returns:
sleep interval in milliseconds.
Since:
0.5

getPoolSize

public int getPoolSize()
Gets the number of resources allocated to pool.

Returns:
number of resources allocated to pool.
Since:
0.5

setPoolSize

public void setPoolSize(int size)
Sets the number of resources that should be allocated to the pool.

Parameters:
sleep - Number of resources allocated to pool.
Since:
0.5

getCreationProperties

public java.util.Properties getCreationProperties()
Gets the used to start resources in the pool.

Returns:
Properties used to start resources.

getPool

public static ResourcePool getPool(java.lang.String poolName)
                            throws ResourceException
Gets the singleton instance of the resource pool.

Returns:
resource pool.
Throws:
ResourceException
Since:
0.5

closeAll

public void closeAll()
Closes all resources in the pool. Note that if you have specific resources to close in addition to the pool, you should override this method.

Since:
0.5

recycleResource

public void recycleResource(Resource resource)
                     throws ResourceException
Validates and puts a resource back in the resource pool.

Specified by:
recycleResource in interface ResourcePool
Parameters:
resource. -
Throws:
ResourceException
Since:
0.5

run

public void run()
Validates idle resources in the pool, replaces them if necessary.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
Since:
0.5

getPoolName

public java.lang.String getPoolName()
                             throws ResourceException
Provides name of the resoruce pool.

Specified by:
getPoolName in interface ResourcePool
Returns:
Name of resource.
Throws:
ResourceException
Since:
0.5


Copyright © 2003 Delta Vortex Technologies, Inc. All Rights Reserved.