Package org.vibur.objectpool
Interface BasePool
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
PoolService<T>
- All Known Implementing Classes:
ConcurrentPool
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 TypeMethodDescriptionvoidclose()A synonym forterminate().intReturns the total number of created objects which currently exist for this object pool.intTries to remove (and destroy) as many created objects from this object pool as possible.intReturns theinitialSizeof this object pool at construction time.booleanReturns the current terminated state of this object pool.intmaxSize()Returns themaxSizeof this object pool.intreduceCreatedBy(int reduceBy, boolean ignoreInitialSize) Tries to remove (and destroy) up toreduceByobjects from the object pool.intreduceCreatedTo(int reduceTo, boolean ignoreInitialSize) Tries to remove (and destroy) such number of objects from the object pool that the number ofcreatedTotal()objects in the pool to become equal ofreduceTo.intReturns the remaining capacity of this object pool, i.e. the number of objects which could be taken from this object pool without blocking.intReturns the number of remaining created objects which are currently available in this object pool.inttaken()Returns the number of objects taken from this object pool.voidTerminates 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 poolcreatedTotal(). 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 poolremainingCapacity(). 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 totaken()+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 seeremainingCreated(). Typically used for testing and debugging purposes.- Returns:
- the object pool remaining capacity
-
initialSize
int initialSize()Returns theinitialSizeof this object pool at construction time. This parameter never changes.- Returns:
- the object pool
initialSize
-
maxSize
int maxSize()Returns themaxSizeof 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 toreduceByobjects from the object pool. This method may bring the object poolcreatedTotal()to a number less than itsinitialSize().- Parameters:
reduceBy- the desired amount of objects to be removedignoreInitialSize- specifies whether thecreatedTotal()may be reduced to less thaninitialSize()- 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 ofcreatedTotal()objects in the pool to become equal ofreduceTo. This method may bring the object poolcreatedTotal()to a number smaller than itsinitialSize().- Parameters:
reduceTo- the desired amount of created objects to remain in the poolignoreInitialSize- specifies whether thecreatedTotal()may be reduced to less thaninitialSize()- 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 poolcreatedTotal()to a number less than itsinitialSize().- 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:
trueif the object pool is terminated; false otherwise
-
close
void close()A synonym forterminate(). Overrides theAutoCloseable's method in order to overrule the throwing of a checkedException.- Specified by:
closein interfaceAutoCloseable
-