org.aitools.programd.util.sql
Class ObjectPool

java.lang.Object
  extended by org.aitools.programd.util.sql.ObjectPool
Direct Known Subclasses:
DbAccessRefsPoolMgr

public abstract class ObjectPool
extends java.lang.Object

An abstract pool of objects that can be checked in and locked, checked out and unlocked.

Author:
Cristian Mircioiu

Field Summary
private  CleanUpThread cleaner
          The thread that manages pool cleanup.
private  long expirationTime
          The time after which an object should expire.
private  java.util.Hashtable<java.lang.Object,java.lang.Long> locked
          The objects that are locked by this pool.
private  java.util.Hashtable<java.lang.Object,java.lang.Long> unlocked
          The objects that are unlocked in this pool.
 
Constructor Summary
protected ObjectPool()
          Initializes the object pool with a default expiration time of one hour.
 
Method Summary
protected  void cleanUp()
          Cleans up the pool by checking for expired objects.
protected abstract  java.lang.Object create()
          Creates a new object to store in the pool.
protected abstract  void expire(java.lang.Object object)
          Expires an object in the pool.
protected  void checkIn(java.lang.Object object)
          Checks in and unlocks an object.
protected  java.lang.Object checkOut()
          Checks out and locks the next available object in the pool.
protected abstract  boolean validate(java.lang.Object object)
          Validates an object in the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expirationTime

private long expirationTime
The time after which an object should expire.


locked

private java.util.Hashtable<java.lang.Object,java.lang.Long> locked
The objects that are locked by this pool.


unlocked

private java.util.Hashtable<java.lang.Object,java.lang.Long> unlocked
The objects that are unlocked in this pool.


cleaner

private CleanUpThread cleaner
The thread that manages pool cleanup.

Constructor Detail

ObjectPool

protected ObjectPool()
Initializes the object pool with a default expiration time of one hour.

Method Detail

checkIn

protected void checkIn(java.lang.Object object)
Checks in and unlocks an object.

Parameters:
object - the object to check in and unlock.

checkOut

protected java.lang.Object checkOut()
Checks out and locks the next available object in the pool.

Returns:
the next available object in the pool

cleanUp

protected void cleanUp()
Cleans up the pool by checking for expired objects.


create

protected abstract java.lang.Object create()
Creates a new object to store in the pool.

Returns:
the created object

expire

protected abstract void expire(java.lang.Object object)
Expires an object in the pool.

Parameters:
object - the object to expire

validate

protected abstract boolean validate(java.lang.Object object)
Validates an object in the pool.

Parameters:
object - the object to validate
Returns:
whether or not the object validates