Package org.codehaus.plexus.util
Class SweeperPool
java.lang.Object
org.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.
- Version:
- $Id$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classPeriodically atsweepIntervalgoes through and tests if the pool should be trimmed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate intAbsolute maximum size of the pool.private intThe size the pool gets trimmed down toHolds the pooled objectsprivate booleanFlag indicating this pool is shuting downprivate SweeperPool.SweeperSweeps the pool periodically to trim it's sizeprivate intWhen the sweeper runs and the pool is over this size, then the pool is trimmed -
Constructor Summary
ConstructorsConstructorDescriptionSweeperPool(int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize) There are a number of settings to control how the pool operates. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Dispose of this pool.get()Return the pooled objectintgetSize()Return the number of pooled objects.(package private) booleanA pool has been disposed if has been shutdown and the sweeper has completed running.voidobjectAdded(Object obj) Override this to be notified of object addition.voidobjectDisposed(Object obj) Override this to be notified of object disposal.voidobjectRetrieved(Object obj) Override this to be notified of object retrieval.booleanAdd an object to the poolprivate intsaneConvert(int value) voidtrim()Trim the pool down to min size
-
Field Details
-
DEBUG
private static final boolean DEBUG- See Also:
-
sweeper
Sweeps the pool periodically to trim it's size -
maxSize
private transient int maxSizeAbsolute maximum size of the pool. -
minSize
private transient int minSizeThe size the pool gets trimmed down to -
triggerSize
private int triggerSizeWhen the sweeper runs and the pool is over this size, then the pool is trimmed -
pooledObjects
Holds the pooled objects -
shuttingDown
private boolean shuttingDownFlag indicating this pool is shuting down
-
-
Constructor Details
-
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 tominSize.maxSize- if the pool has reached this size, any objects added are immediately disposed. If the pool is this size when the sweeper runs, then the pool is also trimmed tominSizeirrespective 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 Details
-
saneConvert
private int saneConvert(int value) -
get
Return the pooled object -
put
Add an object to the pool- Parameters:
obj- the object to pool. Can be null.- Returns:
- true if the object was added to the pool, false if it was disposed or null
-
getSize
public int getSize()Return the number of pooled objects. This is never greater than t maximum size of the pool- Returns:
- the number of pooled objects
-
dispose
public void dispose()Dispose of this pool. Stops the sweeper and disposes each object in the pool -
isDisposed
boolean isDisposed()A pool has been disposed if has been shutdown and the sweeper has completed running.- Returns:
- true if the pool has been disposed, false otherwise
-
trim
public void trim()Trim the pool down to min size -
objectDisposed
Override this to be notified of object disposal. Called after the object has been removed. Occurs when the pool is trimmed.- Parameters:
obj-
-
objectAdded
Override this to be notified of object addition. Called before object is to be added.- Parameters:
obj-
-
objectRetrieved
Override this to be notified of object retrieval. Called after object removed from the pool, but before returned to the client.- Parameters:
obj-
-