|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.sapia.ubik.net.Pool
public abstract class Pool
Implements a basic object pool. Pooled objects must be returned to the pool once done with.
| Field Summary | |
|---|---|
protected int |
_currentCount
|
protected long |
_lastUsageTime
|
protected int |
_maxSize
|
protected java.util.List |
_objects
|
static int |
NO_MAX
|
static long |
NO_TIME_OUT
|
| Constructor Summary | |
|---|---|
Pool()
|
|
Pool(int maxSize)
|
|
| Method Summary | |
|---|---|
java.lang.Object |
acquire()
Acquires an object from the pool; waits indefinitely that an object becomes available if the pool is empty and its maximum created object count has been reach. |
java.lang.Object |
acquire(long timeout)
Acquires an object from this pool; if the pool is empty and its maximum created object count has been reach, this method waits for the specified timeout that an object becomes ready. |
java.lang.Object |
acquireCreate()
This method attempts to acquire an object from this pool. |
protected void |
cleanup(java.lang.Object pooled)
Inheriting classes should override this method to implement proper cleanup behavior for pooled objects. |
protected abstract java.lang.Object |
doNewObject()
This template method should be overridden by inheriting classes to provide object instances that will be pooled. |
void |
fill(int toSize)
Fills the pool up to the given size, or up to this pool's specified maximum size (if the latter was specified). |
int |
getCreatedCount()
Returns the number of objects that have been created by this pool so far. |
long |
getLastUsageTime()
Returns the time an object was last acquired from this pool. |
protected java.lang.Object |
onAcquire(java.lang.Object o)
|
protected void |
onRelease(java.lang.Object o)
|
void |
release(java.lang.Object obj)
Releases the given object to the given pool. |
void |
shrinkTo(int size)
Shrinks the pool to the specified size, or until the pool is empty. |
int |
size()
Returns the number of objects currently in the pool. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long NO_TIME_OUT
public static final int NO_MAX
protected java.util.List _objects
protected int _maxSize
protected int _currentCount
protected long _lastUsageTime
| Constructor Detail |
|---|
public Pool()
public Pool(int maxSize)
| Method Detail |
|---|
public java.lang.Object acquire()
throws java.lang.InterruptedException,
java.lang.Exception
Object
an - Exception if a problem occurs acquiring the object.
java.lang.InterruptedException
java.lang.Exception
public java.lang.Object acquire(long timeout)
throws java.lang.InterruptedException,
NoObjectAvailableException,
java.lang.Exception
timeout - a timeout to wait for until an object becomes available (in millis).
Object
NoObjectAvailableException - if an object could not be acquired within
the specified amount of time.
java.lang.Exception - if a problem occurs creating the object.
java.lang.InterruptedException
protected java.lang.Object onAcquire(java.lang.Object o)
throws java.lang.Exception
java.lang.Exceptionprotected void onRelease(java.lang.Object o)
public void release(java.lang.Object obj)
obj - an Object to put back into
the pool.public long getLastUsageTime()
public int getCreatedCount()
public int size()
public void shrinkTo(int size)
cleanup()
method for each object in the pool, so that the cleaned objects
are properly disposed of.
size - the size to which to clean the pool.cleanup(Object)
public void fill(int toSize)
throws java.lang.Exception
toSize - the size up to which this pool should be filled.
java.lang.Exception
public java.lang.Object acquireCreate()
throws java.lang.Exception
null. If this pool
is currently empty but no maximum number of created objects has been
defined (at construction time), then a new object will be created and
returned.
Object, or null if the pool is currently empty
and has reached the maximum number of objects it can create.
java.lang.Exception - if no object could be acquired/created.
protected abstract java.lang.Object doNewObject()
throws java.lang.Exception
Object to pool.
java.lang.Exception - if an error occurs while creating the object to be
returned.protected void cleanup(java.lang.Object pooled)
shrinkTo(int)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||