This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch POOL_2_X in repository https://gitbox.apache.org/repos/asf/commons-pool.git
commit 33b26d67f48b5f95aa7119cf708081072f0c0297 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Jul 18 08:18:26 2023 -0400 Add BaseGenericObjectPool methods that return Duration as equivalents for methods return milliseconds as long In 3.0 the long methods in implementing classes will be removed so Duration variants must be added in the interface. --- src/changes/changes.xml | 3 + .../commons/pool2/impl/BaseGenericObjectPool.java | 71 +++++++++++++++++++--- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 14ed56aa..77759221 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -114,6 +114,9 @@ The <action> type attribute can be add,update,fix,remove. <action dev="ggregory" type="add"> BaseGenericObjectPool now implements AutoCloseable. </action> + <action dev="ggregory" type="add"> + Add BaseGenericObjectPool methods that return Duration and deprecate equivalents that return milliseconds as long. + </action> <!-- UPDATE --> <action dev="kinow" type="update" due-to="Dependabot, Gary Gregory"> Bump actions/cache from 2.1.6 to 3.0.10 #117, #138, #158, #174, #178. diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java index 5f71b23e..9d6508d0 100644 --- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java +++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java @@ -53,11 +53,11 @@ import org.apache.commons.pool2.SwallowedExceptionListener; * Base class that provides common functionality for {@link GenericObjectPool} * and {@link GenericKeyedObjectPool}. The primary reason this class exists is * reduce code duplication between the two pool implementations. - * - * @param <T> Type of element pooled in this pool. - * + * <p> * This class is intended to be thread-safe. + * </p> * + * @param <T> Type of element pooled in this pool. * @since 2.0 */ public abstract class BaseGenericObjectPool<T> extends BaseObject implements AutoCloseable { @@ -696,8 +696,21 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject implements Aut /** * Gets the maximum time a thread has waited to borrow objects from the pool. + * + * @return maximum wait time in milliseconds since the pool was created + * @since 2.12.0 + */ + public final Duration getMaxBorrowWaitDuration() { + return maxBorrowWaitDuration.get(); + } + + /** + * Gets the maximum time a thread has waited to borrow objects from the pool. + * * @return maximum wait time in milliseconds since the pool was created + * @deprecated Use {@link #getMaxBorrowWaitDuration()}. */ + @Deprecated public final long getMaxBorrowWaitTimeMillis() { return maxBorrowWaitDuration.get().toMillis(); } @@ -710,7 +723,6 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject implements Aut * * @return the cap on the total number of object instances managed by the * pool. - * * @see #setMaxTotal */ public final int getMaxTotal() { @@ -758,8 +770,23 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject implements Aut * Gets the mean time objects are active for based on the last {@link * #MEAN_TIMING_STATS_CACHE_SIZE} objects returned to the pool. * @return mean time an object has been checked out from the pool among - * recently returned objects + * recently returned objects. + * + * @since 2.12.0 + */ + public final Duration getMeanActiveDuration() { + return Duration.ofMillis(activeTimes.getMean()); + } + + /** + * Gets the mean time objects are active for based on the last {@link + * #MEAN_TIMING_STATS_CACHE_SIZE} objects returned to the pool. + * @return mean time an object has been checked out from the pool among + * recently returned objects. + * + * @deprecated Use {@link #getMeanActiveDuration()}. */ + @Deprecated public final long getMeanActiveTimeMillis() { return activeTimes.getMean(); } @@ -767,9 +794,24 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject implements Aut /** * Gets the mean time threads wait to borrow an object based on the last {@link * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool. + * + * @return mean time in milliseconds that a recently served thread has had + * to wait to borrow an object from the pool. + * @since 2.12.0 + */ + public final Duration getMeanBorrowWaitDuration() { + return Duration.ofMillis(waitTimes.getMean()); + } + + /** + * Gets the mean time threads wait to borrow an object based on the last {@link + * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool. + * * @return mean time in milliseconds that a recently served thread has had - * to wait to borrow an object from the pool + * to wait to borrow an object from the pool. + * @deprecated Use {@link #getMeanBorrowWaitDuration()}. */ + @Deprecated public final long getMeanBorrowWaitTimeMillis() { return waitTimes.getMean(); } @@ -777,9 +819,24 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject implements Aut /** * Gets the mean time objects are idle for based on the last {@link * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool. + * * @return mean time an object has been idle in the pool among recently - * borrowed objects + * borrowed objects. + * @since 2.12.0 */ + public final Duration getMeanIdleDuration() { + return Duration.ofMillis(idleTimes.getMean()); + } + + /** + * Gets the mean time objects are idle for based on the last {@link + * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool. + * + * @return mean time an object has been idle in the pool among recently + * borrowed objects. + * @deprecated Use {@link #getMeanIdleDuration()}. + */ + @Deprecated public final long getMeanIdleTimeMillis() { return idleTimes.getMean(); }