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 2019/10/06 23:21:18 UTC

[commons-pool] branch master updated (81ddcd7 -> 6598009)

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 81ddcd7  Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/commons-pool
     new 40e4649  Use lambdas.
     new c5328f9  Use final.
     new 6598009  Remove trailing white space.

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:
 .../org/apache/commons/pool2/PooledObject.java     |  4 +--
 .../apache/commons/pool2/PooledObjectState.java    |  2 +-
 .../apache/commons/pool2/impl/CallStackUtils.java  |  2 +-
 .../apache/commons/pool2/impl/EvictionTimer.java   |  9 ++---
 .../pool2/impl/SecurityManagerCallStack.java       |  7 +---
 .../org/apache/commons/pool2/TestPoolUtils.java    | 15 ++------
 .../pool2/impl/TestDefaultPooledObject.java        | 40 +++++++++-------------
 .../pool2/impl/TestGenericKeyedObjectPool.java     | 35 ++++++++-----------
 .../commons/pool2/impl/TestGenericObjectPool.java  | 13 +++----
 9 files changed, 47 insertions(+), 80 deletions(-)


[commons-pool] 01/03: Use lambdas.

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 40e4649b7f95aa2cb3f22daa3fd2e7ddcdc59ef1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 6 19:07:13 2019 -0400

    Use lambdas.
---
 .../apache/commons/pool2/impl/EvictionTimer.java   |  9 ++---
 .../pool2/impl/SecurityManagerCallStack.java       |  7 +---
 .../org/apache/commons/pool2/TestPoolUtils.java    | 15 ++------
 .../pool2/impl/TestDefaultPooledObject.java        | 40 +++++++++-------------
 .../pool2/impl/TestGenericKeyedObjectPool.java     | 29 +++++++---------
 .../commons/pool2/impl/TestGenericObjectPool.java  | 11 +++---
 6 files changed, 39 insertions(+), 72 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java b/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
