nl.knowledgeplaza.util.pool
Class BaseObjectPool<T>

java.lang.Object
  extended by nl.knowledgeplaza.util.pool.BaseObjectPool<T>
All Implemented Interfaces:
ObjectPool<T>
Direct Known Subclasses:
PriorityObjectPool, RoundRobinObjectPool, StackObjectPool

public abstract class BaseObjectPool<T>
extends Object
implements ObjectPool<T>

This class implements basic object pool logic. It can be placed into synchronized mode. In unsynchronized mode the implementations tries to keep the synchronisation code to a minimum to enable faster execution. In synchronized mode, all code is executed synchronized.

Version:
$Revision: 1.3 $
Author:
$Author: toeukpap $
See Also:

Nested Class Summary
static class BaseObjectPool.NotFromThisPoolException
           
static class BaseObjectPool.TimeOutException
           
 
Field Summary
protected  boolean iClose
           
protected  List<String> iListOfHandedOutObjects
           
protected  List<String> iListOfHandedOutObjectsSync
           
protected  boolean iShuttingDown
           
protected  boolean iSynchronized
           
protected  boolean itestOnBorrow
           
static int MAINTENANCE_PERIOD
           
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
static byte WHEN_EXHAUSTED_BLOCK
           
static byte WHEN_EXHAUSTED_FAIL
           
 
Constructor Summary
BaseObjectPool(org.apache.log4j.Logger log4j)
          Initialize
BaseObjectPool(PoolableObjectFactory<T> pPoolableObjectFactory, org.apache.log4j.Logger log4j)
          Initialize
 
Method Summary
 void addObject()
           
 T borrowObject()
           
 void clear()
           
 void close()
          close
protected  void factoryActivateObject(T object)
           
protected  void factoryDestroyObject(T object)
           
protected  T factoryMakeObject()
           
protected  void factoryPassivateObject(T object)
           
protected  void factoryValidateObject(T object)
           
 void fill(Collection<T> collection)
          Initialize
 PoolableObjectFactory<T> getFactory()
          PoolableObjectFactory
 int getMaxActive()
          MaxActive
 int getMaxIdle()
          MaxIdle
 int getMaxWait()
          MaxWait
 String getName()
          Name
 String getNameDescription()
           
 int getNumActive()
           
 int getNumberOfObjectsScheduledForDestruction()
          number of objects scheduled for destruction
 int getNumIdle()
           
protected  Collection<T> getPooledObjects()
          this method bolts synchronization onto the implementation
protected abstract  Collection<T> getPooledObjectsImpl()
          this method allows read only access to the collection of handed out objects, used by the generic algorithm
 boolean getTestOnBorrow()
           
 byte getWhenExhaustedAction()
          WhenExhaustedAction
 void invalidateObject(T object)
           
 boolean isClosed()
           
 boolean isShuttingDown()
           
 boolean isSynchronized()
           
protected  void maintenance()
          perform maintenance on me
protected  T obtainPooledObject()
          this method bolts synchronization onto the implementation
protected abstract  T obtainPooledObjectImpl()
          this method obtains a pooled object, the implementation determines the behaviour (LIFO, FIFO, etc)
 void returnObject(T object)
           
protected  void returnPooledObject(T o)
          this method bolts synchronization onto the implementation
protected abstract  void returnPooledObjectImpl(T o)
          this method returns a pooled object, the implementation determines the behaviour (LIFO, FIFO, etc)
 void setFactory(PoolableObjectFactory<T> value)
           
 void setMaxActive(int value)
           
 void setMaxIdle(int value)
           
 void setMaxWait(int value)
           
protected  void setName(String value)
           
 void setSynchronized(boolean value)
          Synchronized
 void setTestOnBorrow(boolean value)
          testOnBorrow
 void setWhenExhaustedAction(byte value)
           
 void shutdown()
          shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

iListOfHandedOutObjects

protected List<String> iListOfHandedOutObjects

iListOfHandedOutObjectsSync

protected List<String> iListOfHandedOutObjectsSync

iShuttingDown

protected boolean iShuttingDown

iSynchronized

protected boolean iSynchronized

iClose

protected boolean iClose

itestOnBorrow

protected boolean itestOnBorrow

WHEN_EXHAUSTED_FAIL

public static final byte WHEN_EXHAUSTED_FAIL
See Also:
Constant Field Values

WHEN_EXHAUSTED_BLOCK

