Class SimplePool<T>

java.lang.Object
org.springframework.integration.util.SimplePool<T>
All Implemented Interfaces:
Pool<T>

public class SimplePool<T>
extends Object
implements Pool<T>
Implementation of Pool supporting dynamic resizing and a variable timeout when attempting to obtain an item from the pool. Pool grows on demand up to the limit.
Since:
2.2
Author:
Gary Russell, Sergey Bogatyrev, Artem Bilan
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  SimplePool.PoolItemCallback<T>
    User of the pool provide an implementation of this interface; called during various pool operations.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected Log logger  
  • Constructor Summary

    Constructors 
    Constructor Description
    SimplePool​(int poolSize, SimplePool.PoolItemCallback<T> callback)
    Creates a SimplePool with a specific limit.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Close the pool; returned items will be destroyed.
    int getActiveCount()
    Returns the number of allocated items that are currently checked out of the pool.
    int getAllocatedCount()
    Returns the current count of allocated items (in use and idle).
    int getIdleCount()
    Returns the number of items that have been allocated but are not currently in use.
    T getItem()
    Obtains an item from the pool; waits up to waitTime milliseconds (default infinity).
    int getPoolSize()
    Returns the current size of the pool; may be greater than the target pool size if it was recently reduced and too many items were in use to allow the new size to be set.
    void releaseItem​(T item)
    Returns an item to the pool.
    void removeAllIdleItems()
    Removes all idle items from the pool.
    void setPoolSize​(int poolSize)
    Adjusts the current pool size.
    void setWaitTimeout​(long waitTimeout)
    Adjusts the wait timeout - the time for which getItem() will wait if no idle entries are available.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • setPoolSize

      public void setPoolSize​(int poolSize)
      Adjusts the current pool size. When reducing the pool size, attempts to remove the delta from the pool. If there are not enough unused items in the pool, the actual pool size will decrease to the specified size as in-use items are returned.
      Parameters:
      poolSize - The desired target pool size.
    • getPoolSize

      public int getPoolSize()
      Returns the current size of the pool; may be greater than the target pool size if it was recently reduced and too many items were in use to allow the new size to be set.
      Specified by:
      getPoolSize in interface Pool<T>
      Returns:
      the size.
    • getIdleCount

      public int getIdleCount()
      Description copied from interface: Pool
      Returns the number of items that have been allocated but are not currently in use.
      Specified by:
      getIdleCount in interface Pool<T>
      Returns:
      The number of items.
    • getActiveCount

      public int getActiveCount()
      Description copied from interface: Pool
      Returns the number of allocated items that are currently checked out of the pool.
      Specified by:
      getActiveCount in interface Pool<T>
      Returns:
      The number of items.
    • getAllocatedCount

      public int getAllocatedCount()
      Description copied from interface: Pool
      Returns the current count of allocated items (in use and idle). May be less than the pool size, and reflects the high water mark of pool usage.
      Specified by:
      getAllocatedCount in interface Pool<T>
      Returns:
      the number of items.
    • setWaitTimeout

      public void setWaitTimeout​(long waitTimeout)
      Adjusts the wait timeout - the time for which getItem() will wait if no idle entries are available.
      Default: infinity.
      Parameters:
      waitTimeout - The wait timeout in milliseconds.
    • getItem

      public T getItem()
      Obtains an item from the pool; waits up to waitTime milliseconds (default infinity).
      Specified by:
      getItem in interface Pool<T>
      Returns:
      the item.
      Throws:
      PoolItemNotAvailableException - if no items become available in time.
    • releaseItem

      public void releaseItem​(T item)
      Returns an item to the pool.
      Specified by:
      releaseItem in interface Pool<T>
      Parameters:
      item - the item.
    • removeAllIdleItems

      public void removeAllIdleItems()
      Description copied from interface: Pool
      Removes all idle items from the pool.
      Specified by:
      removeAllIdleItems in interface Pool<T>
    • close

      public void close()
      Description copied from interface: Pool
      Close the pool; returned items will be destroyed.
      Specified by:
      close in interface Pool<T>