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 2009 Sun Microsystems, Inc.
015 * Portions Copyright 2011-2015 ForgeRock AS.
016 */
017
018package org.forgerock.opendj.ldap;
019
020import org.forgerock.util.promise.ExceptionHandler;
021import org.forgerock.util.promise.ResultHandler;
022
023/**
024 * A completion handler for consuming the result of an asynchronous operation or
025 * connection attempts.
026 * <p>
027 * A result completion handler may be specified when performing asynchronous
028 * operations using a {@link Connection} object or when connecting
029 * asynchronously to a remote Directory Server using an
030 * {@link ConnectionFactory}. The {@link #handleResult} method is invoked when
031 * the operation or connection attempt completes successfully. The
032 * {@link #handleException(LdapException)} method is invoked if the operation or connection
033 * attempt fails.
034 * <p>
035 * Implementations of these methods should complete in a timely manner so as to
036 * avoid keeping the invoking thread from dispatching to other completion
037 * handlers.
038 *
039 * @param <S>
040 *            The type of result handled by this result handler.
041 */
042public interface LdapResultHandler<S> extends ResultHandler<S>, ExceptionHandler<LdapException> {
043    /**
044     * Invoked when the asynchronous operation has failed.
045     *
046     * @param exception
047     *            The error result exception indicating why the asynchronous
048     *            operation has failed.
049     */
050    @Override
051    void handleException(LdapException exception);
052
053    /**
054     * Invoked when the asynchronous operation has completed successfully.
055     *
056     * @param result
057     *            The result of the asynchronous operation.
058     */
059    @Override
060    void handleResult(S result);
061}