com.xavax.xstore.util
Class AbstractPool

Object
  extended byAbstractPool
All Implemented Interfaces:
Pool

public abstract class AbstractPool
extends Object
implements Pool

AbstractPool implements the Pool interface and serves as an abstract base class for all resource pools. A derived class should override the createResource and deleteResource methods.


Constructor Summary
AbstractPool(int size)
          Construct a AbstractPool of the specified size.
 
Method Summary
 boolean active()
          Returns true if this pool is active.
 Object allocate(boolean waitFlag)
          Allocate a resource from the pool.
 int available()
          Return the number of available resources.
 void release(Object o)
          Release a resource and return it to the pool.
 void start()
          Start allocating resources.
 String statistics()
           
 void stop()
          Stop allocating resources and release all resources in the pool.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPool

public AbstractPool(int size)
Construct a AbstractPool of the specified size.

Parameters:
size - the maximum size of the pool.
Method Detail

active

public boolean active()
Returns true if this pool is active. An inactive pool will refuse allocate a resource regardless of whether resources are available.

Specified by:
active in interface Pool
Returns:
true if this pool is active.

allocate

public Object allocate(boolean waitFlag)
                          throws PoolException
Allocate a resource from the pool. If no resources are available, and the pool is already at maximum size and waitFlag is true, then wait until a resource is available; otherwise return null.

Specified by:
allocate in interface Pool
Parameters:
waitFlag - true if method should wait for an available resource.
Returns:
a resource, or null if not are available.
Throws:
PoolException

available

public int available()
Return the number of available resources.

Specified by:
available in interface Pool
Returns:
the number of available resources.

release

public void release(Object o)
Release a resource and return it to the pool.

Specified by:
release in interface Pool
Parameters:
o - the resource to be released.

start

public void start()
Start allocating resources.

Specified by:
start in interface Pool

stop

public void stop()
Stop allocating resources and release all resources in the pool.

Specified by:
stop in interface Pool

statistics

public String statistics()