directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [directory-ldap-api] branch master updated: Migrated to commons-pool 2.5.0
Date Fri, 18 May 2018 09:06:05 GMT
This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new c895bd2  Migrated to commons-pool 2.5.0
c895bd2 is described below

commit c895bd2d4000049be550a71dd512d1fc3e815c07
Author: Emmanuel L├ęcharny <elecharny@symas.com>
AuthorDate: Fri May 18 11:06:01 2018 +0200

    Migrated to commons-pool 2.5.0
---
 .../api/osgi/ApiLdapClientApiOsgiTest.java         |  8 +++----
 ldap/client/api/pom.xml                            |  8 +++----
 .../api/AbstractPoolableLdapConnectionFactory.java | 26 ++++++++++++----------
 .../ldap/client/api/LdapConnectionPool.java        | 19 +++++++---------
 .../ValidatingPoolableLdapConnectionFactory.java   | 17 +++++++++-----
 ...alidatingPoolableLdapConnectionFactoryTest.java |  2 +-
 pom.xml                                            |  6 ++---
 7 files changed, 46 insertions(+), 40 deletions(-)

diff --git a/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapClientApiOsgiTest.java
b/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapClientApiOsgiTest.java
index b722ee8..bbcd73b 100644
--- a/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapClientApiOsgiTest.java
+++ b/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapClientApiOsgiTest.java
@@ -20,8 +20,8 @@
 package org.apache.directory.api.osgi;
 
 
-import org.apache.commons.pool.PoolableObjectFactory;
-import org.apache.commons.pool.impl.GenericObjectPool.Config;
+import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.directory.ldap.client.api.DefaultPoolableLdapConnectionFactory;
 import org.apache.directory.ldap.client.api.Krb5LoginConfiguration;
 import org.apache.directory.ldap.client.api.LdapConnection;
@@ -56,9 +56,9 @@ public class ApiLdapClientApiOsgiTest extends ApiOsgiTestBase
         FilterBuilder.and( FilterBuilder.not( FilterBuilder.contains( "cn", "a", "b" ) )
).toString();
 
         // Test for DIRAPI-239
