public class Pool
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Pool.Factory
Defines the requirements for an object that creates, destroys and validates objects, which are maintained by a
Pool.
|
Constructor and Description |
---|
Pool(Pool.Factory f)
Create a Pool object, with a default timeout of 30 mins.
|
Pool(Pool.Factory f,
long keepAlive)
Create a Pool object.
|
Modifier and Type | Method and Description |
---|---|
int |
getMaxCount()
Query the max count of objects in this Pool object.
|
int |
getthreshold()
Query the current threshold value.
|
int |
lock(java.lang.Object key)
Increase the lock count for an object to grant exclusive usage.
|
int |
lockCount(java.lang.Object key)
Retrieve the lockCount for a given key.
|
java.lang.Object |
obtain(java.lang.Object key)
Obtain an object from the pool.
|
java.lang.Object |
obtain(java.lang.Object key,
long timeout)
Obtain an object from the pool with a specified max wait time.
|
void |
release(java.lang.Object key,
java.lang.Object o)
release an object to the pool.
|
java.lang.Object |
renew(java.lang.Object key)
Replace the current object by a new object, without changing lock counts.
|
java.lang.Object |
retrieve(java.lang.Object key)
Retrieve the object for a given key.
|
void |
setKeepAlive(long keepAlive)
Set the timeout for unused objects.
|
void |
setMaxCount(int max)
Defines how many objects are maximal maintained.
|
void |
setThreshold(int th)
Defines how many unused objects are not destroyed.
|
int |
size()
Get total count of objects in this pool.
|
int |
unlock(java.lang.Object key)
decrease the lock count for an object.
|
void |
validate()
Validate the current pool.
|
public Pool(Pool.Factory f)
f
- a Factory to create, validate and destroy the maintained objects.public Pool(Pool.Factory f, long keepAlive)
f
- a Factory to create, validate and destroy the maintained objects.keepAlive
- a timeout after unused object are removed and destroyed.public void setThreshold(int th)
th
- set the count of unused objects that are not destroyedpublic void setKeepAlive(long keepAlive)
keepAlive
- set the count of unused objects that are not destroyedpublic int getthreshold()
public void setMaxCount(int max)
max
- set the max count of objectsgetMaxCount()
public int getMaxCount()
setMaxCount(int)
public int size()
public java.lang.Object obtain(java.lang.Object key) throws java.lang.Exception
key
- a key, must not be null.java.lang.Exception
- an exception, if an error occurs.public java.lang.Object obtain(java.lang.Object key, long timeout) throws java.lang.Exception
key
- a key, must not be null.timeout
- a timeout for max waitjava.lang.Exception
- an exception, if an error occurs.public void release(java.lang.Object key, java.lang.Object o) throws java.lang.IllegalArgumentException
key
- a key, must not be null.o
- the releases object.java.lang.IllegalArgumentException
- when the key does not own an object.public java.lang.Object retrieve(java.lang.Object key)
key
- a key Object - not nullpublic int lockCount(java.lang.Object key)
key
- a key Object - not nullpublic int lock(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the object attached to this key to lock.java.lang.IllegalArgumentException
- when the key does not own an object.public int unlock(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the object attached to this key to lock.java.lang.IllegalArgumentException
- when the key does not own an object.public java.lang.Object renew(java.lang.Object key) throws java.lang.Exception
key
- the key where the old object is bound.java.lang.IllegalArgumentException
- when the key does not own an object.java.lang.Exception
- other Exceptions on creation error.public void validate()