org.apache.excalibur.mpool
Class VariableSizePool

java.lang.Object
  |
  +--org.apache.excalibur.mpool.VariableSizePool
All Implemented Interfaces:
Disposable, ManagablePool, Pool

public final class VariableSizePool
extends Object
implements Pool, Disposable, ManagablePool

This is an Pool that caches Poolable objects for reuse. Please note that this pool offers no resource limiting whatsoever.

Since:
4.1
Version:
CVS $Revision: 1.12 $ $Date: 2003/03/22 12:46:28 $
Author:
Berin Loritsch

Constructor Summary
VariableSizePool(ObjectFactory factory, int size)
          Constructor for an unmanaged pool
VariableSizePool(ObjectFactory factory, int size, long key)
          Constructor for a managed pool
 
Method Summary
 Object acquire()
          Acquire an instance of the pooled object.
 void dispose()
           
 void grow(int byNum, long key)
          Grow by the specified amount.
 Object newInstance()
          Create a new instance of the object being pooled.
 void release(Object pooledObject)
          Release the instance of the pooled object.
 void shrink(int byNum, long key)
          Shrink the pool by the specified amount.
 int size(long key)
          Determine the pool's current size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableSizePool

public VariableSizePool(ObjectFactory factory,
                        int size)
                 throws Exception
Constructor for an unmanaged pool


VariableSizePool

public VariableSizePool(ObjectFactory factory,
                        int size,
                        long key)
                 throws Exception
Constructor for a managed pool

Method Detail

acquire

public Object acquire()
               throws Exception
Description copied from interface: Pool
Acquire an instance of the pooled object.

Specified by:
acquire in interface Pool
Returns:
the pooled Object instance
Throws:
Exception - if the Pool is not able to return an object.

release

public void release(Object pooledObject)
Description copied from interface: Pool
Release the instance of the pooled object.

Specified by:
release in interface Pool
Parameters:
pooledObject - The pooled object to release to the pool.

newInstance

public Object newInstance()
                   throws Exception
Description copied from interface: Pool
Create a new instance of the object being pooled.

Specified by:
newInstance in interface Pool
Returns:
the pooled Object instance
Throws:
Exception - if the instance cannot be created

dispose

public void dispose()
Specified by:
dispose in interface Disposable

shrink

public void shrink(int byNum,
                   long key)
            throws IllegalAccessException
Description copied from interface: ManagablePool
Shrink the pool by the specified amount. The pool should trust the Controller, but be smart enough not to achieve a negative pool size. In other words, you should clip the shrink amount so that the pool does not go below 0.

Specified by:
shrink in interface ManagablePool
Parameters:
byNum - an integer amount to decrease the pool size by.
key - an integer number supplied by the PoolManager to validate that the method is called legitimately
Throws:
IllegalAccessException - if the key does not match the controller's key.

grow

public void grow(int byNum,
                 long key)
          throws IllegalAccessException
Description copied from interface: ManagablePool
Grow by the specified amount. The pool should trust the Controller for the Grow size.

Specified by:
grow in interface ManagablePool
Parameters:
byNum - an integer amount to increase the pool size by.
key - an integer number supplied by the PoolManager to validate that the method is called legitimately
Throws:
IllegalAccessException - if the key does not match the controller's key.

size

public int size(long key)
         throws IllegalAccessException
Description copied from interface: ManagablePool
Determine the pool's current size. The size is defined as the number of Poolable objects in reserve.

Specified by:
size in interface ManagablePool
Parameters:
key - an integer number supplied by the PoolManager to validate that the method is called legitimately
Returns:
size of pool's reserve.
Throws:
IllegalAccessException - if the key does not match the controller's key.


Copyright © 2002 Apache Avalon Project. All Rights Reserved.