Class SweeperPool

java.lang.Object
org.codehaus.plexus.util.SweeperPool

public class SweeperPool extends 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.
Author:
Bert van Brakel
  • Constructor Summary

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    void
    Dispose of this pool.
    get()
    Return the pooled object
    int
    Return the number of pooled objects.
    void
    Override this to be notified of object addition.
    void
    Override this to be notified of object disposal.
    void
    Override this to be notified of object retrieval.
    boolean
    put(Object obj)
    Add an object to the pool
    void
    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
  • 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.
      Parameters:
      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 to minSize irrespective of the triggerSize.
      minSize - - this is the size the pool is trimmed to
      triggerSize - - 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.
      sweepInterval - how often the sweeper runs. Is actually the time since the sweeper last finished a pass. 0 if the sweeper should not run.
      intialCapacity - the intial capacity

      Any value less than 0 is automatically converted to 0

  • Method Details

    • get

      public Object get()
      Return the pooled object
      Returns:
      first available object from the pool
    • put

      public boolean put(Object obj)
      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
    • trim

      public void trim()
      Trim the pool down to min size
    • 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.
      Parameters:
      obj - the Object
    • objectAdded

      public void objectAdded(Object obj)
      Override this to be notified of object addition. Called before object is to be added.
      Parameters:
      obj - the Object
    • 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.
      Parameters:
      obj - the Object