Interface BasePool

All Superinterfaces:
AutoCloseable
All Known Subinterfaces:
PoolService<T>
All Known Implementing Classes:
ConcurrentPool

public interface BasePool extends AutoCloseable
Defines the base object pool operations. These operations include various pool metrics, pool termination methods, and support for shrinking (reduction) of the number of allocated on the pool objects.
Author:
Simeon Malchev
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    A synonym for terminate().
    int
    Returns the total number of created objects which currently exist for this object pool.
    int
    Tries to remove (and destroy) as many created objects from this object pool as possible.
    int
    Returns the initialSize of this object pool at construction time.
    boolean
    Returns the current terminated state of this object pool.
    int
    Returns the maxSize of this object pool.
    int
    reduceCreatedBy(int reduceBy, boolean ignoreInitialSize)
    Tries to remove (and destroy) up to reduceBy objects from the object pool.
    int
    reduceCreatedTo(int reduceTo, boolean ignoreInitialSize)
    Tries to remove (and destroy) such number of objects from the object pool that the number of createdTotal() objects in the pool to become equal of reduceTo.
    int
    Returns the remaining capacity of this object pool, i.e. the number of objects which could be taken from this object pool without blocking.
    int
    Returns the number of remaining created objects which are currently available in this object pool.
    int
    Returns the number of objects taken from this object pool.
    void
    Terminates this object pool.
  • Method Details

    • taken

      int taken()
      Returns the number of objects taken from this object pool. This number is less than or equal to the object pool createdTotal(). Typically used for testing and debugging purposes.
      Returns:
      the number of objects taken from this object pool
    • remainingCreated

      int remainingCreated()
      Returns the number of remaining created objects which are currently available in this object pool. This number is less than or equal to the object pool remainingCapacity(). Typically used for testing and debugging purposes.
      Returns:
      the number of remaining created objects in this object pool
    • createdTotal

      int createdTotal()
      Returns the total number of created objects which currently exist for this object pool. This number is equal to taken() + remainingCreated(). Typically used for testing and debugging purposes.
      Returns:
      the total number of created objects for this object pool
    • remainingCapacity

      int remainingCapacity()
      Returns the remaining capacity of this object pool, i.e. the number of objects which could be taken from this object pool without blocking. It is not guaranteed that all these objects exist at the time of the call (i.e. are already created) in the object pool - some of them might be created on demand upon take requests. Also see remainingCreated(). Typically used for testing and debugging purposes.
      Returns:
      the object pool remaining capacity
    • initialSize

      int initialSize()
      Returns the initialSize of this object pool at construction time. This parameter never changes.
      Returns:
      the object pool initialSize
    • maxSize

      int maxSize()
      Returns the maxSize of this object pool. This parameter never changes.
      Returns:
      the object pool maxSize
    • reduceCreatedBy

      int reduceCreatedBy(int reduceBy, boolean ignoreInitialSize)
      Tries to remove (and destroy) up to reduceBy objects from the object pool. This method may bring the object pool createdTotal() to a number less than its initialSize().
      Parameters:
      reduceBy - the desired amount of objects to be removed
      ignoreInitialSize - specifies whether the createdTotal() may be reduced to less than initialSize()
      Returns:
      the actual amount of objects removed
    • reduceCreatedTo

      int reduceCreatedTo(int reduceTo, boolean ignoreInitialSize)
      Tries to remove (and destroy) such number of objects from the object pool that the number of createdTotal() objects in the pool to become equal of reduceTo. This method may bring the object pool createdTotal() to a number smaller than its initialSize().
      Parameters:
      reduceTo - the desired amount of created objects to remain in the pool
      ignoreInitialSize - specifies whether the createdTotal() may be reduced to less than initialSize()
      Returns:
      the actual amount of objects removed
    • drainCreated

      int drainCreated()
      Tries to remove (and destroy) as many created objects from this object pool as possible. May bring the object pool createdTotal() to a number less than its initialSize().
      Returns:
      the actual amount of objects removed (and destroyed)
    • terminate

      void terminate()
      Terminates this object pool. Once terminated the object pool cannot be more revived. All take and restore operations called on a terminated object pool should throw an exception or be ignored. This method can be invoked multiple times.
    • isTerminated

      boolean isTerminated()
      Returns the current terminated state of this object pool.
      Returns:
      true if the object pool is terminated; false otherwise
    • close

      void close()
      A synonym for terminate(). Overrides the AutoCloseable's method in order to overrule the throwing of a checked Exception.
      Specified by:
      close in interface AutoCloseable