PooliT v2.0

org.ascentphase.poolit.poolers
Class TimeoutPooler

java.lang.Object
  extended byorg.ascentphase.poolit.poolers.TimeoutPooler
All Implemented Interfaces:
Pooler

public class TimeoutPooler
extends java.lang.Object
implements Pooler

This Pooler will keep objects in its pool for a specified amount of time. When an object is put into the pool, it is marked with the time it is inserted. If the object stays in the pool longer than a specified period, it will be removed from the pool. A separate daemon thread is created with the pool which will periodic scan through the objects in the pool to see if there time there has exceed the limit. If there are no objects left in the pool and a fetch() is called, the pool will call the associated PoolHandler to create a new object.

Author:
Huy Duong

Field Summary
protected  org.ascentphase.poolit.poolers.TimeoutPooler.Cleanup cleaner
           
protected  PoolHandler handler
           
 
Constructor Summary
TimeoutPooler(java.lang.Class name, int size, long timeout, long interval)
          Creates a TimeoutPooler for the specified class and size.
TimeoutPooler(PoolHandler handler, int size, long timeout, long interval)
          Creates a TimeoutPooler with the specified Handler and size.
 
Method Summary
 void cleanup()
          Examines each object to see if any of them needs to be removed because there time limit has exceeded.
 void close()
          Releases all objects in the pool and any resources held by these objects.
 java.lang.Object fetch()
          Retrieves an object from the pool.
protected  void fillPool(int size)
          Called by the constructor to fill the pool to the size specified.
 long getCleanupInterval()
           
 long getTimeout()
          Returns the amount of time (in msec.) that an object is allowed to remain unused in the pool before it is removed.
 void release(java.lang.Object o)
          Returns an object to the pool.
 void setCleanupInterval(long cleanupInterval)
           
 void setTimeout(long time)
          Sets the amount of time (in msec.) that an object is allowed to remain unused in the pool before it is removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handler

protected PoolHandler handler

cleaner

protected org.ascentphase.poolit.poolers.TimeoutPooler.Cleanup cleaner
Constructor Detail

TimeoutPooler

public TimeoutPooler(java.lang.Class name,
                     int size,
                     long timeout,
                     long interval)
              throws CreateException
Creates a TimeoutPooler for the specified class and size. The NoArgHandler will be used, therefore the class must have a "no-arg" constructor.

Parameters:
name - the class to be pooled
size - the initial size of the pool
timeout - the time the object will stay in the pool (in msec.)
interval - the interval which the cleanup thread is run (in msec.)

TimeoutPooler

public TimeoutPooler(PoolHandler handler,
                     int size,
                     long timeout,
                     long interval)
              throws CreateException
Creates a TimeoutPooler with the specified Handler and size.

Parameters:
handler - the Handler this pool will use
size - the initial size of the pool
timeout - the time the object will stay in the pool (in msec.)
interval - the interval which the cleanup thread is run (in msec.)
Method Detail

fetch

public java.lang.Object fetch()
                       throws FetchException
Description copied from interface: Pooler
Retrieves an object from the pool.

Specified by:
fetch in interface Pooler
Returns:
an object from the pool
Throws:
FetchException - if the pooler is unable to return an object from the pool.

release

public void release(java.lang.Object o)
Description copied from interface: Pooler
Returns an object to the pool.

Specified by:
release in interface Pooler
Parameters:
o - the object

cleanup

public void cleanup()
Examines each object to see if any of them needs to be removed because there time limit has exceeded.


fillPool

protected void fillPool(int size)
                 throws CreateException
Called by the constructor to fill the pool to the size specified.

Parameters:
size - number of objects to create
Throws:
CreateException

getTimeout

public long getTimeout()
Returns the amount of time (in msec.) that an object is allowed to remain unused in the pool before it is removed.

Returns:
the timeout value.

setTimeout

public void setTimeout(long time)
Sets the amount of time (in msec.) that an object is allowed to remain unused in the pool before it is removed.

Parameters:
time -

close

public void close()
Description copied from interface: Pooler
Releases all objects in the pool and any resources held by these objects.

Specified by:
close in interface Pooler
See Also:
Pooler.close()

getCleanupInterval

public long getCleanupInterval()
Returns:
the time interval (in msec.) which the cleanup scans the pool for stale objects.

setCleanupInterval

public void setCleanupInterval(long cleanupInterval)
Parameters:
cleanupInterval -

PooliT v2.0

Copyright © 2005 Ascent Phase Corp.