Class LdapPromiseImpl<S>
- java.lang.Object
-
- org.forgerock.opendj.ldap.spi.LdapPromiseImpl<S>
-
- Type Parameters:
S
- The type of result returned by this promise.
- All Implemented Interfaces:
LdapPromise<S>
,LdapResultHandler<S>
,ExceptionHandler<LdapException>
,Promise<S,LdapException>
,ResultHandler<S>
public final class LdapPromiseImpl<S> extends Object implements LdapPromise<S>, LdapResultHandler<S>
This class provides an implementation of theLdapPromise
.- See Also:
Promise
,Promises
,LdapPromise
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
cancel(boolean mayInterruptIfRunning)
Attempts to cancel the asynchronous task associated with thisPromise
.R
get()
Waits if necessary for thisPromise
to complete, and then returns the result if it completed successfully, or throws anExecutionException
containing the cause of the failure.R
get(long timeout, TimeUnit unit)
Waits if necessary for at most the given time for thisPromise
to complete, and then returns the result if it completed successfully, or throws anExecutionException
containing the cause of the failure.R
getOrThrow()
Waits if necessary for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.R
getOrThrow(long timeout, TimeUnit unit)
Waits if necessary for at most the given time for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.R
getOrThrowUninterruptibly()
Waits if necessary for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.R
getOrThrowUninterruptibly(long timeout, TimeUnit unit)
Waits if necessary for at most the given time for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.int
getRequestId()
Returns the request ID of the request if appropriate.void
handleException(LdapException exception)
Invoked when the asynchronous operation has failed.void
handleResult(S result)
Invoked when the asynchronous operation has completed successfully.boolean
isCancelled()
Returnstrue
if thisPromise
was cancelled before it completed normally.boolean
isDone()
Returnstrue
if thisPromise
has completed.boolean
isResult()
Returnstrue
if thisPromise
has completed and contains a value.static <S> LdapPromiseImpl<S>
newLdapPromiseImpl(int requestId)
Creates a newLdapPromiseImpl
with a requestId.<VOUT,EOUT extends Exception>
Promise<VOUT,EOUT>then(Function<? super R,VOUT,EOUT> onResult, Function<? super LdapException,VOUT,EOUT> onException)
Submits the provided functions for execution once thisPromise
has completed (with a result or an exception), and returns a newPromise
representing the outcome of the invoked function.<VOUT,EOUT extends Exception>
Promise<VOUT,EOUT>then(Function<? super R,VOUT,EOUT> onResult, Function<? super LdapException,VOUT,EOUT> onException, Function<? super RuntimeException,VOUT,EOUT> onRuntimeException)
Submits the provided functions for execution once thisPromise
has completed (with a result or an exception or aRuntimeException
), and returns a newPromise
representing the outcome of the invoked function.<VOUT> LdapPromise<VOUT>
then(Function<? super R,VOUT,LdapException> onResult)
Submits the provided function for execution once thisPromise
has completed with a result, and returns a newPromise
representing the outcome of the function.LdapPromise<R>
thenAlways(Runnable onResultOrException)
Submits the provided runnable for execution once thisPromise
has completed, and regardless of whether it has a result or an exception.<VOUT,EOUT extends Exception>
Promise<VOUT,EOUT>thenAsync(AsyncFunction<? super R,VOUT,EOUT> onResult, AsyncFunction<? super LdapException,VOUT,EOUT> onException)
Submits the provided asynchronous functions for execution once thisPromise
has completed, and returns a newPromise
representing the outcome of the invoked function.<VOUT,EOUT extends Exception>
Promise<VOUT,EOUT>thenAsync(AsyncFunction<? super R,VOUT,EOUT> onResult, AsyncFunction<? super LdapException,VOUT,EOUT> onException, AsyncFunction<? super RuntimeException,VOUT,EOUT> onRuntimeException)
Submits the provided asynchronous functions for execution once thisPromise
has completed, and returns a newPromise
representing the outcome of the invoked function.<VOUT> LdapPromise<VOUT>
thenAsync(AsyncFunction<? super R,VOUT,LdapException> onResult)
Submits the provided asynchronous function for execution once thisPromise
has completed with a result, and returns a newPromise
representing the outcome of the function.<EOUT extends Exception>
Promise<R,EOUT>thenCatch(Function<? super LdapException,R,EOUT> onException)
Submits the provided function for execution once thisPromise
has not completed with a result (has completed with an exception), and returns a newPromise
representing the outcome of the function.<EOUT extends Exception>
Promise<R,EOUT>thenCatchAsync(AsyncFunction<? super LdapException,R,EOUT> onException)
Submits the provided asynchronous function for execution once thisPromise
has completed with an exception, and returns a newPromise
representing the outcome of the function.Promise<R,LdapException>
thenCatchRuntimeException(Function<? super RuntimeException,R,LdapException> onRuntimeException)
Submits the provided function for execution once thisPromise
has not completed with a result nor with an exception but with aRuntimeException
, and returns a newPromise
representing the outcome of the function.Promise<R,LdapException>
thenCatchRuntimeExceptionAsync(AsyncFunction<? super RuntimeException,R,LdapException> onRuntimeException)
Submits the provided asynchronous function for execution once thisPromise
has completed with aRuntimeException
, and returns a newPromise
representing the outcome of the function.LdapPromise<R>
thenFinally(Runnable onResultOrException)
Submits the provided runnable for execution once thisPromise
has completed, and regardless of whether of its outcome.<T extends ResultHandler<? super R> & ExceptionHandler<? super LdapException> & RuntimeExceptionHandler>
Promise<R,LdapException>thenOnCompletion(T handler)
Registers the provided completion handler for notification for all completion cases of thisPromise
.LdapPromise<R>
thenOnException(ExceptionHandler<? super LdapException> onException)
Registers the provided completion handler for notification if thisPromise
cannot be completed due to an exception.LdapPromise<R>
thenOnResult(ResultHandler<? super R> onResult)
Registers the provided completion handler for notification once thisPromise
has completed with a result.LdapPromise<R>
thenOnResultOrException(Runnable onResultOrException)
Submits the provided runnable for execution once thisPromise
has completed, and regardless of whether it has a result or an exception.LdapPromise<R>
thenOnResultOrException(ResultHandler<? super R> onResult, ExceptionHandler<? super LdapException> onException)
Registers the provided completion handlers for notification once thisPromise
has completed (with a result or an exception).LdapPromise<R>
thenOnRuntimeException(RuntimeExceptionHandler onRuntimeException)
Registers the provided completion handler for notification if thisPromise
cannot be completed due to an runtime exception.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.forgerock.opendj.ldap.LdapPromise
getRequestId, then, thenAlways, thenAsync, thenFinally, thenOnException, thenOnResult, thenOnResultOrException, thenOnResultOrException
-
Methods inherited from interface org.forgerock.util.promise.Promise
cancel, get, get, getOrThrow, getOrThrow, getOrThrowIfInterrupted, getOrThrowUninterruptibly, getOrThrowUninterruptibly, isCancelled, isDone, isResult, then, then, thenAsync, thenAsync, thenCatch, thenCatchAsync, thenCatchRuntimeException, thenCatchRuntimeExceptionAsync, thenOnCompletion, thenOnRuntimeException
-
-
-
-
Method Detail
-
newLdapPromiseImpl
public static <S> LdapPromiseImpl<S> newLdapPromiseImpl(int requestId)
Creates a newLdapPromiseImpl
with a requestId.- Type Parameters:
S
- The type of result of the promise.- Parameters:
requestId
- Identifier of the request.- Returns:
- a new
LdapPromiseImpl
-
handleException
public void handleException(LdapException exception)
Description copied from interface:LdapResultHandler
Invoked when the asynchronous operation has failed.- Specified by:
handleException
in interfaceExceptionHandler<S>
- Specified by:
handleException
in interfaceLdapResultHandler<S>
- Parameters:
exception
- The error result exception indicating why the asynchronous operation has failed.
-
handleResult
public void handleResult(S result)
Description copied from interface:LdapResultHandler
Invoked when the asynchronous operation has completed successfully.- Specified by:
handleResult
in interfaceLdapResultHandler<S>
- Specified by:
handleResult
in interfaceResultHandler<S>
- Parameters:
result
- The result of the asynchronous operation.
-
getRequestId
public int getRequestId()
Description copied from interface:LdapPromise
Returns the request ID of the request if appropriate.- Specified by:
getRequestId
in interfaceLdapPromise<R>
- Returns:
- The request ID, or
-1
if there is no request ID.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
Description copied from interface:Promise
Attempts to cancel the asynchronous task associated with thisPromise
. Cancellation will fail if thisPromise
has already completed or has already been cancelled. If successful, then cancellation will complete thisPromise
with an appropriate exception and notify any registered functions and completion handlers.After this method returns, subsequent calls to
Promise.isDone()
will always returntrue
. Subsequent calls toPromise.isCancelled()
will always returntrue
if this method returnedtrue
.- Specified by:
cancel
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
mayInterruptIfRunning
-true
if the thread executing executing the response handler should be interrupted; otherwise, in-progress response handlers are allowed to complete.- Returns:
false
ifPromise
could not be cancelled, typically because it has already completed normally;true
otherwise.
-
get
public R get() throws ExecutionException, InterruptedException
Description copied from interface:Promise
Waits if necessary for thisPromise
to complete, and then returns the result if it completed successfully, or throws anExecutionException
containing the cause of the failure.- Specified by:
get
in interfacePromise<R,P extends Promise<R,LdapException>>
- Returns:
- The result, but only if this
Promise
completed successfully. - Throws:
ExecutionException
- If thisPromise
was cancelled or did not complete successfully. TheExecutionException
will contain the cause of the failure.InterruptedException
- If the current thread was interrupted while waiting.
-
get
public R get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException, InterruptedException
Description copied from interface:Promise
Waits if necessary for at most the given time for thisPromise
to complete, and then returns the result if it completed successfully, or throws anExecutionException
containing the cause of the failure.- Specified by:
get
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
timeout
- The maximum time to wait.unit
- The time unit of the timeout argument.- Returns:
- The result, but only if this
Promise
completed successfully. - Throws:
ExecutionException
- If thisPromise
was cancelled or did not complete successfully. TheExecutionException
will contain the cause of the failure.TimeoutException
- If the wait timed out.InterruptedException
- If the current thread was interrupted while waiting.
-
getOrThrow
public R getOrThrow() throws InterruptedException, LdapException
Description copied from interface:Promise
Waits if necessary for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.- Specified by:
getOrThrow
in interfacePromise<R,P extends Promise<R,LdapException>>
- Returns:
- The result, but only if this
Promise
completed successfully. - Throws:
InterruptedException
- If the current thread was interrupted while waiting.LdapException
-
getOrThrow
public R getOrThrow(long timeout, TimeUnit unit) throws InterruptedException, LdapException, TimeoutException
Description copied from interface:Promise
Waits if necessary for at most the given time for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.- Specified by:
getOrThrow
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
timeout
- The maximum time to wait.unit
- The time unit of the timeout argument.- Returns:
- The result, but only if this
Promise
completed successfully. - Throws:
InterruptedException
- If the current thread was interrupted while waiting.TimeoutException
- If the wait timed out.LdapException
-
getOrThrowUninterruptibly
public R getOrThrowUninterruptibly() throws LdapException
Description copied from interface:Promise
Waits if necessary for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.This method is similar to
Promise.getOrThrow()
except that it will ignore thread interrupts. When this method returns the status of the current thread will be interrupted if an interrupt was received while waiting.- Specified by:
getOrThrowUninterruptibly
in interfacePromise<R,P extends Promise<R,LdapException>>
- Returns:
- The result, but only if this
Promise
completed successfully. - Throws:
LdapException
-
getOrThrowUninterruptibly
public R getOrThrowUninterruptibly(long timeout, TimeUnit unit) throws LdapException, TimeoutException
Description copied from interface:Promise
Waits if necessary for at most the given time for thisPromise
to complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.This method is similar to
Promise.getOrThrow(long, TimeUnit)
except that it will ignore thread interrupts. When this method returns the status of the current thread will be interrupted if an interrupt was received while waiting.- Specified by:
getOrThrowUninterruptibly
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
timeout
- The maximum time to wait.unit
- The time unit of the timeout argument.- Returns:
- The result, but only if this
Promise
completed successfully. - Throws:
TimeoutException
- If the wait timed out.LdapException
-
isCancelled
public boolean isCancelled()
Description copied from interface:Promise
Returnstrue
if thisPromise
was cancelled before it completed normally.- Specified by:
isCancelled
in interfacePromise<R,P extends Promise<R,LdapException>>
- Returns:
true
if thisPromise
was cancelled before it completed normally, otherwisefalse
.
-
isDone
public boolean isDone()
Description copied from interface:Promise
Returnstrue
if thisPromise
has completed.Completion may be due to normal termination, an exception, or cancellation. In all of these cases, this method will return
true
.- Specified by:
isDone
in interfacePromise<R,P extends Promise<R,LdapException>>
- Returns:
true
if thisPromise
has completed, otherwisefalse
.
-
isResult
public boolean isResult()
Description copied from interface:Promise
Returnstrue
if thisPromise
has completed and contains a value.- Specified by:
isResult
in interfacePromise<R,P extends Promise<R,LdapException>>
- Returns:
true
if thisPromise
has completed with a value.
-
thenOnCompletion
public <T extends ResultHandler<? super R> & ExceptionHandler<? super LdapException> & RuntimeExceptionHandler> Promise<R,LdapException> thenOnCompletion(T handler)
Description copied from interface:Promise
Registers the provided completion handler for notification for all completion cases of thisPromise
.This method can be used for asynchronous completion notification.
- Specified by:
thenOnCompletion
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
T
- the composite type of the handler for handling all completion cases- Parameters:
handler
- The handler that will be called once thisPromise
is completed.- Returns:
- A
Promise
that is guaranteed to be completed once the provided callback has been executed.
-
thenOnException
public LdapPromise<R> thenOnException(ExceptionHandler<? super LdapException> onException)
Description copied from interface:Promise
Registers the provided completion handler for notification if thisPromise
cannot be completed due to an exception. If thisPromise
completes with a result then the completion handler will not be notified.This method can be used for asynchronous completion notification.
- Specified by:
thenOnException
in interfaceLdapPromise<R>
- Specified by:
thenOnException
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onException
- The completion handler which will be notified upon failure completion of thisPromise
.- Returns:
- A
Promise
that is guaranteed to be completed once the provided callback has been executed.
-
thenOnRuntimeException
public LdapPromise<R> thenOnRuntimeException(RuntimeExceptionHandler onRuntimeException)
Description copied from interface:Promise
Registers the provided completion handler for notification if thisPromise
cannot be completed due to an runtime exception. If thisPromise
completes with a result or the typed exception then the completion handler will not be notified.This method can be used for asynchronous completion notification.
- Specified by:
thenOnRuntimeException
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onRuntimeException
- The completion handler which will be notified upon an uncaught runtime exception completion of thisPromise
.- Returns:
- A
Promise
that is guaranteed to be completed once the provided callback has been executed.
-
thenOnResult
public LdapPromise<R> thenOnResult(ResultHandler<? super R> onResult)
Description copied from interface:Promise
Registers the provided completion handler for notification once thisPromise
has completed with a result. If thisPromise
completes with an exception then the completion handler will not be notified.This method can be used for asynchronous completion notification and is equivalent to
Promise.then(Function)
.- Specified by:
thenOnResult
in interfaceLdapPromise<R>
- Specified by:
thenOnResult
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onResult
- The completion handler which will be notified upon successful completion of thisPromise
.- Returns:
- A
Promise
that is guaranteed to be completed once the provided callback has been executed.
-
thenOnResultOrException
public LdapPromise<R> thenOnResultOrException(Runnable onResultOrException)
Description copied from interface:Promise
Submits the provided runnable for execution once thisPromise
has completed, and regardless of whether it has a result or an exception.This method can be used for resource cleanup after a series of asynchronous tasks have completed. More specifically, this method should be used in a similar manner to
finally
statements intry...catch
expressions.This method is equivalent to
Promise.thenAlways(Runnable)
.- Specified by:
thenOnResultOrException
in interfaceLdapPromise<R>
- Specified by:
thenOnResultOrException
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onResultOrException
- The runnable which will be notified regardless of the final outcome of thisPromise
.- Returns:
- A
Promise
that is guaranteed to be completed once the provided callback has been executed.
-
then
public <VOUT> LdapPromise<VOUT> then(Function<? super R,VOUT,LdapException> onResult)
Description copied from interface:Promise
Submits the provided function for execution once thisPromise
has completed with a result, and returns a newPromise
representing the outcome of the function. If thisPromise
does not complete with a result then the function will not be invoked and the exception will be forwarded to the returnedPromise
.This method can be used for transforming the result of an asynchronous task.
- Specified by:
then
in interfaceLdapPromise<R>
- Specified by:
then
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
VOUT
- The type of the function's result, orVoid
if the function does not return anything (i.e. it only has side-effects). Note that the type may be different to the type of thisPromise
.- Parameters:
onResult
- The function which will be executed upon successful completion of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the function.
-
then
public <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> then(Function<? super R,VOUT,EOUT> onResult, Function<? super LdapException,VOUT,EOUT> onException)
Description copied from interface:Promise
Submits the provided functions for execution once thisPromise
has completed (with a result or an exception), and returns a newPromise
representing the outcome of the invoked function. If thisPromise
completes with a result thenonResult
will be invoked with the result, otherwiseonException
will be invoked with the exception that occurred.This method can be used for transforming the outcome of an asynchronous task.
- Specified by:
then
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
VOUT
- The type of the functions' result, orVoid
if the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of thisPromise
.EOUT
- The type of the exception thrown by the functions if they fail, orNeverThrowsException
if they cannot fail. Note that the type may be different to the type of thisPromise
.- Parameters:
onResult
- The function which will be executed upon successful completion of thisPromise
.onException
- The function which will be executed upon failure of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the invoked function.
-
then
public <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> then(Function<? super R,VOUT,EOUT> onResult, Function<? super LdapException,VOUT,EOUT> onException, Function<? super RuntimeException,VOUT,EOUT> onRuntimeException)
Description copied from interface:Promise
Submits the provided functions for execution once thisPromise
has completed (with a result or an exception or aRuntimeException
), and returns a newPromise
representing the outcome of the invoked function. If thisPromise
completes with a result thenonResult
will be invoked with the result, with aRuntimeException
thenonRuntimeException
will be invoked with the runtime exception that occurred, otherwiseonException
will be invoked with the exception that occurred.This method can be used for transforming the outcome of an asynchronous task.
- Specified by:
then
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
VOUT
- The type of the functions' result, orVoid
if the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of thisPromise
.EOUT
- The type of the exception thrown by the functions if they fail, orNeverThrowsException
if they cannot fail. Note that the type may be different to the type of thisPromise
.- Parameters:
onResult
- The function which will be executed upon successful completion of thisPromise
.onException
- The function which will be executed upon failure of thisPromise
.onRuntimeException
- The function which will be executed upon failure withRuntimeException
of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the invoked function.
-
thenOnResultOrException
public LdapPromise<R> thenOnResultOrException(ResultHandler<? super R> onResult, ExceptionHandler<? super LdapException> onException)
Description copied from interface:Promise
Registers the provided completion handlers for notification once thisPromise
has completed (with a result or an exception). If thisPromise
completes with a result thenonResult
will be notified with the result, otherwiseonException
will be notified with the exception that occurred.This method can be used for asynchronous completion notification.
- Specified by:
thenOnResultOrException
in interfaceLdapPromise<R>
- Specified by:
thenOnResultOrException
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onResult
- The completion handler which will be notified upon completion with a result of thisPromise
.onException
- The completion handler which will be notified upon failure of thisPromise
.- Returns:
- A
Promise
that is guaranted to be completed once the provided callback has been executed.
-
thenAlways
public LdapPromise<R> thenAlways(Runnable onResultOrException)
Description copied from interface:Promise
Submits the provided runnable for execution once thisPromise
has completed, and regardless of whether it has a result or an exception.This method can be used for resource cleanup after a series of asynchronous tasks have completed. More specifically, this method should be used in a similar manner to
finally
statements intry...catch
expressions.This method is equivalent to
Promise.thenOnResultOrException(Runnable)
.- Specified by:
thenAlways
in interfaceLdapPromise<R>
- Specified by:
thenAlways
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onResultOrException
- The runnable which will be notified regardless of the final outcome of thisPromise
.- Returns:
- A
Promise
that is guaranteed to be completed once the provided callback has been executed.
-
thenAsync
public <VOUT> LdapPromise<VOUT> thenAsync(AsyncFunction<? super R,VOUT,LdapException> onResult)
Description copied from interface:Promise
Submits the provided asynchronous function for execution once thisPromise
has completed with a result, and returns a newPromise
representing the outcome of the function. If thisPromise
complete with an exception then the function will not be invoked and the error will be forwarded to the returnedPromise
.This method may be used for chaining together a series of asynchronous tasks.
- Specified by:
thenAsync
in interfaceLdapPromise<R>
- Specified by:
thenAsync
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
VOUT
- The type of the function's result, orVoid
if the function does not return anything (i.e. it only has side-effects). Note that the type may be different to the type of thisPromise
.- Parameters:
onResult
- The asynchronous function which will be executed upon successful completion of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the function.
-
thenAsync
public <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> thenAsync(AsyncFunction<? super R,VOUT,EOUT> onResult, AsyncFunction<? super LdapException,VOUT,EOUT> onException)
Description copied from interface:Promise
Submits the provided asynchronous functions for execution once thisPromise
has completed, and returns a newPromise
representing the outcome of the invoked function. If thisPromise
completes with a result thenonResult
will be invoked with the result, otherwiseonException
will be invoked with the exception that occurred.This method may be used for chaining together a series of asynchronous tasks.
- Specified by:
thenAsync
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
VOUT
- The type of the functions' result, orVoid
if the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of thisPromise
.EOUT
- The type of the exception thrown by the functions if they fail, orNeverThrowsException
if they cannot fail. Note that the type may be different to the type of thisPromise
.- Parameters:
onResult
- The asynchronous function which will be executed upon successful completion of thisPromise
.onException
- The asynchronous function which will be executed upon failure of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the invoked function.
-
thenAsync
public <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> thenAsync(AsyncFunction<? super R,VOUT,EOUT> onResult, AsyncFunction<? super LdapException,VOUT,EOUT> onException, AsyncFunction<? super RuntimeException,VOUT,EOUT> onRuntimeException)
Description copied from interface:Promise
Submits the provided asynchronous functions for execution once thisPromise
has completed, and returns a newPromise
representing the outcome of the invoked function. If thisPromise
completes with a result thenonResult
will be invoked with the result, otherwiseonException
will be invoked with the exception that occurred, oronRuntimeException
will be invoked with the runtime exception that occurred.This method may be used for chaining together a series of asynchronous tasks.
- Specified by:
thenAsync
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
VOUT
- The type of the functions' result, orVoid
if the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of thisPromise
.EOUT
- The type of the exception thrown by the functions if they fail, orNeverThrowsException
if they cannot fail. Note that the type may be different to the type of thisPromise
.- Parameters:
onResult
- The asynchronous function which will be executed upon successful completion of thisPromise
.onException
- The asynchronous function which will be executed upon failure of thisPromise
.onRuntimeException
- The asynchronous function which will be executed upon failure withRuntimeException
of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the invoked function.
-
thenCatch
public <EOUT extends Exception> Promise<R,EOUT> thenCatch(Function<? super LdapException,R,EOUT> onException)
Description copied from interface:Promise
Submits the provided function for execution once thisPromise
has not completed with a result (has completed with an exception), and returns a newPromise
representing the outcome of the function. If thisPromise
completes with a result then the function will not be invoked and the result notification will be forwarded to the returnedPromise
.This method can be used for transforming the result of an asynchronous task.
- Specified by:
thenCatch
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
EOUT
- The type of the exception thrown by the function if it fails, orNeverThrowsException
if it cannot fails. Note that the type may be different to the type of thisPromise
.- Parameters:
onException
- The function which will be executed upon failure completion of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the function.
-
thenCatchRuntimeException
public Promise<R,LdapException> thenCatchRuntimeException(Function<? super RuntimeException,R,LdapException> onRuntimeException)
Description copied from interface:Promise
Submits the provided function for execution once thisPromise
has not completed with a result nor with an exception but with aRuntimeException
, and returns a newPromise
representing the outcome of the function. If thisPromise
completes with a result or an exception then the function will not be invoked and the result notification will be forwarded to the returnedPromise
.This method can be used for transforming the result of an asynchronous task.
- Specified by:
thenCatchRuntimeException
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onRuntimeException
- The function which will be executed upon failure completion of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the function.
-
thenCatchRuntimeExceptionAsync
public Promise<R,LdapException> thenCatchRuntimeExceptionAsync(AsyncFunction<? super RuntimeException,R,LdapException> onRuntimeException)
Description copied from interface:Promise
Submits the provided asynchronous function for execution once thisPromise
has completed with aRuntimeException
, and returns a newPromise
representing the outcome of the function. If thisPromise
completes with a result or the typed exception then the completion asynchronous function will not be called.This method may be used for chaining together a series of asynchronous tasks.
- Specified by:
thenCatchRuntimeExceptionAsync
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onRuntimeException
- The asynchronous function which will be executed upon failure completion with aRuntimeException
of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the function.
-
thenFinally
public LdapPromise<R> thenFinally(Runnable onResultOrException)
Description copied from interface:Promise
Submits the provided runnable for execution once thisPromise
has completed, and regardless of whether of its outcome.This method can be used for resource cleanup after a series of asynchronous tasks have completed. More specifically, this method should be used in a similar manner to
finally
statements intry...catch
expressions.This method is equivalent to
Promise.thenAlways(Runnable)
.- Specified by:
thenFinally
in interfaceLdapPromise<R>
- Specified by:
thenFinally
in interfacePromise<R,P extends Promise<R,LdapException>>
- Parameters:
onResultOrException
- The runnable which will be notified regardless of the final outcome of thisPromise
.- Returns:
- A
Promise
that is guaranteed to be completed once the provided callback has been executed.
-
thenCatchAsync
public <EOUT extends Exception> Promise<R,EOUT> thenCatchAsync(AsyncFunction<? super LdapException,R,EOUT> onException)
Description copied from interface:Promise
Submits the provided asynchronous function for execution once thisPromise
has completed with an exception, and returns a newPromise
representing the outcome of the function. If thisPromise
completes with a result then the function will not be invoked and the exception will be forwarded to the returnedPromise
.This method may be used for chaining together a series of asynchronous tasks.
- Specified by:
thenCatchAsync
in interfacePromise<R,P extends Promise<R,LdapException>>
- Type Parameters:
EOUT
- The type of the exception thrown by the function if it fails, orNeverThrowsException
if it cannot fails. Note that the type may be different to the type of thisPromise
.- Parameters:
onException
- The asynchronous function which will be executed upon failure completion of thisPromise
.- Returns:
- A new
Promise
representing the outcome of the function.
-
-