net.sourceforge.idrs.utils.pool
Class ObjectPool

java.lang.Object
  |
  +--net.sourceforge.idrs.utils.pool.ObjectPool
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
IDRSPool, JDBCPool

public abstract class ObjectPool
extends java.lang.Object
implements java.io.Serializable

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

See Also:
GenericPool, JDBCPool, Serialized Form

Field Summary
protected  int count
           
protected  long daysOpen
           
protected  boolean debug
           
protected static long DEFAULT_DAYS_OPEN
           
static long DEFAULT_EXPIRATION
           
protected static int DEFAULT_MIN_POOLSIZE
           
protected static java.lang.String DEFAULT_PATH
           
static long DEFAULT_SLEEPTIME
           
static long DEFAULT_TIMEOUT
           
protected static int DEFAULT_TRYS
           
protected  int limit
           
protected  java.lang.String logPath
           
static int MAX_POOLSIZE
           
protected  int maxTrys
           
protected  int minn
           
protected  java.io.PrintStream out
           
protected  PooledObject[] pool
           
protected  long sleepTime
           
 
Constructor Summary
ObjectPool()
          Creates an ObjectPool with the default params.
ObjectPool(int objectMin, int objectLimit, long daysOpen, long sleepTime, java.lang.String path, int trys)
          Create an instance of ObjectPool
ObjectPool(long daysOpen, long sleepTime)
          Create an ObjectPool with no object count limit.
 
Method Summary
protected  void checkIn(java.lang.Object obj)
          Checks an object back into the pool.
 void checkIn(java.lang.String DBName)
           
 java.lang.Object checkOut(int num)
          Checkout cycles through the available objects and returns the first valid object it finds.
protected abstract  PooledObject create()
           
protected abstract  void expire(PooledObject obj)
           
protected  int getConnID(java.lang.Object obj)
           
 boolean isDebugging()
           
protected abstract  void logHeader()
           
protected abstract  void reset(int index)
           
 void setDebugging(boolean b)
           
protected  boolean shouldReset(int index)
           
protected abstract  boolean validate(PooledObject obj)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.PrintStream out

maxTrys

protected int maxTrys

daysOpen

protected long daysOpen

sleepTime

protected long sleepTime

DEFAULT_PATH

protected static final java.lang.String DEFAULT_PATH

DEFAULT_TRYS

protected static final int DEFAULT_TRYS

DEFAULT_DAYS_OPEN

protected static final long DEFAULT_DAYS_OPEN

DEFAULT_MIN_POOLSIZE

protected static final int DEFAULT_MIN_POOLSIZE

logPath

protected java.lang.String logPath

minn

protected int minn

pool

protected PooledObject[] pool

limit

protected int limit

count

protected int count

debug

protected boolean debug

DEFAULT_EXPIRATION

public static final long DEFAULT_EXPIRATION

DEFAULT_SLEEPTIME

public static final long DEFAULT_SLEEPTIME

MAX_POOLSIZE

public static final int MAX_POOLSIZE

DEFAULT_TIMEOUT

public static final long DEFAULT_TIMEOUT
Constructor Detail

ObjectPool

public ObjectPool()
           throws java.lang.Exception
Creates an ObjectPool with the default params.

ObjectPool

public ObjectPool(long daysOpen,
                  long sleepTime)
           throws java.lang.Exception
Create an ObjectPool with no object count limit.

ObjectPool

public ObjectPool(int objectMin,
                  int objectLimit,
                  long daysOpen,
                  long sleepTime,
                  java.lang.String path,
                  int trys)
           throws java.lang.Exception
Create an instance of ObjectPool
Parameters:
expirationTime - is the time in milliseconds that each object has to live.
objectLimit - is the total number of objects that are allowed in the pool at any time. If objectLimit is equal to or less than 0, it is assumed that the limit is Integer.MAX_VALUE
sleepTime - is the time in miliseconds that the pool skimming thread sleeps between 'reap' cycles
Method Detail

isDebugging

public boolean isDebugging()

setDebugging

public void setDebugging(boolean b)

logHeader

protected abstract void logHeader()
                           throws java.lang.Exception

create

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

validate

protected abstract boolean validate(PooledObject obj)

expire

protected abstract void expire(PooledObject obj)

checkOut

public java.lang.Object checkOut(int num)
                          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

getConnID

protected int getConnID(java.lang.Object obj)

checkIn

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

checkIn

public void checkIn(java.lang.String DBName)
             throws java.lang.Exception

shouldReset

protected boolean shouldReset(int index)

reset

protected abstract void reset(int index)