You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/08/07 13:37:28 UTC

[commons-pool] branch master updated (d2d4ef84 -> 35e2d77e)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git


    from d2d4ef84 Simplify: Keys and values cannot be null inside a ConcurrentHashMap.
     new 60bee245 Javadoc
     new f370532e Use forEach and streams
     new 35e2d77e Bump pmd from 6.47.0 to 6.48.0.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |  4 +--
 src/changes/changes.xml                            |  5 ++-
 .../commons/pool2/impl/BaseGenericObjectPool.java  | 34 ++++++++++----------
 .../commons/pool2/impl/GenericKeyedObjectPool.java | 36 ++++++++--------------
 .../commons/pool2/impl/GenericObjectPool.java      |  4 +--
 5 files changed, 35 insertions(+), 48 deletions(-)


[commons-pool] 01/03: Javadoc

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 60bee245fc54829ae3584d974f08fd1c2fac610d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 7 08:54:51 2022 -0400

    Javadoc
---
 .../commons/pool2/impl/BaseGenericObjectPool.java  | 34 ++++++++++------------
 1 file changed, 16 insertions(+), 18 deletions(-)

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 a4993c2f..afdf7921 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
@@ -517,7 +517,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The total number of objects successfully borrowed from this pool over the
+     * Gets the total number of objects successfully borrowed from this pool over the
      * lifetime of the pool.
      * @return the borrowed object count
      */
@@ -526,7 +526,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The total number of objects created for this pool over the lifetime of
+     * Gets the total number of objects created for this pool over the lifetime of
      * the pool.
      * @return the created object count
      */
