com.atomikos.util
Class BaseObjectPool

java.lang.Object
  extended by com.atomikos.util.BaseObjectPool
All Implemented Interfaces:
ObjectPool
Direct Known Subclasses:
LRUPool

public abstract class BaseObjectPool
extends Object
implements ObjectPool

Copyright © 2001, Atomikos. All rights reserved. A general implementation of an object pool.


Field Summary
protected  long maxSize_
           
protected  Hashtable pool_
           
protected  long size_
           
 
Constructor Summary
BaseObjectPool(long maxSize)
          Constructor.
 
Method Summary
 Identifiable add(Identifiable object)
          Add an identifiable instance to the pool.
 Enumeration elements()
          Retrieve an enummeration of all elements in the pool.
 long getMaxSize()
          Get the maximum size of the pool.
 long getSize()
          Get the current size of the pool.
protected abstract  Object getVictim()
          Get a victim for removal if pool is full.
protected  Enumeration internalElements()
          Returns an enummeration of PooledObject instances for use in subclasses.
 boolean isEmpty()
          Test if pool is empty.
 boolean isFull()
          Test if pool is full.
 Identifiable remove()
          Remove an arbitrary element from the pool.
 Identifiable remove(Object id)
          Remove an object from the pool.
 Identifiable retrieve()
          Get an arbitrary element from the pool.
 Identifiable retrieve(Object id)
          Retrieve an object from the pool.
protected abstract  PooledObject wrap(Identifiable object)
          Wrap an instance into a pool handle object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool_

protected Hashtable pool_

size_

protected long size_

maxSize_

protected long maxSize_
Constructor Detail

BaseObjectPool

public BaseObjectPool(long maxSize)
Constructor.

Parameters:
maxSize - The max size of the pool. If negative or zero, a default size will be taken.
Method Detail

getSize

public long getSize()
Description copied from interface: ObjectPool
Get the current size of the pool.

Specified by:
getSize in interface ObjectPool
Returns:
long The current size.
See Also:
ObjectPool

getMaxSize

public long getMaxSize()
Description copied from interface: ObjectPool
Get the maximum size of the pool.

Specified by:
getMaxSize in interface ObjectPool
Returns:
long The max size.
See Also:
ObjectPool

isFull

public boolean isFull()
Description copied from interface: ObjectPool
Test if pool is full.

Specified by:
isFull in interface ObjectPool
Returns:
boolean True iff pool is full.
See Also:
ObjectPool

isEmpty

public boolean isEmpty()
Description copied from interface: ObjectPool
Test if pool is empty.

Specified by:
isEmpty in interface ObjectPool
Returns:
boolean True iff pool is empty.
See Also:
ObjectPool

add

public Identifiable add(Identifiable object)
Description copied from interface: ObjectPool
Add an identifiable instance to the pool. If the pool is full at its maximum, this method will return a victim that is thrown out of the pool. It is up to the client to treat those cases appropriately.

Specified by:
add in interface ObjectPool
Returns:
Identifiable The object thrown out, or null if none.
See Also:
ObjectPool

retrieve

public Identifiable retrieve(Object id)
                      throws ObjectNotFoundException
Description copied from interface: ObjectPool
Retrieve an object from the pool.

Specified by:
retrieve in interface ObjectPool
Parameters:
id - The id of the object wanted.
Returns:
Identifiable The instance wanted.
Throws:
ObjectNotFoundException - If not found.
See Also:
ObjectPool

retrieve

public Identifiable retrieve()
                      throws ObjectNotFoundException
Description copied from interface: ObjectPool
Get an arbitrary element from the pool.

Specified by:
retrieve in interface ObjectPool
Returns:
Identifiable The selected element.
Throws:
ObjectNotFoundException - If empty.
See Also:
ObjectPool

remove

public Identifiable remove()
                    throws ObjectNotFoundException
Description copied from interface: ObjectPool
Remove an arbitrary element from the pool.

Specified by:
remove in interface ObjectPool
Returns:
Identifiable The removed element.
Throws:
ObjectNotFoundException - If empty.
See Also:
ObjectPool

remove

public Identifiable remove(Object id)
                    throws ObjectNotFoundException
Description copied from interface: ObjectPool
Remove an object from the pool.

Specified by:
remove in interface ObjectPool
Parameters:
id - The identifier for the object.
Returns:
Identifiable The object removed.
Throws:
ObjectNotFoundException - If the id was not in the pool.
See Also:
ObjectPool

elements

public Enumeration elements()
                     throws ObjectNotFoundException
Description copied from interface: ObjectPool
Retrieve an enummeration of all elements in the pool.

Specified by:
elements in interface ObjectPool
Returns:
Enumeration All elements.
Throws:
ObjectNotFoundException - If empty.
See Also:
ObjectPool

internalElements

protected Enumeration internalElements()
Returns an enummeration of PooledObject instances for use in subclasses.

Returns:
Enumeration PooledOjbect instances.

getVictim

protected abstract Object getVictim()
Get a victim for removal if pool is full.

Returns:
Object The id of the victim.

wrap

protected abstract PooledObject wrap(Identifiable object)
Wrap an instance into a pool handle object.

Parameters:
object - The instance.
Returns:
PooledObject The pool handle.