Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AB4AF200BEB for ; Tue, 13 Dec 2016 21:37:43 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AA0D2160B23; Tue, 13 Dec 2016 20:37:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CBA13160B07 for ; Tue, 13 Dec 2016 21:37:42 +0100 (CET) Received: (qmail 48885 invoked by uid 500); 13 Dec 2016 20:37:42 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 48876 invoked by uid 99); 13 Dec 2016 20:37:42 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Dec 2016 20:37:42 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 7AAB93A00B7 for ; Tue, 13 Dec 2016 20:37:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1002748 - in /websites/staging/directory/trunk/content: ./ api/user-guide/2.1-connection-disconnection.html Date: Tue, 13 Dec 2016 20:37:41 -0000 To: commits@directory.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161213203741.7AAB93A00B7@svn01-us-west.apache.org> archived-at: Tue, 13 Dec 2016 20:37:43 -0000 Author: buildbot Date: Tue Dec 13 20:37:41 2016 New Revision: 1002748 Log: Staging update by buildbot for directory Modified: websites/staging/directory/trunk/content/ (props changed) websites/staging/directory/trunk/content/api/user-guide/2.1-connection-disconnection.html Propchange: websites/staging/directory/trunk/content/ ------------------------------------------------------------------------------ --- cms:source-revision (original) +++ cms:source-revision Tue Dec 13 20:37:41 2016 @@ -1 +1 @@ -1770592 +1774097 Modified: websites/staging/directory/trunk/content/api/user-guide/2.1-connection-disconnection.html ============================================================================== --- websites/staging/directory/trunk/content/api/user-guide/2.1-connection-disconnection.html (original) +++ websites/staging/directory/trunk/content/api/user-guide/2.1-connection-disconnection.html Tue Dec 13 20:37:41 2016 @@ -223,21 +223,47 @@ h2:hover > .headerlink, h3:hover > .head

Using a pool of connections

-

Creating a connection is expensive. If you are to reuse a connection over and over, or if you are writing an application that will need many LDAP conenctions, you may want to use a pool of connections.

-

This is slightly more complex than simply opening a new connection, as you have a lot of parametrs that can come into play when creating a pool. -Here is an example of creation of a pool of connections :

+

Creating a connection is expensive. If that connection will be reused, or if your application needs multiple connections, you may want to consider using a connection pool.

+

This process is slightly more complex given that there are many parameters that can be used to tune the pool. Here is an example:

LdapConnectionConfig config = new LdapConnectionConfig();
-config.setLdapHost( "localhost" );
-config.setLdapPort( 389 );
-config.setName( "uid=admin,ou=system" );
-config.setCredentials( "secret" );
-PoolableLdapConnectionFactory factory = new PoolableLdapConnectionFactory( config );
-LdapConnectionPool pool = new LdapConnectionPool( factory );
-pool.setTestOnBorrow( true );
+config.setLdapHost( hostname );
+config.setLdapPort( port );
+config.setName( adminDn );
+config.setCredentials( adminPassword );
+
+DefaultLdapConnectionFactory factory = new DefaultLdapConnectionFactory( config );
+factory.setTimeOut( connectionTimeout );
+
+// optional, values below are defaults
+GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
+poolConfig.lifo = true;
+poolConfig.maxActive = 8;
+poolConfig.maxIdle = 8;
+poolConfig.maxWait = -1L;
+poolConfig.minEvictableIdleTimeMillis = 1000L * 60L * 30L;
+poolConfig.minIdle = 0;
+poolConfig.numTestsPerEvictionRun = 3;
+poolConfig.softMinEvictableIdleTimeMillis = -1L;
+poolConfig.testOnBorrow = false;
+poolConfig.testOnReturn = false;
+poolConfig.testWhileIdle = false;
+poolConfig.timeBetweenEvictionRunsMillis = -1L;
+poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
+
+LdapConnectionPool pool = new LdapConnectionPool(
+    new DefaultPoolableLdapConnectionFactory( factory ), poolConfig ) );
+
+ + +

This will create a pool of connections that will be pre-authenticated. If you do not setName and setCredentials, then the pool will contain unauthenticated connections.

+

The DefaultPoolableLdapConnectionFactory is sufficient for many cases. However, certain operations result in modifications to the connection itself. For example, when the pool is created, a bind operation will occur with the credentials supplied as part of the config. If you borrow a connection and perform a bind yourself, that would result in the connection being re-bound as a different user. The next time that connection gets borrowed, things are likely to break. If you perform any operation that results in a modification of the connection, you should instead use ValidatingPoolableLdapConnectionFactory:

+
...
+PoolableLdapConnectionFactory factory = new ValidatingPoolableLdapConnectionFactory( config );
+...
 
-

Here, we just have created a pool of connections which all are unthenticated using the administrator user. You can create anonymous connections, it's just a matter of not setting any name or credentials in the config.

+

A connection pool using this factory will unbind and rebind any connection that was modified while it was borrowed (see the javadoc for more detail). This will be slower due to the additional operations, but not too significantly.