Class ConnectionPool

java.lang.Object
org.forgerock.opendj.ldap.ConnectionPool
All Implemented Interfaces:
Closeable, AutoCloseable, LdapClient

public final class ConnectionPool extends Object implements LdapClient
A connection pool which maintains a cache of client sockets with a configurable core pool size, maximum size, and expiration policy.

When connection pool is no longer needed it must be explicitly closed in order to close any remaining pooled connections.

Since pooled connections are re-used, applications must use operations such as binds and StartTLS with extreme caution.

Trying to get a connection when the pool has no connection available, will delegate the connection request to the provided LdapClient unless the maximum number of connection configured for the pool is reached. At which point the connection request will be queued for a maximum duration of LdapClients.CONNECT_TIMEOUT seconds before being aborted with a TimeoutResultException if the requests have not been fulfilled by the release of a connection to the pool.

Effectively, receiving ResultCode.CLIENT_SIDE_CONNECT_ERROR as a result of a connection request could be the sign of an undersized connection pool.

See Also:
  • Method Details

    • close

      public void close()
      Releases any resources associated with this connection pool. Pooled connections will be permanently closed and this connection pool will no longer be available for use.

      Attempts to use this connection pool after it has been closed will result in an IllegalStateException.

      Calling close on a connection pool which is already closed has no effect.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface LdapClient
    • connect

      public Single<LdapClientSocket> connect()
      Description copied from interface: LdapClient
      Returns a Single which connects to a peer each time it is subscribed.
      Specified by:
      connect in interface LdapClient
      Returns:
      A Single which connects to a peer each time it is subscribed.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • finalize

      protected void finalize()
      Provide a finalizer because connection pools are expensive resources to accidentally leave around. Also, since they won't be created all that frequently, there's little risk of overloading the finalizer.
      Overrides:
      finalize in class Object
    • getStatistics

      public ConnectionPool.Statistics getStatistics()
      Retrieves the statistics for this connection pool.
      Returns:
      the statistics for this connection pool