com.codestudio.util
Class ObjectPool

java.lang.Object
  |
  +--com.codestudio.util.ObjectPool
All Implemented Interfaces:
Pool, java.io.Serializable
Direct Known Subclasses:
GenericPool, JDBCPool

public abstract class ObjectPool
extends java.lang.Object
implements Pool

ObjectPool provides a mechanism for pooling objects and resources. It must be subclassed to create specific pools; GenericPool and JDBCPool are examples of such subclasses.

See Also:
GenericPool, JDBCPool, Serialized Form

Field Summary
protected  int count
           
protected  java.lang.Thread lifeguard
           
protected  java.util.Hashtable locked
           
protected  org.apache.log4j.Category logit
          Log4j handle
protected  PoolMetaData metadata
           
protected  java.lang.Thread skimmer
           
protected  java.util.Hashtable unlocked
           
 
Constructor Summary
ObjectPool(PoolMetaData metad)
           
 
Method Summary
protected  void checkIn(java.lang.Object o)
          Checks an object back into the pool.
protected  java.lang.Object checkOut()
          Checkout cycles through the available objects and returns the first valid object it finds.
protected  void checkTimeout()
          Determine whether locked objects have timed out and should be checked back in.
protected  void cleanUp()
          Remove timed-out objects from the pool, called by PoolSkimmerThread.
 void closeAllResources()
          Close all resources in the pool.
protected abstract  java.lang.Object create()
           
 void debug(java.lang.String message)
           
 void debug(java.lang.String message, java.lang.Exception e)
           
protected  void debugMetrics()
           
protected  void expire(java.lang.Object o)
          Default expiration invokes PooledObject.closeAllResources()
 void finalize()
           
 java.lang.String getPoolname()
           
 void init()
           
 void log(java.lang.String message)
           
 void log(java.lang.String message, java.lang.Exception e)
           
 int numCheckedInObjects()
           
 int numCheckedOutObjects()
           
 int numTotalObjects()
           
 java.lang.Object requestObject()
          Subclasses will usually want to override this method.
 void returnObject(java.lang.Object o)
          Subclasses will usually want to override this method, at least for type safety.
 void updateLocked(PooledObject o)
           
protected abstract  boolean validate(java.lang.Object o)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

metadata

protected PoolMetaData metadata

count

protected int count

locked

protected java.util.Hashtable locked

unlocked

protected java.util.Hashtable unlocked

skimmer

protected java.lang.Thread skimmer

lifeguard

protected java.lang.Thread lifeguard

logit

protected org.apache.log4j.Category logit
Log4j handle
Constructor Detail

ObjectPool

public ObjectPool(PoolMetaData metad)
Method Detail

init

public void init()
          throws java.lang.Exception

create

protected abstract java.lang.Object create()
                                    throws java.lang.Exception

validate

protected abstract boolean validate(java.lang.Object o)

expire

protected void expire(java.lang.Object o)
Default expiration invokes PooledObject.closeAllResources()

getPoolname

public java.lang.String getPoolname()
Specified by:
getPoolname in interface Pool

requestObject

public java.lang.Object requestObject()
Subclasses will usually want to override this method.
Specified by:
requestObject in interface Pool

returnObject

public void returnObject(java.lang.Object o)
Subclasses will usually want to override this method, at least for type safety.
Specified by:
returnObject in interface Pool

numTotalObjects

public int numTotalObjects()
Returns:
int The total number of objects in the pool, both locked and unlocked.

numCheckedOutObjects

public int numCheckedOutObjects()
Returns:
int The number of objects currently available.

numCheckedInObjects

public int numCheckedInObjects()
Returns:
int The number of objects currently checked out.

checkOut

protected java.lang.Object checkOut()
                             throws java.lang.Exception
Checkout cycles through the available objects and returns the first valid object it finds. if there are no valid objects, checkOut will create one, unless the client specified amount of objects have already been created, and then it will block until it finds an appropriate object

checkIn

protected void checkIn(java.lang.Object o)
Checks an object back into the pool.

updateLocked

public void updateLocked(PooledObject o)

cleanUp

protected void cleanUp()
Remove timed-out objects from the pool, called by PoolSkimmerThread. Checks the unlocked objects for expired members, and shrinks the pool according to the shrinkBy value, ensuring that it keeps at least the minimumSize number of objects available.

checkTimeout

protected void checkTimeout()
Determine whether locked objects have timed out and should be checked back in. Called by LifeGuardThread.

closeAllResources

public void closeAllResources()
Close all resources in the pool.

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

log

public void log(java.lang.String message)

log

public void log(java.lang.String message,
                java.lang.Exception e)

debug

public void debug(java.lang.String message)

debug

public void debug(java.lang.String message,
                  java.lang.Exception e)

debugMetrics

protected void debugMetrics()


Copyright © 1999-2001 The Code Studio. All Rights Reserved.