|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.plexus.util.SweeperPool
Pools a bunch of objects . Runs a sweeper periodically to keep it down to size. The objects in the pool first get disposed first.
Nested Class Summary | |
private static class |
SweeperPool.Sweeper
Periodically at sweepInterval goes through
and tests if the pool should be trimmed. |
Field Summary | |
private static boolean |
DEBUG
|
private int |
maxSize
Absolute maxiumuim size of the pool. |
private int |
minSize
The size the pool gets trimmed down to |
private java.util.ArrayList |
pooledObjects
Holds the pooled objects |
private boolean |
shuttingDown
Flag indicating this pool is shuting down |
private SweeperPool.Sweeper |
sweeper
Sweeps the pool periodically to trim it's size |
private int |
triggerSize
When the sweeper runs and the pool is over this size, then the pool is trimmed |
Constructor Summary | |
SweeperPool(int maxSize,
int minSize,
int intialCapacity,
int sweepInterval,
int triggerSize)
There are a number of settings to control how the pool operates. |
Method Summary | |
void |
dispose()
Dispose of this pool. |
java.lang.Object |
get()
Return the pooled object |
int |
getSize()
Return the number of pooled objects. |
void |
objectAdded(java.lang.Object obj)
Override this to be notified of object addition. |
void |
objectDisposed(java.lang.Object obj)
Override this to be notified of object disposal. |
void |
objectRetrieved(java.lang.Object obj)
Override this to be notified of object retrieval. |
boolean |
put(java.lang.Object obj)
Add an object to the pool |
private int |
saneConvert(int value)
|
void |
trim()
Trim the pool down to min size |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final boolean DEBUG
private transient SweeperPool.Sweeper sweeper
private transient int maxSize
private transient int minSize
private int triggerSize
private java.util.ArrayList pooledObjects
private boolean shuttingDown
Constructor Detail |
public SweeperPool(int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize)
There are a number of settings to control how the pool operates.
minSize
- this is the size the pool is trimmed totriggerSize
- this determines if the pool is trimmed when
the sweeper runs. If the pool size is greater or equal than this value then
the pool is trimmed to minSize
.
maxSize
- if the pool has reached this size, any objects added
are immediatley disposed. If the pool is this size when the sweeper runs, then
the pool is also trimmed to minSize
irrespective of the triggerSize.
sweepInterval
- how often the sweeper runs. Is actually the
time since the sweeper last finished a pass. 0 if the sweeper should not run.
Any value less than 0 is automatically converted to 0
Method Detail |
private int saneConvert(int value)
public java.lang.Object get()
public boolean put(java.lang.Object obj)
obj
- the object to pool. Can be null.
public int getSize()
public void dispose()
public void trim()
public void objectDisposed(java.lang.Object obj)
obj
- public void objectAdded(java.lang.Object obj)
obj
- public void objectRetrieved(java.lang.Object obj)
obj
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |