13.1. Connection Pooling

As shown in the Proxy example, the Connections.newFixedConnectionPool() returns a connection pool of the maximum size you specify.

final List<ConnectionFactory> factories = new LinkedList<~>();

factories.add(Connections.newFixedConnectionPool(Connections
        .newAuthenticatedConnectionFactory(Connections
                .newHeartBeatConnectionFactory(new LDAPConnectionFactory(
                        remoteAddress, remotePort)),
                        Requests.newSimpleBindRequest(proxyDN,
                                proxyPassword.toCharArray())),
                                Integer.MAX_VALUE));

Connections are returned to the pool when you close() them. Notice that Connections also provides methods to return ConnectionFactorys with a heart beat check on connections provided by the factory, and connection factories that authenticate connections before returning them.

Connections in the pool are intended for reuse. The Proxy gets an authenticated connection, which is a connection where the OpenDJ LDAP SDK passes a bind request immediately when getting the connection. The Proxy then uses proxied authorization to handle the identity from the client requesting the operation. As a rule, either handle binds separately and use proxied authorization as in the Proxy example, or else make sure that the first operation on a connection retrieved from the pool is a bind that correctly authenticates the user currently served by the connection.

When you close() a connection from the pool, the OpenDJ LDAP SDK does not perform an unbind(). This is why you must be careful about how you manage authentication on connections from a pool.