org.apache.excalibur.mpool
Class VariableSizePool

java.lang.Object
  extended byorg.apache.excalibur.mpool.VariableSizePool
All Implemented Interfaces:
Disposable, ManagablePool, Pool

public final class VariableSizePool
extends java.lang.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.4 $ $Date: 2004/02/28 11:47:34 $
Author:
Avalon Development Team

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
 java.lang.Object acquire()
          Acquire an instance of the pooled object.
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 void grow(int byNum, long key)
          Grow by the specified amount.
 java.lang.Object newInstance()
          Create a new instance of the object being pooled.
 void release(java.lang.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 java.lang.Exception
Constructor for an unmanaged pool


VariableSizePool

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

Method Detail

acquire

public java.lang.Object acquire()
                         throws java.lang.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:
java.lang.Exception - if the Pool is not able to return an object.

release

public void release(java.lang.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 java.lang.Object newInstance()
                             throws java.lang.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:
java.lang.Exception - if the instance cannot be created

dispose

public void dispose()
Description copied from interface: Disposable
The dispose operation is called at the end of a components lifecycle. This method will be called after Startable.stop() method (if implemented by component). Components use this method to release and destroy any resources that the Component owns.

Specified by:
dispose in interface Disposable

shrink

public void shrink(int byNum,
                   long key)
            throws java.lang.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:
java.lang.IllegalAccessException - if the key does not match the controller's key.

grow

public void grow(int byNum,
                 long key)
          throws java.lang.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:
java.lang.IllegalAccessException - if the key does not match the controller's key.

size

public int size(long key)
         throws java.lang.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:
java.lang.IllegalAccessException - if the key does not match the controller's key.


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.