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 2009 Sun Microsystems, Inc.
025 *      Portions copyright 2014-2015 ForgeRock AS
026 */
027
028package org.forgerock.opendj.ldap;
029
030import org.forgerock.util.AsyncFunction;
031import org.forgerock.util.promise.ExceptionHandler;
032import org.forgerock.util.Function;
033import org.forgerock.util.promise.Promise;
034import org.forgerock.util.promise.ResultHandler;
035
036/**
037 * A handle which can be used to retrieve the Result of an asynchronous Request.
038 *
039 * @param <S>
040 *            The type of result returned by this promise.
041 */
042public interface LdapPromise<S> extends Promise<S, LdapException> {
043    /**
044     * Returns the request ID of the request if appropriate.
045     *
046     * @return The request ID, or {@code -1} if there is no request ID.
047     */
048    int getRequestID();
049
050    @Override
051    LdapPromise<S> thenOnResult(ResultHandler<? super S> onResult);
052
053    @Override
054    LdapPromise<S> thenOnException(ExceptionHandler<? super LdapException> onException);
055
056    @Override
057    LdapPromise<S> thenOnResultOrException(Runnable onResultOrException);
058
059    @Override
060    // @Checkstyle:ignore
061    <VOUT> LdapPromise<VOUT> then(Function<? super S, VOUT, LdapException> onResult);
062
063    @Override
064    LdapPromise<S> thenOnResultOrException(ResultHandler<? super S> onResult,
065                                           ExceptionHandler<? super LdapException> onException);
066
067    @Override
068    LdapPromise<S> thenAlways(Runnable onResultOrException);
069
070    @Override
071    // @Checkstyle:ignore
072    <VOUT> LdapPromise<VOUT> thenAsync(AsyncFunction<? super S, VOUT, LdapException> onResult);
073}