org.codehaus.plexus.util
Class SweeperPool
java.lang.Object
org.codehaus.plexus.util.SweeperPool
public class SweeperPool
extends java.lang.Object
Pools a bunch of objects . Runs a sweeper periodically to
keep it down to size. The objects in the pool first get disposed first.
private static class | SweeperPool.Sweeper - Periodically at
sweepInterval goes through
and tests if the pool should be trimmed.
|
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 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
|
SweeperPool(int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize) -
There are a number of settings to control how the pool operates.
|
void | dispose() - Dispose of this pool.
|
Object | get() - Return the pooled object
|
int | getSize() - Return the number of pooled objects.
|
void | objectAdded(Object obj) - Override this to be notified of object addition.
|
void | objectDisposed(Object obj) - Override this to be notified of object disposal.
|
void | objectRetrieved(Object obj) - Override this to be notified of object retrieval.
|
boolean | put(Object obj) - Add an object to the pool
|
private int | saneConvert(int value)
|
void | trim() - Trim the pool down to min size
|
DEBUG
private static final boolean DEBUG
maxSize
private int maxSize
Absolute maxiumuim size of the pool.
minSize
private int minSize
The size the pool gets trimmed down to
pooledObjects
private ArrayList pooledObjects
Holds the pooled objects
shuttingDown
private boolean shuttingDown
Flag indicating this pool is shuting down
triggerSize
private int triggerSize
When the sweeper runs
and the pool is over this size, then the pool is trimmed
SweeperPool
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
dispose
public void dispose()
Dispose of this pool. Stops the sweeper and disposes each object in the pool
get
public Object get()
Return the pooled object
getSize
public int getSize()
Return the number of pooled objects. This is never
greater than t maximuim size of the pool
- the number of pooled objects
objectAdded
public void objectAdded(Object obj)
Override this to be notified of object addition.
Called before object is to be added.
objectDisposed
public void objectDisposed(Object obj)
Override this to be notified of object disposal. Called
after the object has been removed. Occurs when the pool
is trimmed.
objectRetrieved
public void objectRetrieved(Object obj)
Override this to be notified of object retrieval.
Called after object removed from the pool, but
before returned to the client.
put
public boolean put(Object obj)
Add an object to the pool
obj
- the object to pool. Can be null.
- true if the object was added to the pool, false if it was disposed or null
saneConvert
private int saneConvert(int value)
trim
public void trim()
Trim the pool down to min size