index 8ab6435..9fa96d5 100644
--- a/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
+++ b/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
@@ -120,12 +120,9 @@ class EvictionTimer {
         public Thread newThread(final Runnable runnable) {
             final Thread thread = new Thread(null, runnable, "commons-pool-evictor-thread");
             thread.setDaemon(true); // POOL-363 - Required for applications using Runtime.addShutdownHook().
-            AccessController.doPrivileged(new PrivilegedAction<Void>() {
-                @Override
-                public Void run() {
-                    thread.setContextClassLoader(EvictorThreadFactory.class.getClassLoader());
-                    return null;
-                }
+            AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                thread.setContextClassLoader(EvictorThreadFactory.class.getClassLoader());
+                return null;
             });
 
             return thread;
diff --git a/src/main/java/org/apache/commons/pool2/impl/SecurityManagerCallStack.java b/src/main/java/org/apache/commons/pool2/impl/SecurityManagerCallStack.java
index f8c5eac..24aa014 100644
--- a/src/main/java/org/apache/commons/pool2/impl/SecurityManagerCallStack.java
+++ b/src/main/java/org/apache/commons/pool2/impl/SecurityManagerCallStack.java
@@ -52,12 +52,7 @@ public class SecurityManagerCallStack implements CallStack {
     public SecurityManagerCallStack(final String messageFormat, final boolean useTimestamp) {
         this.messageFormat = messageFormat;
         this.dateFormat = useTimestamp ? new SimpleDateFormat(messageFormat) : null;
-        this.securityManager = AccessController.doPrivileged(new PrivilegedAction<PrivateSecurityManager>() {
-            @Override
-            public PrivateSecurityManager run() {
-                return new PrivateSecurityManager();
-            }
-        });
+        this.securityManager = AccessController.doPrivileged((PrivilegedAction<PrivateSecurityManager>) () -> new PrivateSecurityManager());
     }
 
     @Override
diff --git a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
index 600374c..c06f77d 100644
--- a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
+++ b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
@@ -558,13 +558,7 @@ public class TestPoolUtils {
     @Test
     public void testErodingObjectPoolDefaultFactor() {
         try (@SuppressWarnings("unchecked")
-            final ObjectPool<Object> internalPool = createProxy(ObjectPool.class, new InvocationHandler() {
-
-            @Override
-            public Object invoke(final Object arg0, final Method arg1, final Object[] arg2) throws Throwable {
-                return null;
-            }
-        })) {
+            final ObjectPool<Object> internalPool = createProxy(ObjectPool.class, (arg0, arg1, arg2) -> null)) {
             final ObjectPool<Object> pool = PoolUtils.erodingPool(internalPool);
             final String expectedToString = "ErodingObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, pool="
                     + internalPool + "}";
@@ -686,12 +680,7 @@ public class TestPoolUtils {
     public void testErodingPoolKeyedObjectPoolDefaultFactor() {
         try (@SuppressWarnings("unchecked")
         final KeyedObjectPool<Object, Object> internalPool = createProxy(KeyedObjectPool.class,
-                new InvocationHandler() {
-                    @Override
-                    public Object invoke(final Object arg0, final Method arg1, final Object[] arg2) throws Throwable {
-                        return null;
-                    }
-                })) {
+                (arg0, arg1, arg2) -> null)) {
             final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(internalPool);
             final String expectedToString = "ErodingKeyedObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, keyedPool="
                     + internalPool + "}";
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java
index cba537a..b4f2a5e 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java
@@ -38,33 +38,27 @@ public class TestDefaultPooledObject {
         final AtomicBoolean negativeIdleTimeReturned = new AtomicBoolean(false);
         final ExecutorService executor = Executors.newFixedThreadPool(
                                       Runtime.getRuntime().availableProcessors()*3);
-        final Runnable allocateAndDeallocateTask = new Runnable() {
-            @Override
-            public void run() {
-                for (int i=0;i<10000;i++) {
-                    if (dpo.getIdleTimeMillis() < 0) {
-                        negativeIdleTimeReturned.set(true);
-                        break;
-                    }
+        final Runnable allocateAndDeallocateTask = () -> {
+            for (int i1=0;i1<10000;i1++) {
+                if (dpo.getIdleTimeMillis() < 0) {
+                    negativeIdleTimeReturned.set(true);
+                    break;
                 }
-                dpo.allocate();
-                for (int i=0;i<10000;i++) {
-                    if (dpo.getIdleTimeMillis() < 0) {
-                        negativeIdleTimeReturned.set(true);
-                        break;
-                    }
+            }
+            dpo.allocate();
+            for (int i2=0;i2<10000;i2++) {
+                if (dpo.getIdleTimeMillis() < 0) {
+                    negativeIdleTimeReturned.set(true);
+                    break;
                 }
-                dpo.deallocate();
             }
+            dpo.deallocate();
         };
-        final Runnable getIdleTimeTask = new Runnable() {
-            @Override
-            public void run() {
-                for (int i=0;i<10000;i++) {
-                    if (dpo.getIdleTimeMillis() < 0) {
-                        negativeIdleTimeReturned.set(true);
-                        break;
-                    }
+        final Runnable getIdleTimeTask = () -> {
+            for (int i=0;i<10000;i++) {
+                if (dpo.getIdleTimeMillis() < 0) {
+                    negativeIdleTimeReturned.set(true);
+                    break;
                 }
             }
         };
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
index d9247a7..9357e3d 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -35,7 +35,6 @@ import java.util.Random;
 import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -2004,23 +2003,19 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
             // Cause a thread to block waiting for an object
             final ExecutorService executorService = Executors.newSingleThreadExecutor(new DaemonThreadFactory());
             final Semaphore signal = new Semaphore(0);
-            final Future<Exception> result = executorService.submit(new Callable<Exception>() {
-
-                @Override
-                public Exception call() {
-                    try {
-                        signal.release();
-                        final Object object3 = pool.borrowObject(Integer.valueOf(1));
-                        pool.returnObject(Integer.valueOf(1), object3);
-                        signal.release();
-                    } catch (final Exception e) {
-                        return e;
-                    } catch (final Throwable e) {
-                        return new Exception(e);
-                    }
-
-                    return null;
+            final Future<Exception> result = executorService.submit(() -> {
+                try {
+                    signal.release();
+                    final Object object3 = pool.borrowObject(Integer.valueOf(1));
+                    pool.returnObject(Integer.valueOf(1), object3);
+                    signal.release();
+                } catch (final Exception e1) {
+                    return e1;
+                } catch (final Throwable e2) {
+                    return new Exception(e2);
                 }
+
+                return null;
             });
 
             // Wait for the thread to start
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
index 0b4509e..e93cc58 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
@@ -2748,14 +2748,11 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
         /*
          * A simple listener, that will throw a OOM on 3rd exception.
          */
-        final SwallowedExceptionListener listener = new SwallowedExceptionListener() {
-            @Override
-            public void onSwallowException(final Exception e) {
-                if (swallowedExceptions.size() == 2) {
-                    throw new OutOfMemoryError();
-                }
-                swallowedExceptions.add(e);
+        final SwallowedExceptionListener listener = e -> {
+            if (swallowedExceptions.size() == 2) {
+                throw new OutOfMemoryError();
             }
+            swallowedExceptions.add(e);
         };
         genericObjectPool.setSwallowedExceptionListener(listener);
 


[commons-pool] 02/03: Use final.

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 c5328f9ab2ec04af98aa3eac9a7bb5c35f75da87
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 6 19:07:54 2019 -0400

    Use final.
---
 src/main/java/org/apache/commons/pool2/PooledObject.java            | 2 +-
 .../org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java   | 6 +++---
 .../java/org/apache/commons/pool2/impl/TestGenericObjectPool.java   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/PooledObject.java b/src/main/java/org/apache/commons/pool2/PooledObject.java
index 142deca..9cac096 100644
--- a/src/main/java/org/apache/commons/pool2/PooledObject.java
+++ b/src/main/java/org/apache/commons/pool2/PooledObject.java
@@ -188,7 +188,7 @@ public interface PooledObject<T> extends Comparable<PooledObject<T>> {
      * @param requireFullStackTrace the new configuration setting for abandoned object logging
      * @since 2.7.0
      */
-    default void setRequireFullStackTrace(boolean requireFullStackTrace) {
+    default void setRequireFullStackTrace(final boolean requireFullStackTrace) {
         // noop
     }
 
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
index 9357e3d..509fbb6 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -2318,7 +2318,7 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
         gkoPool.setEvictionPolicy(new SlowEvictionPolicy<String>(1000));
 
         // Borrow an instance
-        String val = gkoPool.borrowObject("foo");
+        final String val = gkoPool.borrowObject("foo");
 
         // Add another idle one
         gkoPool.addObject("foo");
@@ -2352,7 +2352,7 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
          *
          * @param delay number of ms of latency to inject in evict
          */
-        public SlowEvictionPolicy(long delay) {
+        public SlowEvictionPolicy(final long delay) {
             super();
             this.delay = delay;
         }
@@ -2362,7 +2362,7 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
                 final int idleCount) {
             try {
                 Thread.sleep(delay);
-            } catch (InterruptedException e) {
+            } catch (final InterruptedException e) {
                 // ignore
             }
             return super.evict(config, underTest, idleCount);
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
index e93cc58..fa61f9f 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
@@ -2134,7 +2134,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool {
         genericObjectPool.setMaxTotal(1);
         genericObjectPool.setTestOnCreate(true);
         genericObjectPool.setMaxWaitMillis(-1);
-        String obj = genericObjectPool.borrowObject();
+        final String obj = genericObjectPool.borrowObject();
         // Make validation fail - this will cause create() to return null
         simpleFactory.setValid(false);
         // Create a take waiter


[commons-pool] 03/03: Remove trailing white space.

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 65980097be1861a495512b49ffff826a1073bde7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 6 19:08:33 2019 -0400

    Remove trailing white space.
---
 src/main/java/org/apache/commons/pool2/PooledObject.java        | 2 +-
 src/main/java/org/apache/commons/pool2/PooledObjectState.java   | 2 +-
 src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/PooledObject.java b/src/main/java/org/apache/commons/pool2/PooledObject.java
index 9cac096..d39b0a3 100644
--- a/src/main/java/org/apache/commons/pool2/PooledObject.java
+++ b/src/main/java/org/apache/commons/pool2/PooledObject.java
@@ -59,7 +59,7 @@ public interface PooledObject<T> extends Comparable<PooledObject<T>> {
 
     /**
      * Gets the number of times this object has been borrowed.
-     * 
+     *
      * @return -1 by default for old implementations prior to release 2.7.0.
      * @since 2.7.0
      */
diff --git a/src/main/java/org/apache/commons/pool2/PooledObjectState.java b/src/main/java/org/apache/commons/pool2/PooledObjectState.java
index 68fa3b4..d10a9f3 100644
--- a/src/main/java/org/apache/commons/pool2/PooledObjectState.java
+++ b/src/main/java/org/apache/commons/pool2/PooledObjectState.java
@@ -22,7 +22,7 @@ package org.apache.commons.pool2;
  * @since 2.0
  */
 public enum PooledObjectState {
-    
+
     /**
      * In the queue, not in use.
      */
diff --git a/src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java b/src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java
index eaf58fb..c1bff0a 100644
--- a/src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java
+++ b/src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java
@@ -27,7 +27,7 @@ public final class CallStackUtils {
 
     /**
      * Returns whether the caller can create a security manager in the current environment.
-     * 
+     *
      * @return {@code true} if it is able to create a security manager in the current environment, {@code false}
      *         otherwise.
      */