org.apache.commons.pool.impl

Class StackKeyedObjectPool

Implemented Interfaces:
KeyedObjectPool

public class StackKeyedObjectPool
extends BaseKeyedObjectPool
implements KeyedObjectPool

A simple, Stack-based KeyedObjectPool implementation.

Given a KeyedPoolableObjectFactory, this class will maintain a simple pool of instances. A finite number of "sleeping" or inactive instances is enforced, but when the pool is empty, new instances are created to support the new load. Hence this class places no limit on the number of "active" instances created by the pool, but is quite useful for re-using Objects without introducing artificial limits.

Version:
$Revision: 328937 $ $Date: 2005-10-27 15:23:53 -0400 (Thu, 27 Oct 2005) $
Author:
Rodney Waldhoff

Constructor Summary

StackKeyedObjectPool()
Create a new pool using no factory.
StackKeyedObjectPool(int max)
Create a new pool using no factory.
StackKeyedObjectPool(int max, int init)
Create a new pool using no factory.
StackKeyedObjectPool(KeyedPoolableObjectFactory factory)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances.
StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances.
StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max, int init)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances.

Method Summary

void
addObject(Object key)
Object
borrowObject(Object key)
void
clear()
void
clear(Object key)
void
close()
int
getNumActive()
int
getNumActive(Object key)
int
getNumIdle()
int
getNumIdle(Object key)
void
invalidateObject(Object key, Object obj)
void
returnObject(Object key, Object obj)
void
setFactory(KeyedPoolableObjectFactory factory)
String
toString()

Methods inherited from class org.apache.commons.pool.BaseKeyedObjectPool

addObject, borrowObject, clear, clear, close, getNumActive, getNumActive, getNumIdle, getNumIdle, invalidateObject, returnObject, setFactory

Constructor Details

StackKeyedObjectPool

public StackKeyedObjectPool()
Create a new pool using no factory. Clients must first populate the pool using returnObject(java.lang.Object,java.lang.Object) before they can be borrowed.

StackKeyedObjectPool

public StackKeyedObjectPool(int max)
Create a new pool using no factory. Clients must first populate the pool using returnObject(java.lang.Object,java.lang.Object) before they can be borrowed.
Parameters:
max - cap on the number of "sleeping" instances in the pool

StackKeyedObjectPool

public StackKeyedObjectPool(int max,
                            int init)
Create a new pool using no factory. Clients must first populate the pool using returnObject(java.lang.Object,java.lang.Object) before they can be borrowed.
Parameters:
max - cap on the number of "sleeping" instances in the pool
init - initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)

StackKeyedObjectPool

public StackKeyedObjectPool(KeyedPoolableObjectFactory factory)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances.
Parameters:
factory - the KeyedPoolableObjectFactory used to populate the pool

StackKeyedObjectPool

public StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
                            int max)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances. capping the number of "sleeping" instances to max
Parameters:
factory - the KeyedPoolableObjectFactory used to populate the pool
max - cap on the number of "sleeping" instances in the pool

StackKeyedObjectPool

public StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
                            int max,
                            int init)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances. capping the number of "sleeping" instances to max, and initially allocating a container capable of containing at least init instances.
Parameters:
factory - the KeyedPoolableObjectFactory used to populate the pool
max - cap on the number of "sleeping" instances in the pool
init - initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)

Method Details

addObject

public void addObject(Object key)
            throws Exception
Specified by:
addObject in interface KeyedObjectPool
Overrides:
addObject in interface BaseKeyedObjectPool

borrowObject

public Object borrowObject(Object key)
            throws Exception
Specified by:
borrowObject in interface KeyedObjectPool
Overrides:
borrowObject in interface BaseKeyedObjectPool

clear

public void clear()
Specified by:
clear in interface KeyedObjectPool
Overrides:
clear in interface BaseKeyedObjectPool

clear

public void clear(Object key)
Specified by:
clear in interface KeyedObjectPool
Overrides:
clear in interface BaseKeyedObjectPool

close

public void close()
            throws Exception
Specified by:
close in interface KeyedObjectPool
Overrides:
close in interface BaseKeyedObjectPool

getNumActive

public int getNumActive()
Specified by:
getNumActive in interface KeyedObjectPool
Overrides:
getNumActive in interface BaseKeyedObjectPool

getNumActive

public int getNumActive(Object key)
Specified by:
getNumActive in interface KeyedObjectPool
Overrides:
getNumActive in interface BaseKeyedObjectPool

getNumIdle

public int getNumIdle()
Specified by:
getNumIdle in interface KeyedObjectPool
Overrides:
getNumIdle in interface BaseKeyedObjectPool

getNumIdle

public int getNumIdle(Object key)
Specified by:
getNumIdle in interface KeyedObjectPool
Overrides:
getNumIdle in interface BaseKeyedObjectPool

invalidateObject

public void invalidateObject(Object key,
                             Object obj)
            throws Exception
Specified by:
invalidateObject in interface KeyedObjectPool
Overrides:
invalidateObject in interface BaseKeyedObjectPool

returnObject

public void returnObject(Object key,
                         Object obj)
            throws Exception
Specified by:
returnObject in interface KeyedObjectPool
Overrides:
returnObject in interface BaseKeyedObjectPool

setFactory

public void setFactory(KeyedPoolableObjectFactory factory)
            throws IllegalStateException
Specified by:
setFactory in interface KeyedObjectPool
Overrides:
setFactory in interface BaseKeyedObjectPool

toString

public String toString()

Copyright © 2001-2003 Apache Software Foundation. Documenation generated June 5 2007.