001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2014 ForgeRock AS
026 */
027
028package org.forgerock.opendj.ldap;
029
030/**
031 * A handler interface for accepting new connections from clients.
032 * <p>
033 * A connection listener implementation, such as {@link LDAPListener} or
034 * {@link Connections#newInternalConnectionFactory newInternalConnectionFactory}
035 * , invoke the method {@link #handleAccept(Object) handleAccept} whenever a new
036 * client connection is accepted.
037 *
038 * @param <C>
039 *            The type of client context.
040 * @param <R>
041 *            The type of request context.
042 * @see LDAPListener
043 * @see Connections#newInternalConnectionFactory(ServerConnectionFactory,
044 *      Object) newInternalConnectionFactory
045 */
046public interface ServerConnectionFactory<C, R> {
047    /**
048     * Invoked when a new client connection is accepted by the associated
049     * listener. Implementations should return a {@code ServerConnection} which
050     * will be used to handle requests from the client connection.
051     *
052     * @param clientContext
053     *            The protocol dependent context information associated with the
054     *            client connection. Depending on the protocol this may contain
055     *            information about the client such as their address and level
056     *            connection security. It may also be used to manage the state
057     *            of the client's connection.
058     * @return A {@code ServerConnection} which will be used to handle requests
059     *         from a client connection.
060     * @throws LdapException
061     *             If this server connection factory cannot accept the client
062     *             connection.
063     */
064    ServerConnection<R> handleAccept(C clientContext) throws LdapException;
065}