public static final byte WHEN_EXHAUSTED_BLOCK
See Also:
Constant Field Values

MAINTENANCE_PERIOD

public static final int MAINTENANCE_PERIOD
See Also:
Constant Field Values
Constructor Detail

BaseObjectPool

public BaseObjectPool(org.apache.log4j.Logger log4j)
Initialize


BaseObjectPool

public BaseObjectPool(PoolableObjectFactory<T> pPoolableObjectFactory,
                      org.apache.log4j.Logger log4j)
Initialize

Method Detail

getPooledObjectsImpl

protected abstract Collection<T> getPooledObjectsImpl()
this method allows read only access to the collection of handed out objects, used by the generic algorithm


obtainPooledObjectImpl

protected abstract T obtainPooledObjectImpl()
this method obtains a pooled object, the implementation determines the behaviour (LIFO, FIFO, etc)


returnPooledObjectImpl

protected abstract void returnPooledObjectImpl(T o)
this method returns a pooled object, the implementation determines the behaviour (LIFO, FIFO, etc)


getPooledObjects

protected Collection<T> getPooledObjects()
this method bolts synchronization onto the implementation


obtainPooledObject

protected T obtainPooledObject()
this method bolts synchronization onto the implementation


returnPooledObject

protected void returnPooledObject(T o)
this method bolts synchronization onto the implementation


getFactory

public PoolableObjectFactory<T> getFactory()
PoolableObjectFactory


setFactory

public void setFactory(PoolableObjectFactory<T> value)
Specified by:
setFactory in interface ObjectPool<T>

shutdown

public void shutdown()
shutdown

Specified by:
shutdown in interface ObjectPool<T>

isShuttingDown

public boolean isShuttingDown()

setSynchronized

public void setSynchronized(boolean value)
Synchronized

Specified by:
setSynchronized in interface ObjectPool<T>

isSynchronized

public boolean isSynchronized()
Specified by:
isSynchronized in interface ObjectPool<T>

close

public void close()
close

Specified by:
close in interface ObjectPool<T>

isClosed

public boolean isClosed()

getMaxWait

public int getMaxWait()
MaxWait


setMaxWait

public void setMaxWait(int value)

getMaxActive

public int getMaxActive()
MaxActive


setMaxActive

public void setMaxActive(int value)

getMaxIdle

public int getMaxIdle()
MaxIdle


setMaxIdle

public void setMaxIdle(int value)

setTestOnBorrow

public void setTestOnBorrow(boolean value)
testOnBorrow


getTestOnBorrow

public boolean getTestOnBorrow()

getWhenExhaustedAction

public byte getWhenExhaustedAction()
WhenExhaustedAction


setWhenExhaustedAction

public void setWhenExhaustedAction(byte value)

getName

public String getName()
Name


setName

protected void setName(String value)

getNameDescription

public String getNameDescription()

getNumberOfObjectsScheduledForDestruction

public int getNumberOfObjectsScheduledForDestruction()
number of objects scheduled for destruction


borrowObject

public T borrowObject()
Specified by:
borrowObject in interface ObjectPool<T>

returnObject

public void returnObject(T object)
Specified by:
returnObject in interface ObjectPool<T>

invalidateObject

public void invalidateObject(T object)
Specified by:
invalidateObject in interface ObjectPool<T>

getNumActive

public int getNumActive()
                 throws UnsupportedOperationException
Specified by:
getNumActive in interface ObjectPool<T>
Throws:
UnsupportedOperationException

getNumIdle

public int getNumIdle()
               throws UnsupportedOperationException
Specified by:
getNumIdle in interface ObjectPool<T>
Throws:
UnsupportedOperationException

addObject

public void addObject()
Specified by:
addObject in interface ObjectPool<T>

clear

public void clear()
           throws UnsupportedOperationException
Specified by:
clear in interface ObjectPool<T>
Throws:
UnsupportedOperationException

fill

public void fill(Collection<T> collection)
Initialize


factoryMakeObject

protected T factoryMakeObject()
Returns:

factoryActivateObject

protected void factoryActivateObject(T object)

factoryValidateObject

protected void factoryValidateObject(T object)

factoryPassivateObject

protected void factoryPassivateObject(T object)

factoryDestroyObject

protected void factoryDestroyObject(T object)

maintenance

protected void maintenance()
perform maintenance on me



Copyright © 2011 KnowledgePlaza. All Rights Reserved.