com.sapportals.portal.prt.util
Class AbstractPool

java.lang.Object
  |
  +--com.sapportals.portal.prt.util.AbstractPool
Direct Known Subclasses:
StringBufferPool

public abstract class AbstractPool
extends java.lang.Object

Manages a pool of objects. Unused objects are removed after a certain period of time. The maximum number of objects managed by the pool is by default 100.
This property can be overriden when constructing the pool

Version:
$Revision: #3 $
$File:$ , $Revision:$ Last modified on $Date:$ by $Author:$ using $Change:$ Copyright (c) SAP Portals Europe GmbH 2001

Field Summary
protected  int mm_maxPoolSize
           
protected  java.util.List mm_unlocked
          Contains pool objects that are available for use
 
Constructor Summary
AbstractPool(int initialCapacity)
          Construct a pool given an initial capacity and the maximum number set to 100 to manage
AbstractPool(int initialCapacity, int nbInitialInstance)
          Construct a pool given an initial capacity and the number of initial items to manage
AbstractPool(int initialCapacity, int nbInitialInstance, int maxNumberObjects)
          Construct a pool given an initial capacity and the maximum number of items to manage
 
Method Summary
protected abstract  java.lang.Object createPoolObject()
          Factory method to create pool objects
protected abstract  void expirePoolObject(java.lang.Object o)
          Callback when object are not managed anymore by the pool.
 java.lang.Object getPoolObject()
          Returns an object from the pool.
If no object was available, the object factory is called to instantiate an object
 void releasePoolObject(java.lang.Object o)
          Tells the pool to release an object and make it available in the pool.
protected abstract  boolean validatePoolObject(java.lang.Object o)
          Method called to validate an object that has been put back in the pool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mm_maxPoolSize

protected int mm_maxPoolSize

mm_unlocked

protected java.util.List mm_unlocked
Contains pool objects that are available for use
Constructor Detail

AbstractPool

public AbstractPool(int initialCapacity)
Construct a pool given an initial capacity and the maximum number set to 100 to manage
Parameters:
initialCapacity - the initial container capacity

AbstractPool

public AbstractPool(int initialCapacity,
                    int nbInitialInstance)
Construct a pool given an initial capacity and the number of initial items to manage
Parameters:
initialCapacity - the initial container capacity. You should here choose a value that is as close as the given maxNumberObjects.
nbInitialInstance - the initial number of objects to manage in the pool

AbstractPool

public AbstractPool(int initialCapacity,
                    int nbInitialInstance,
                    int maxNumberObjects)
Construct a pool given an initial capacity and the maximum number of items to manage
Parameters:
initialCapacity - the initial container capacity. You should here choose a value that is as close as the given maxNumberObjects.
nbInitialInstance - the initial number of objects to manage in the pool
maxNumberObjects - the maximum number of objects to manage in the pool. value -1 means infinite.
Method Detail

createPoolObject

protected abstract java.lang.Object createPoolObject()
                                              throws java.lang.Exception
Factory method to create pool objects
Returns:
the object to be pooled
Throws:
java.lang.Exception -  

validatePoolObject

protected abstract boolean validatePoolObject(java.lang.Object o)
Method called to validate an object that has been put back in the pool
Parameters:
o - the object to validate
Returns:
true is the object is valid for reuse.

expirePoolObject

protected abstract void expirePoolObject(java.lang.Object o)
Callback when object are not managed anymore by the pool.
Parameters:
o - the object that is to be expired

getPoolObject

public java.lang.Object getPoolObject()
                               throws java.lang.Exception
Returns an object from the pool.
If no object was available, the object factory is called to instantiate an object
Returns:
an object coming form the pool, either newly created or and old valid one.
Throws:
java.lang.Exception -  

releasePoolObject

public void releasePoolObject(java.lang.Object o)
Tells the pool to release an object and make it available in the pool. If the maximum number of pool objects is reached, the object is not managed anymore by the pool.
Parameters:
o - the object to release.