PooliT v2.0

org.ascentphase.poolit.poolers
Class FixedPooler

java.lang.Object
  extended byorg.ascentphase.poolit.poolers.FixedPooler
All Implemented Interfaces:
Pooler

public class FixedPooler
extends java.lang.Object
implements Pooler

This Pooler implements a fixed-sized pool. The pool is initialized to a fixed size and filled to the fixed capacity upon creation. Objects are fetched from the pool and if no more objects exist in the pool, new objects are created by calling the associated PoolHandler's create() method.

Author:
Huy Duong
See Also:
Pooler

Field Summary
protected  int availPos
          Points to the index in the pool array where the next available object can be retrieved from.
protected  PoolHandler handler
           
protected  java.lang.Object[] pool
           
 
Constructor Summary
FixedPooler(java.lang.Class name, int size)
          Creates a pool with the specified class and size.
FixedPooler(PoolHandler handler, int size)
          Creates a pool using the specified handler and size.
 
Method Summary
 int capacity()
          Reports the maximum number of objects this pool can contain.
 void close()
          Destroys all objects in the pool.
 java.lang.Object fetch()
          Retrieves an object from the pool.
protected  void fillPool()
          Called by constructor to fill up the pool.
 void release(java.lang.Object o)
          Returns an object to the pool.
 void resize(int newsize)
          Changes the size of the pool.
 int size()
          Reports the number of objects currently in the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

protected java.lang.Object[] pool

handler

protected PoolHandler handler

availPos

protected int availPos
Points to the index in the pool array where the next available object can be retrieved from.

Constructor Detail

FixedPooler

public FixedPooler(java.lang.Class name,
                   int size)
            throws CreateException
Creates a pool with the specified class and size.

Parameters:
name - class to be pooled
size - size of pool to be created

FixedPooler

public FixedPooler(PoolHandler handler,
                   int size)
            throws CreateException
Creates a pool using the specified handler and size.

Parameters:
handler - PoolHandler to be used by this pool
size - size of pool to be created
Method Detail

fetch

public java.lang.Object fetch()
                       throws FetchException
Description copied from interface: Pooler
Retrieves an object from the pool.

Specified by:
fetch in interface Pooler
Returns:
an object from the pool
Throws:
FetchException - if the pooler is unable to return an object from the pool.

release

public void release(java.lang.Object o)
Description copied from interface: Pooler
Returns an object to the pool.

Specified by:
release in interface Pooler
Parameters:
o - the object

size

public int size()
Reports the number of objects currently in the pool.

Returns:
the number of objects in the pool

capacity

public int capacity()
Reports the maximum number of objects this pool can contain.

Returns:
the capacity of the pool

resize

public void resize(int newsize)
Changes the size of the pool. If the new size is smaller than the current, the number of objects exceeding the new size will be discarded. If the new size is greater than the current, the objects currently pooled will be moved over to the new pool, but no new objects will be created to fill in the new space.

Parameters:
newsize - the new size of the pool

fillPool

protected void fillPool()
                 throws CreateException
Called by constructor to fill up the pool.

Throws:
CreateException

close

public void close()
Destroys all objects in the pool. Implicitly, the next call to the fetch() will force a call to the handler's create() method.

Specified by:
close in interface Pooler
See Also:
Pooler.close()

PooliT v2.0

Copyright © 2005 Ascent Phase Corp.