Package edu.uiuc.ncsa.security.core.util
Class Pool<T>
- java.lang.Object
-
- edu.uiuc.ncsa.security.core.util.Pool<T>
-
- Direct Known Subclasses:
ConnectionPool
public abstract class Pool<T> extends Object
A pool of items, that is to say, a managed list that keeps valid items on it and can create or destroy them as needed. when pushing and popping off a stack.Supremely useful with SQL connections. This does check for validity as a matter of course.
Created by Jeff Gaynor
on Mar 12, 2010 at 3:48:20 PM
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
DEEP_DEBUG
Set true if you want to see a ton of low level debugging for this.static int
INFINITE
protected int
inUse
protected int
maxSize
protected Queue<T>
stack
protected int
totalCreated
protected int
totalDestroyed
-
Constructor Summary
Constructors Constructor Description Pool()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract T
create()
Create a new, ready-to-use object for the poolabstract void
destroy(T object)
Destroy an object that is no longer needed.T
doCreate()
void
doDestroy(T item)
Destroying an item reduces the number of in-use items.int
getMaxSize()
Get the maximum number of itemsQueue<T>
getStack()
boolean
isValid(T object)
Is this item still good? If not it will be removed from the pool so a new one can be created.T
pop()
Pop an object off the stack if there is one, otherwise, create one.void
push(T object)
Check an object into the pool.void
setMaxSize(int c)
Set the maximum number of items.String
toString()
protected void
trace(String x)
-
-
-
Field Detail
-
INFINITE
public static final int INFINITE
- See Also:
- Constant Field Values
-
maxSize
protected int maxSize
-
totalCreated
protected int totalCreated
-
totalDestroyed
protected int totalDestroyed
-
inUse
protected int inUse
-
DEEP_DEBUG
protected boolean DEEP_DEBUG
Set true if you want to see a ton of low level debugging for this.
-
-
Method Detail
-
trace
protected void trace(String x)
-
create
public abstract T create() throws PoolException
Create a new, ready-to-use object for the pool- Returns:
- the object
- Throws:
PoolException
-
destroy
public abstract void destroy(T object) throws PoolException
Destroy an object that is no longer needed.- Parameters:
object
- the object- Throws:
PoolException
-
isValid
public boolean isValid(T object) throws PoolException
Is this item still good? If not it will be removed from the pool so a new one can be created. Default is to return true.- Throws:
PoolException
-
pop
public T pop() throws PoolException
Pop an object off the stack if there is one, otherwise, create one.- Returns:
- the object
- Throws:
PoolException
-
doCreate
public T doCreate() throws PoolException
- Throws:
PoolException
-
doDestroy
public void doDestroy(T item) throws PoolException
Destroying an item reduces the number of in-use items. Do not call this on an item that hasn't been checked out.- Parameters:
item
- the item- Throws:
PoolException
-
setMaxSize
public void setMaxSize(int c)
Set the maximum number of items.- Parameters:
c
-
-
getMaxSize
public int getMaxSize()
Get the maximum number of items- Returns:
- capacity
-
push
public void push(T object) throws PoolException
Check an object into the pool. If the pool is at capacity, destroy the object.- Parameters:
object
- the object- Throws:
PoolException
-
-