org.d_haven.mpool

Interface Pool

public interface Pool

This interface is to define how a Pool is used. We have determined by using the previous Pool implementations that the Pool marker interface is considered harmful. When generics are introduced in JDK 1.5, this interface will be a prime candidate for those improvements.

It is important to realize that some objects are cheaper to simply allow the garbage collector to take care of them. Therefore, only pool objects that are computationally expensive to create. Prime candidates would be Components, JDBC Connection objects, Socket connections, etc.

The interface is inspired by both the Mutex acquire/release and the structure of the ThreadLocal object. In fact, it would be trivial to implement a "ThreadLocal" pool.

Version: CVS $Revision: 1.4 $ $Date: 2004/06/21 17:03:46 $

Author: Berin Loritsch

Method Summary
Objectacquire()
Acquire an instance of the pooled object.
voidaddPoolListener(PoolListener listener)
Add a pool listener to the pool.
voidrelease(Object pooledObject)
Release the instance of the pooled object.
voidremovePoolListener(PoolListener listener)
Remove a pool listener from the pool.

Method Detail

acquire

public Object acquire()
Acquire an instance of the pooled object.

Returns: the pooled Object instance

Throws: Exception if the Pool is not able to return an object.

addPoolListener

public void addPoolListener(PoolListener listener)
Add a pool listener to the pool. If you add a listener twice it will be notified twice and you will have to remove it twice.

Parameters: listener the listener to add.

release

public void release(Object pooledObject)
Release the instance of the pooled object.

Parameters: pooledObject The pooled object to release to the pool.

removePoolListener

public void removePoolListener(PoolListener listener)
Remove a pool listener from the pool. If you add a listener twice it will be notified twice and you will have to remove it twice.

Parameters: listener the listener to remove