001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2013-2015 ForgeRock AS.
015 */
016package org.forgerock.opendj.ldap.spi;
017
018import java.io.Closeable;
019import java.net.InetSocketAddress;
020
021import org.forgerock.opendj.ldap.LdapException;
022import org.forgerock.util.promise.Promise;
023
024/**
025 * Interface for all classes that implement {@code LDAPConnectionFactory}.
026 * <p>
027 * An implementation class is provided by a {@code TransportProvider}.
028 * <p>
029 * The implementation can be automatically loaded using the
030 * {@code java.util.ServiceLoader} facility if its provider extending
031 * {@code TransportProvider} is declared in the provider-configuration file
032 * {@code META-INF/services/org.forgerock.opendj.ldap.spi.TransportProvider}.
033 */
034public interface LDAPConnectionFactoryImpl extends Closeable {
035
036    /**
037     * Returns the address used by the connections created by this factory.
038     *
039     * @return The address used by the connections.
040     */
041    InetSocketAddress getSocketAddress();
042
043    /**
044     * Returns the hostname used by the connections created by this factory.
045     *
046     * @return The hostname used by the connections.
047     */
048    String getHostName();
049
050    /**
051     * Returns the remote port number used by the connections created by this factory.
052     *
053     * @return The remote port number used by the connections.
054     */
055    int getPort();
056
057    /**
058     * Releases any resources associated with this connection factory implementation.
059     */
060    @Override
061    void close();
062
063    /**
064     * Asynchronously obtains a connection to the Directory Server associated
065     * with this connection factory. The returned {@code Promise} can be used to
066     * retrieve the completed connection.
067     *
068     * @return A promise which can be used to retrieve the connection.
069     */
070    Promise<LDAPConnectionImpl, LdapException> getConnectionAsync();
071}