Interface ConnectionFactory

  • All Superinterfaces:
    AutoCloseable, Closeable
    All Known Implementing Classes:
    LdapConnectionFactory

    public interface ConnectionFactory
    extends Closeable
    A connection factory provides an interface for obtaining a connection to a Directory Server. Connection factories can be used to wrap other connection factories in order to provide enhanced capabilities in a manner which is transparent to the application. For example:
    • Connection pooling
    • Load balancing
    • Keep alive
    • Transactional connections
    • Connections to LDIF files
    • Data transformations
    • Logging connections
    • Read-only connections
    • Pre-authenticated connections
    • Recording connections, with primitive roll-back functionality
    An application typically obtains a connection from a connection factory, performs one or more operations, and then closes the connection. Applications should aim to close connections as soon as possible in order to avoid resource contention.
    • Method Detail

      • close

        void close()
        Releases any resources associated with this connection factory. Depending on the implementation a factory may:
        • do nothing
        • close underlying connection factories (e.g. load-balancers)
        • close pooled connections (e.g. connection pools)
        • shutdown IO event service and related thread pools.
        Calling close on a connection factory which is already closed has no effect.

        Applications should avoid closing connection factories while there are remaining active connections in use or connection attempts in progress.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        See Also:
        Connections.uncloseable(ConnectionFactory)
      • getConnectionAsync

        Promise<Connection,​LdapException> getConnectionAsync()
        Asynchronously obtains a connection to the Directory Server associated with this connection factory. The returned Promise can be used to retrieve the completed connection.
        Returns:
        A promise which can be used to retrieve the connection.
      • getConnection

        Connection getConnection()
                          throws LdapException
        Returns a connection to the Directory Server associated with this connection factory. The connection returned by this method can be used immediately.

        If the calling thread is interrupted while waiting for the connection attempt to complete then the calling thread unblock and throw a CancelledResultException whose cause is the underlying InterruptedException.

        Returns:
        A connection to the Directory Server associated with this connection factory.
        Throws:
        LdapException - If the connection request failed for some reason.