jet.pool
Class ObjectPool

java.lang.Object
  extended by java.lang.Thread
      extended by jet.pool.ObjectPool
All Implemented Interfaces:
java.lang.Runnable

public class ObjectPool
extends java.lang.Thread

Author:
Markus.Meisters@web.de

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean continued
          Variable that indicates to stop running
private  java.util.concurrent.locks.ReentrantLock lock
           
private  int objectCount
          The count - how much object should be pooled for each given Poolable object
private  java.util.HashMap<java.lang.String,java.lang.Object> orgs
          Holds the original object from which the pooled objects were cloned
private  java.util.HashMap<java.lang.String,java.lang.Object> pool
          Holds the pooled objects
private  java.util.concurrent.locks.ReentrantLock stacklock
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ObjectPool(int objectCount)
          Creates a new instance of ObjectPool
 
Method Summary
 void add(Poolable o)
          This methods adds a new Poolable object
 void addAll(java.util.Collection c)
          This method adds all Objects from the colletion
 Poolable getCloneFromOriginalObject(java.lang.String identifier)
          Returns a clone from pooled object
 boolean getContinued()
          Returns the flag if the ObjectPoolThread should continue running.
 Poolable getInstanceFor(java.lang.String identifier)
          Returns a pooled object or a new one if pool empty
 int getObjectCount()
          Returns the count how many objects should be pooled
 java.util.HashMap getPool()
          Returns the pool
 void pushBack(Poolable o)
          This method returns the object to the pool
 void run()
          This method checks from time to time if there are too much objectspooled.
 void setContinued(boolean val)
          Sets the flag if the ObjectPoolThread should continue running.
 void setObjectCount(int objectCount)
          Sets the object count to use (TODO?
 void setPool(java.util.HashMap<java.lang.String,java.lang.Object> pool)
          Sets the internal pool
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

continued

private boolean continued
Variable that indicates to stop running


pool

private java.util.HashMap<java.lang.String,java.lang.Object> pool
Holds the pooled objects


orgs

private java.util.HashMap<java.lang.String,java.lang.Object> orgs
Holds the original object from which the pooled objects were cloned


stacklock

private java.util.concurrent.locks.ReentrantLock stacklock

lock

private java.util.concurrent.locks.ReentrantLock lock

objectCount

private int objectCount
The count - how much object should be pooled for each given Poolable object

Constructor Detail

ObjectPool

public ObjectPool(int objectCount)
Creates a new instance of ObjectPool

Parameters:
objectCount - the count how many objects should be pooled
Method Detail

run

public void run()
This method checks from time to time if there are too much objectspooled. This could happen if programmers clone the a object and return both objects

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getPool

public java.util.HashMap getPool()
Returns the pool

Returns:
HashMap the original map

setPool

public void setPool(java.util.HashMap<java.lang.String,java.lang.Object> pool)
Sets the internal pool


getObjectCount

public int getObjectCount()
Returns the count how many objects should be pooled

Returns:
int count

setObjectCount

public void setObjectCount(int objectCount)
Sets the object count to use (TODO?: currently only a max boundary!)

Parameters:
objectCount - the count

add

public void add(Poolable o)
This methods adds a new Poolable object

Parameters:
o - the object to pool

pushBack

public void pushBack(Poolable o)
This method returns the object to the pool

Parameters:
o - object to return

addAll

public void addAll(java.util.Collection c)
            throws java.lang.CloneNotSupportedException
This method adds all Objects from the colletion

Parameters:
c - collection to add objects from
Throws:
java.lang.CloneNotSupportedException

getInstanceFor

public Poolable getInstanceFor(java.lang.String identifier)
Returns a pooled object or a new one if pool empty

Parameters:
identifier - the identifierer
Returns:
Poolable the object from pool

getCloneFromOriginalObject

public Poolable getCloneFromOriginalObject(java.lang.String identifier)
Returns a clone from pooled object

Parameters:
identifier - the identifierer
Returns:
Poolable the object cloned

getContinued

public boolean getContinued()
Returns the flag if the ObjectPoolThread should continue running. Needed for undeploy of the servlet

Returns:
boolean

setContinued

public void setContinued(boolean val)
Sets the flag if the ObjectPoolThread should continue running. Needed for undeploy of the servlet

Parameters:
val -