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