@@ -535,7 +535,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * Provides the stack trace for the call that created this pool. JMX
+     * Gets the stack trace for the call that created this pool. JMX
      * registration may trigger a memory leak so it is important that pools are
      * deregistered when no longer used by calling the {@link #close()} method.
      * This method is provided to assist with identifying code that creates but
@@ -547,7 +547,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The total number of objects destroyed by this pool as a result of failing
+     * Gets the total number of objects destroyed by this pool as a result of failing
      * validation during {@code borrowObject()} over the lifetime of the
      * pool.
      * @return validation destroyed object count
@@ -557,7 +557,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The total number of objects destroyed by the evictor associated with this
+     * Gets the total number of objects destroyed by the evictor associated with this
      * pool over the lifetime of the pool.
      * @return the evictor destroyed object count
      */
@@ -566,7 +566,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The total number of objects destroyed by this pool over the lifetime of
+     * Gets the total number of objects destroyed by this pool over the lifetime of
      * the pool.
      * @return the destroyed object count
      */
@@ -665,7 +665,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * Provides the name under which the pool has been registered with the
+     * Gets the name under which the pool has been registered with the
      * platform MBean server or {@code null} if the pool has not been
      * registered.
      * @return the JMX name
@@ -765,7 +765,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The mean time objects are active for based on the last {@link
+     * 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
@@ -775,7 +775,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The mean time threads wait to borrow an object based on the last {@link
+     * 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
@@ -785,7 +785,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The mean time objects are idle for based on the last {@link
+     * 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
@@ -863,7 +863,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The number of instances currently idle in this pool.
+     * Gets the number of instances currently idle in this pool.
      * @return count of instances available for checkout from the pool
      */
     public abstract int getNumIdle();
@@ -949,7 +949,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The total number of objects returned to this pool over the lifetime of
+     * Gets the total number of objects returned to this pool over the lifetime of
      * the pool. This excludes attempts to return the same object multiple
      * times.
      * @return the returned object count
@@ -1164,10 +1164,8 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
         return durationBetweenEvictionRuns.toMillis();
     }
 
-    // Monitoring (primarily JMX) related methods
-
     /**
-     * Gets whether or not abandoned object removal is configured for this pool.
+     * Tests whether or not abandoned object removal is configured for this pool.
      *
      * @return true if this pool is configured to detect and remove
      * abandoned objects
@@ -1178,7 +1176,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * Has this pool instance been closed.
+     * Tests whether this pool instance been closed.
      * @return {@code true} when this pool has been closed.
      */
     public final boolean isClosed() {
@@ -1297,7 +1295,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * Initializes the receiver with the given configuration.
+     * Sets the receiver with the given configuration.
      *
      * @param config Initialization source.
      */
@@ -1670,7 +1668,7 @@ public abstract class BaseGenericObjectPool<T, E extends Exception> extends Base
     }
 
     /**
-     * The listener used (if any) to receive notifications of exceptions
+     * Sets the listener used (if any) to receive notifications of exceptions
      * unavoidably swallowed by the pool.
      *
      * @param swallowedExceptionListener    The listener or {@code null}


[commons-pool] 02/03: Use forEach and streams

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit f370532e9c30b6574e6e31a2c0cc063aec4306da
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 7 09:37:11 2022 -0400

    Use forEach and streams
    
    - Be more specific with local and private types for IDEs and static
    analysis.
---
 .../commons/pool2/impl/GenericKeyedObjectPool.java | 36 ++++++++--------------
 .../commons/pool2/impl/GenericObjectPool.java      |  4 +--
 2 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
index aece8351..7e03146c 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
@@ -193,7 +193,6 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     private static final String ONAME_BASE =
             "org.apache.commons.pool2:type=GenericKeyedObjectPool,name=";
 
-    //--- configuration attributes ---------------------------------------------
     private volatile int maxIdlePerKey =
             GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY;
 
@@ -637,7 +636,7 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     public void clearOldest() {
 
         // build sorted map of idle objects
-        final Map<PooledObject<T>, K> map = new TreeMap<>();
+        final TreeMap<PooledObject<T>, K> map = new TreeMap<>();
 
         poolMap.forEach((key, value) -> {
             // Each item into the map using the PooledObject object as the
@@ -1189,14 +1188,10 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
 
     @Override
     public Map<String, Integer> getNumActivePerKey() {
-        final HashMap<String, Integer> result = new HashMap<>();
-
-        poolMap.forEach((key, objectDequeue) -> {
-            result.put(key.toString(), Integer.valueOf(
-                objectDequeue.getAllObjects().size() -
-                objectDequeue.getIdleObjects().size()));
-        });
-        return result;
+        return poolMap.entrySet().stream().collect(Collectors.toMap(
+                e -> e.getKey().toString(),
+                e -> Integer.valueOf(e.getValue().getAllObjects().size() - e.getValue().getIdleObjects().size()),
+                (t, u) -> u));
     }
 
     @Override
@@ -1204,9 +1199,6 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
         return poolMap.values().stream().mapToInt(e -> e.getIdleObjects().size()).sum();
     }
 
-
-    //--- JMX support ----------------------------------------------------------
-
     @Override
     public int getNumIdle(final K key) {
         final ObjectDeque<T> objectDeque = poolMap.get(key);
@@ -1214,7 +1206,7 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     }
 
     /**
-     * Calculate the number of objects to test in a run of the idle object
+     * Gets the number of objects to test in a run of the idle object
      * evictor.
      *
      * @return The number of objects to test for validity
@@ -1229,7 +1221,7 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     }
 
     /**
-     * Return an estimate of the number of threads currently blocked waiting for
+     * Gets an estimate of the number of threads currently blocked waiting for
      * an object from the pool. This is intended for monitoring only, not for
      * synchronization control.
      *
@@ -1246,7 +1238,7 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     }
 
     /**
-     * Return an estimate of the number of threads currently blocked waiting for
+     * Gets an estimate of the number of threads currently blocked waiting for
      * an object from the pool for each key. This is intended for
      * monitoring only, not for synchronization control.
      *
@@ -1256,12 +1248,9 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     @Override
     public Map<String, Integer> getNumWaitersByKey() {
         final Map<String, Integer> result = new HashMap<>();
-
-        for (final Entry<K, ObjectDeque<T>> entry : poolMap.entrySet()) {
-            final K k = entry.getKey();
-            final ObjectDeque<T> deque = entry.getValue();
-            result.put(k.toString(), getBlockWhenExhausted() ? Integer.valueOf(deque.getIdleObjects().getTakeQueueLength()) : ZERO);
-        }
+        poolMap.forEach((k, deque) -> result.put(k.toString(), getBlockWhenExhausted() ?
+                Integer.valueOf(deque.getIdleObjects().getTakeQueueLength()) :
+                ZERO));
         return result;
     }
 
@@ -1274,7 +1263,7 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     }
 
     /**
-     * Checks to see if there are any threads currently waiting to borrow
+     * Tests to see if there are any threads currently waiting to borrow
      * objects but are blocked waiting for more objects to become available.
      *
      * @return {@code true} if there is at least one thread waiting otherwise
@@ -1351,7 +1340,6 @@ public class GenericKeyedObjectPool<K, T, E extends Exception> extends BaseGener
     @Override
     public Map<String, List<DefaultPooledObjectInfo>> listAllObjects() {
         final Map<String, List<DefaultPooledObjectInfo>> result = new HashMap<>();
-
         poolMap.forEach((k, v) -> result.put(k.toString(), v.getAllObjects().values().stream().map(DefaultPooledObjectInfo::new).collect(Collectors.toList())));
         return result;
     }
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
index 1e105cc2..006aeccf 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
@@ -18,7 +18,6 @@ package org.apache.commons.pool2.impl;
 
 import java.time.Duration;
 import java.util.ArrayList;
-import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -102,8 +101,7 @@ public class GenericObjectPool<T, E extends Exception> extends BaseGenericObject
      * #_maxActive}. Map keys are pooled objects, values are the PooledObject
      * wrappers used internally by the pool.
      */
-    private final Map<IdentityWrapper<T>, PooledObject<T>> allObjects =
-        new ConcurrentHashMap<>();
+    private final ConcurrentHashMap<IdentityWrapper<T>, PooledObject<T>> allObjects = new ConcurrentHashMap<>();
 
     /*
      * The combined count of the currently created objects and those in the


[commons-pool] 03/03: Bump pmd from 6.47.0 to 6.48.0.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 35e2d77e85315f2293734dbf7dca6177e427f8ce
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 7 09:37:22 2022 -0400

    Bump pmd from 6.47.0 to 6.48.0.
    
    Bump animal-sniffer-maven-plugin 1.20 to 1.21
---
 pom.xml                 | 4 ++--
 src/changes/changes.xml | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 463efa4b..1f74312d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,14 +187,14 @@
     <commons.jira.pid>12310488</commons.jira.pid>
     <commons.scmPubCheckoutDirectory>site-content</commons.scmPubCheckoutDirectory>
     <commons.osgi.import>net.sf.cglib.proxy;resolution:=optional,*</commons.osgi.import>
-    <commons.animal-sniffer.version>1.20</commons.animal-sniffer.version>
+    <commons.animal-sniffer.version>1.21</commons.animal-sniffer.version>
     <commons.checkstyle-plugin.version>3.1.2</commons.checkstyle-plugin.version>
     <commons.checkstyle.version>9.3</commons.checkstyle.version>
     <commons.felix.version>5.1.8</commons.felix.version>
     <spotbugs.plugin.version>4.7.1.1</spotbugs.plugin.version>
     <spotbugs.impl.version>4.7.1</spotbugs.impl.version>
     <commons.pmd.version>3.17.0</commons.pmd.version>
-    <commons.pmd-impl.version>6.47.0</commons.pmd-impl.version>
+    <commons.pmd-impl.version>6.48.0</commons.pmd-impl.version>
 
     <!-- Commons Release Plugin -->
     <commons.bc.version>2.11.1</commons.bc.version>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d1b4a026..d1ff0dec 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,7 +102,7 @@ The <action> type attribute can be add,update,fix,remove.
       Bump maven-pmd-plugin from 3.14.0 to 3.17.0 #101, #153.
     </action>
     <action dev="ggregory" type="update" due-to="Gary Gregory">
-      Bump pmd from 6.44.0 to 6.47.0.
+      Bump pmd from 6.44.0 to 6.48.0.
     </action>
     <action dev="ggregory" type="update" due-to="Dependabot">
       Bump biz.aQute.bndlib from 5.3.0 to 6.3.1 #105, #118, #135, #151, #154.
@@ -122,6 +122,9 @@ The <action> type attribute can be add,update,fix,remove.
     <action dev="ggregory" type="update" due-to="Gary Gregory">
       Bump japicmp-maven-plugin from 0.15.3 to 0.15.7.
     </action>
+    <action dev="ggregory" type="update" due-to="Gary Gregory">
+      Bump animal-sniffer-maven-plugin 1.20 to 1.21.
+    </action>
   </release>
   <release version="2.11.1" date="2021-08-18" description="This is a maintenance release (Java 8).">
     <!-- FIX -->