-        PoolableObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(
+        PooledObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(
             new LdapConnectionConfig() );
-        Config config = new Config();
+        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
         LdapConnectionPool ldapConnectionPool = new LdapConnectionPool( factory, config );
         ldapConnectionPool.getLdapApiService();
         ldapConnectionPool.getTestOnBorrow();
diff --git a/ldap/client/api/pom.xml b/ldap/client/api/pom.xml
index 7a32f50..69bdeae 100644
--- a/ldap/client/api/pom.xml
+++ b/ldap/client/api/pom.xml
@@ -74,8 +74,8 @@
     </dependency>
 
     <dependency>
-      <groupId>commons-pool</groupId>
-      <artifactId>commons-pool</artifactId>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-pool2</artifactId>
     </dependency>
    
     <dependency>
@@ -146,8 +146,8 @@
               org.apache.directory.ldap.client.template.exception;version=${project.version};-noimport:=true
             </Export-Package>
             <Import-Package>
-              org.apache.commons.pool;version=${commons.pool.version},
-              org.apache.commons.pool.impl;version=${commons.pool.version},
+              org.apache.commons.pool2;version=${commons.pool.version},
+              org.apache.commons.pool2.impl;version=${commons.pool.version},
               org.apache.directory.api.asn1;version=${project.version},
               org.apache.directory.api.asn1.util;version=${project.version},
               org.apache.directory.api.i18n;version=${project.version},
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractPoolableLdapConnectionFactory.java
b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractPoolableLdapConnectionFactory.java
index acebc44..542b616 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractPoolableLdapConnectionFactory.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractPoolableLdapConnectionFactory.java
@@ -23,7 +23,9 @@ package org.apache.directory.ldap.client.api;
 
 import java.lang.reflect.Constructor;
 
-import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.slf4j.Logger;
@@ -35,7 +37,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public abstract class AbstractPoolableLdapConnectionFactory implements PoolableObjectFactory<LdapConnection>
+public abstract class AbstractPoolableLdapConnectionFactory implements PooledObjectFactory<LdapConnection>
 {
     /** This class logger */
     private static final Logger LOG = LoggerFactory.getLogger( AbstractPoolableLdapConnectionFactory.class
);
@@ -52,21 +54,21 @@ public abstract class AbstractPoolableLdapConnectionFactory implements
PoolableO
      * There is nothing to do to activate a connection.
      */
     @Override
-    public void activateObject( LdapConnection connection ) throws LdapException
+    public void activateObject( PooledObject<LdapConnection> connection ) throws LdapException
     {
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Activating {}", connection );
         }
         
-        if ( !connection.isConnected() || !connection.isAuthenticated() )
+        if ( !connection.getObject().isConnected() || !connection.getObject().isAuthenticated()
)
         {
             if ( LOG.isDebugEnabled() )
             {
                 LOG.debug( "rebind due to connection dropped on {}", connection );
             }
             
-            connectionFactory.bindConnection( connection );
+            connectionFactory.bindConnection( connection.getObject() );
         }
     }
 
@@ -78,7 +80,7 @@ public abstract class AbstractPoolableLdapConnectionFactory implements PoolableO
      * of teh underlying protocol.
      */
     @Override
-    public void destroyObject( LdapConnection connection ) throws LdapException
+    public void destroyObject( PooledObject<LdapConnection> connection ) throws LdapException
     {
         if ( LOG.isDebugEnabled() )
         {
@@ -89,7 +91,7 @@ public abstract class AbstractPoolableLdapConnectionFactory implements PoolableO
         {
             // https://tools.ietf.org/html/rfc2251#section-4.3
             // unbind closes the connection so no need to close
-            connection.unBind();
+            connection.getObject().unBind();
         }
         catch ( LdapException e )
         {
@@ -122,14 +124,14 @@ public abstract class AbstractPoolableLdapConnectionFactory implements
PoolableO
      * @throws LdapException If unable to connect.
      */
     @Override
-    public LdapConnection makeObject() throws LdapException
+    public PooledObject<LdapConnection> makeObject() throws LdapException
     {
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Creating a LDAP connection" );
         }
         
-        return connectionFactory.newLdapConnection();
+        return new DefaultPooledObject<>( connectionFactory.newLdapConnection() );
     }
 
 
@@ -159,7 +161,7 @@ public abstract class AbstractPoolableLdapConnectionFactory implements
PoolableO
      * @throws LdapException If unable to reconfigure and rebind.
      */
     @Override
-    public void passivateObject( LdapConnection connection ) throws LdapException
+    public void passivateObject( PooledObject<LdapConnection> connection ) throws LdapException
     {
         if ( LOG.isDebugEnabled() )
         {
@@ -194,13 +196,13 @@ public abstract class AbstractPoolableLdapConnectionFactory implements
PoolableO
      * Validating a connection is done by checking the connection status.
      */
     @Override
-    public boolean validateObject( LdapConnection connection )
+    public boolean validateObject( PooledObject<LdapConnection> connection )
     {
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Validating {}", connection );
         }
         
-        return validator.validate( connection );
+        return validator.validate( connection.getObject() );
     }
 }
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionPool.java
b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionPool.java
index 442f5cc..abc9b14 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionPool.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionPool.java
@@ -21,8 +21,9 @@
 package org.apache.directory.ldap.client.api;
 
 
-import org.apache.commons.pool.PoolableObjectFactory;
-import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.slf4j.Logger;
@@ -41,7 +42,7 @@ public class LdapConnectionPool extends GenericObjectPool<LdapConnection>
 {
     private static final Logger LOG = LoggerFactory.getLogger( LdapConnectionPool.class );
 
-    private PoolableObjectFactory<LdapConnection> factory;
+    private PooledObjectFactory<LdapConnection> factory;
 
 
     /**
@@ -67,7 +68,7 @@ public class LdapConnectionPool extends GenericObjectPool<LdapConnection>
      * @param poolConfig The pool configuration
      */
     public LdapConnectionPool( LdapConnectionConfig connectionConfig,
-        LdapApiService apiService, long timeout, Config poolConfig )
+        LdapApiService apiService, long timeout, GenericObjectPoolConfig poolConfig )
     {
         this( newPoolableConnectionFactory( connectionConfig, apiService, timeout ), poolConfig
);
     }
@@ -78,7 +79,7 @@ public class LdapConnectionPool extends GenericObjectPool<LdapConnection>
      *
      * @param factory The LDAP connection factory
      */
-    public LdapConnectionPool( PoolableObjectFactory<LdapConnection> factory )
+    public LdapConnectionPool( PooledObjectFactory<LdapConnection> factory )
     {
         this( factory, null );
     }
@@ -90,9 +91,9 @@ public class LdapConnectionPool extends GenericObjectPool<LdapConnection>
      * @param factory The LDAP connection factory
      * @param poolConfig The pool configuration
      */
-    public LdapConnectionPool( PoolableObjectFactory<LdapConnection> factory, Config
poolConfig )
+    public LdapConnectionPool( PooledObjectFactory<LdapConnection> factory, GenericObjectPoolConfig
poolConfig )
     {
-        super( factory, poolConfig == null ? new Config() : poolConfig );
+        super( factory, poolConfig == null ? new GenericObjectPoolConfig() : poolConfig );
         this.factory = factory;
     }
 
@@ -173,10 +174,6 @@ public class LdapConnectionPool extends GenericObjectPool<LdapConnection>
                 LOG.trace( "returned connection {}", connection );
             }
         }
-        catch ( LdapException e )
-        {
-            throw e;
-        }
         catch ( Exception e )
         {
             // wrap in runtime, but this should NEVER happen as it only throws 
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactory.java
b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactory.java
index b75114e..8f43259 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactory.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactory.java
@@ -21,6 +21,8 @@
 package org.apache.directory.ldap.client.api;
 
 
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
 import org.apache.directory.api.asn1.util.Oid;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.message.BindRequest;
@@ -109,14 +111,16 @@ public class ValidatingPoolableLdapConnectionFactory extends AbstractPoolableLda
      * There is nothing to do to activate a connection.
      */
     @Override
-    public void activateObject( LdapConnection connection ) throws LdapException
+    public void activateObject( PooledObject<LdapConnection> pooledObject ) throws
LdapException
     {
+        LdapConnection connection = pooledObject.getObject();
+        
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Activating {}", connection );
         }
         
-        super.activateObject( connection );
+        super.activateObject( pooledObject );
 
         // clear the monitors
         ( ( MonitoringLdapConnection ) connection ).resetMonitors();
@@ -132,14 +136,14 @@ public class ValidatingPoolableLdapConnectionFactory extends AbstractPoolableLda
      * @throws LdapException If unable to connect.
      */
     @Override
-    public MonitoringLdapConnection makeObject() throws LdapException
+    public PooledObject<LdapConnection> makeObject() throws LdapException
     {
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Creating a LDAP connection" );
         }
         
-        return new MonitoringLdapConnection( connectionFactory.newLdapConnection() );
+        return new DefaultPooledObject<LdapConnection>( new MonitoringLdapConnection(
connectionFactory.newLdapConnection() ) );
     }
 
 
@@ -152,8 +156,10 @@ public class ValidatingPoolableLdapConnectionFactory extends AbstractPoolableLda
      * @throws LdapException If unable to reconfigure and rebind.
      */
     @Override
-    public void passivateObject( LdapConnection connection ) throws LdapException
+    public void passivateObject( PooledObject<LdapConnection> pooledObject ) throws
LdapException
     {
+        LdapConnection connection = pooledObject.getObject();
+
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Passivating {}", connection );
@@ -169,6 +175,7 @@ public class ValidatingPoolableLdapConnectionFactory extends AbstractPoolableLda
             
             connectionFactory.bindConnection( connection );
         }
+        
         if ( ( ( MonitoringLdapConnection ) connection ).startTlsCalled() )
         {
             if ( LOG.isDebugEnabled() )
diff --git a/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactoryTest.java
b/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactoryTest.java
index 3b2ab17..a812833 100755
--- a/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactoryTest.java
+++ b/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/ValidatingPoolableLdapConnectionFactoryTest.java
@@ -503,7 +503,7 @@ public class ValidatingPoolableLdapConnectionFactoryTest
             poolableFactory.setValidator( validator );
 
             pool = new LdapConnectionPool( poolableFactory );
-            pool.setMaxActive( 1 );
+            pool.setMaxTotal( 1 );
             pool.setTestOnBorrow( true );
             pool.setTestOnReturn( true );
         }
diff --git a/pom.xml b/pom.xml
index 798f0ee..51b5423 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,7 +49,7 @@
     <commons.codec.version>1.11</commons.codec.version>
     <commons.collections.version>3.2.2</commons.collections.version>
     <commons.lang.version>2.6</commons.lang.version>
-    <commons.pool.version>1.6</commons.pool.version>
+    <commons.pool.version>2.5.0</commons.pool.version>
     <dom4j.version>1.6.1</dom4j.version>
     <findbugs.annotations.version>1.0.0</findbugs.annotations.version>
     <forbiddenapis.version>2.2</forbiddenapis.version>
@@ -484,8 +484,8 @@
       </dependency>
 
       <dependency>
-        <groupId>commons-pool</groupId>
-        <artifactId>commons-pool</artifactId>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-pool2</artifactId>
         <version>${commons.pool.version}</version>
       </dependency>
 

-- 
To stop receiving notification emails like this one, please contact
elecharny@apache.org.

Mime
View raw message