S
- The type of result returned by this promise.public final class LdapPromiseImpl<S> extends Object implements LdapPromise<S>, LdapResultHandler<S>
LdapPromise
.Promise
,
Promises
,
LdapPromise
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Attempts to cancel the asynchronous task associated with this
Promise . |
R |
get()
Waits if necessary for this
Promise to complete, and then returns
the result if it completed successfully, or throws an
ExecutionException containing the cause of the failure. |
R |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for this
Promise to
complete, and then returns the result if it completed successfully, or
throws an ExecutionException containing the cause of the failure. |
R |
getOrThrow()
Waits if necessary for this
Promise 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 this
Promise 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 this
Promise 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 this
Promise 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()
Returns
true if this Promise was cancelled before it
completed normally. |
boolean |
isDone()
Returns
true if this Promise has completed. |
boolean |
isResult()
Returns
true if this Promise has completed and contains a value. |
static <S> LdapPromiseImpl<S> |
newLdapPromiseImpl(int requestId)
Creates a new
LdapPromiseImpl with a requestId. |
<VOUT,EOUT extends Exception> |
then(Function<? super R,VOUT,EOUT> onResult,
Function<? super LdapException,VOUT,EOUT> onException)
Submits the provided functions for execution once this
Promise
has completed (with a result or an exception), and returns a new
Promise representing the outcome of the invoked function. |
<VOUT,EOUT extends Exception> |
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 this
Promise
has completed (with a result or an exception or a RuntimeException ), and returns a new
Promise representing the outcome of the invoked function. |
<VOUT> LdapPromise<VOUT> |
then(Function<? super R,VOUT,LdapException> onResult)
Submits the provided function for execution once this
Promise has
completed with a result, and returns a new Promise representing
the outcome of the function. |
LdapPromise<R> |
thenAlways(Runnable onResultOrException)
Submits the provided runnable for execution once this
Promise has
completed, and regardless of whether it has a result or an exception. |
<VOUT,EOUT extends Exception> |
thenAsync(AsyncFunction<? super R,VOUT,EOUT> onResult,
AsyncFunction<? super LdapException,VOUT,EOUT> onException)
Submits the provided asynchronous functions for execution once this
Promise has completed, and returns a new Promise
representing the outcome of the invoked function. |
<VOUT,EOUT extends Exception> |
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 this
Promise has completed, and returns a new Promise
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 this
Promise has completed with a result, and returns a new
Promise representing the outcome of the function. |
<EOUT extends Exception> |
thenCatch(Function<? super LdapException,R,EOUT> onException)
Submits the provided function for execution once this
Promise has
not completed with a result (has completed with an exception), and returns
a new Promise representing the outcome of the function. |
<EOUT extends Exception> |
thenCatchAsync(AsyncFunction<? super LdapException,R,EOUT> onException)
Submits the provided asynchronous function for execution once this
Promise has completed with an exception, and returns a new
Promise representing the outcome of the function. |
Promise<R,LdapException> |
thenCatchRuntimeException(Function<? super RuntimeException,R,LdapException> onRuntimeException)
Submits the provided function for execution once this
Promise has
not completed with a result nor with an exception but with a RuntimeException , and returns
a new Promise representing the outcome of the function. |
Promise<R,LdapException> |
thenCatchRuntimeExceptionAsync(AsyncFunction<? super RuntimeException,R,LdapException> onRuntimeException)
Submits the provided asynchronous function for execution once this
Promise has completed with a RuntimeException , and returns a new
Promise representing the outcome of the function. |
LdapPromise<R> |
thenFinally(Runnable onResultOrException)
Submits the provided runnable for execution once this
Promise has
completed, and regardless of whether of its outcome. |
LdapPromise<R> |
thenOnException(ExceptionHandler<? super LdapException> onException)
Registers the provided completion handler for notification if this
Promise cannot be completed due to an exception. |
LdapPromise<R> |
thenOnResult(ResultHandler<? super R> onResult)
Registers the provided completion handler for notification once this
Promise has completed with a result. |
LdapPromise<R> |
thenOnResultOrException(ResultHandler<? super R> onResult,
ExceptionHandler<? super LdapException> onException)
Registers the provided completion handlers for notification once this
Promise has completed (with a result or an exception). |
LdapPromise<R> |
thenOnResultOrException(Runnable onResultOrException)
Submits the provided runnable for execution once this
Promise has
completed, and regardless of whether it has a result or an exception. |
LdapPromise<R> |
thenOnRuntimeException(RuntimeExceptionHandler onRuntimeException)
Registers the provided completion handler for notification if this
Promise cannot be completed due to an runtime exception. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRequestId, then, thenAlways, thenAsync, thenFinally, thenOnException, thenOnResult, thenOnResultOrException, thenOnResultOrException
cancel, get, get, getOrThrow, getOrThrow, getOrThrowUninterruptibly, getOrThrowUninterruptibly, isCancelled, isDone, isResult, then, then, thenAsync, thenAsync, thenCatch, thenCatchAsync, thenCatchRuntimeException, thenCatchRuntimeExceptionAsync, thenOnRuntimeException
public static <S> LdapPromiseImpl<S> newLdapPromiseImpl(int requestId)
LdapPromiseImpl
with a requestId.S
- The type of result of the promise.requestId
- Identifier of the request.LdapPromiseImpl
public void handleException(LdapException exception)
LdapResultHandler
handleException
in interface LdapResultHandler<S>
handleException
in interface ExceptionHandler<LdapException>
exception
- The error result exception indicating why the asynchronous
operation has failed.public void handleResult(S result)
LdapResultHandler
handleResult
in interface LdapResultHandler<S>
handleResult
in interface ResultHandler<S>
result
- The result of the asynchronous operation.public int getRequestId()
LdapPromise
getRequestId
in interface LdapPromise<R>
-1
if there is no request ID.public boolean cancel(boolean mayInterruptIfRunning)
Promise
Promise
. Cancellation will fail if this Promise
has
already completed or has already been cancelled. If successful, then
cancellation will complete this Promise
with an appropriate
exception and notify any registered functions and completion handlers.
After this method returns, subsequent calls to Promise.isDone()
will
always return true
. Subsequent calls to Promise.isCancelled()
will
always return true
if this method returned true
.
cancel
in interface Future<R>
cancel
in interface Promise<R,LdapException>
mayInterruptIfRunning
- true
if the thread executing executing the response
handler should be interrupted; otherwise, in-progress response
handlers are allowed to complete.false
if Promise
could not be cancelled,
typically because it has already completed normally; true
otherwise.public R get() throws ExecutionException, InterruptedException
Promise
Promise
to complete, and then returns
the result if it completed successfully, or throws an
ExecutionException
containing the cause of the failure.get
in interface Future<R>
get
in interface Promise<R,LdapException>
Promise
completed
successfully.ExecutionException
- If this Promise
was cancelled or did not complete
successfully. The ExecutionException
will contain the
cause of the failure.InterruptedException
- If the current thread was interrupted while waiting.public R get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException, InterruptedException
Promise
Promise
to
complete, and then returns the result if it completed successfully, or
throws an ExecutionException
containing the cause of the failure.get
in interface Future<R>
get
in interface Promise<R,LdapException>
timeout
- The maximum time to wait.unit
- The time unit of the timeout argument.Promise
completed
successfully.ExecutionException
- If this Promise
was cancelled or did not complete
successfully. The ExecutionException
will contain the
cause of the failure.TimeoutException
- If the wait timed out.InterruptedException
- If the current thread was interrupted while waiting.public R getOrThrow() throws InterruptedException, LdapException
Promise
Promise
to complete, and then returns
the result if it completed successfully, or throws an exception
representing the cause of the failure.getOrThrow
in interface Promise<R,LdapException>
Promise
completed
successfully.InterruptedException
- If the current thread was interrupted while waiting.LdapException
public R getOrThrow(long timeout, TimeUnit unit) throws InterruptedException, LdapException, TimeoutException
Promise
Promise
to
complete, and then returns the result if it completed successfully, or
throws an exception representing the cause of the failure.getOrThrow
in interface Promise<R,LdapException>
timeout
- The maximum time to wait.unit
- The time unit of the timeout argument.Promise
completed
successfully.InterruptedException
- If the current thread was interrupted while waiting.TimeoutException
- If the wait timed out.LdapException
public R getOrThrowUninterruptibly() throws LdapException
Promise
Promise
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.
getOrThrowUninterruptibly
in interface Promise<R,LdapException>
Promise
completed
successfully.LdapException
public R getOrThrowUninterruptibly(long timeout, TimeUnit unit) throws LdapException, TimeoutException
Promise
Promise
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.
getOrThrowUninterruptibly
in interface Promise<R,LdapException>
timeout
- The maximum time to wait.unit
- The time unit of the timeout argument.Promise
completed
successfully.TimeoutException
- If the wait timed out.LdapException
public boolean isCancelled()
Promise
true
if this Promise
was cancelled before it
completed normally.isCancelled
in interface Future<R>
isCancelled
in interface Promise<R,LdapException>
true
if this Promise
was cancelled before it
completed normally, otherwise false
.public boolean isDone()
Promise
true
if this Promise
has completed.
Completion may be due to normal termination, an exception, or
cancellation. In all of these cases, this method will return true
.
isDone
in interface Future<R>
isDone
in interface Promise<R,LdapException>
true
if this Promise
has completed, otherwise
false
.public boolean isResult()
Promise
true
if this Promise
has completed and contains a value.isResult
in interface Promise<R,LdapException>
true
if this Promise
has completed with a value.public LdapPromise<R> thenOnException(ExceptionHandler<? super LdapException> onException)
Promise
Promise
cannot be completed due to an exception. If this
Promise
completes with a result then the completion handler
will not be notified.
This method can be used for asynchronous completion notification.
thenOnException
in interface LdapPromise<R>
thenOnException
in interface Promise<R,LdapException>
onException
- The completion handler which will be notified upon failure
completion of this Promise
.Promise
that is guaranted to be completed once the provided
callback has been executed.public LdapPromise<R> thenOnRuntimeException(RuntimeExceptionHandler onRuntimeException)
Promise
Promise
cannot be completed due to an runtime exception. If this
Promise
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.
thenOnRuntimeException
in interface Promise<R,LdapException>
onRuntimeException
- The completion handler which will be notified upon an
uncaught runtime exception completion of this
Promise
.Promise
that is guaranted to be completed once the provided
callback has been executed.public LdapPromise<R> thenOnResult(ResultHandler<? super R> onResult)
Promise
Promise
has completed with a result. If this Promise
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)
.
thenOnResult
in interface LdapPromise<R>
thenOnResult
in interface Promise<R,LdapException>
onResult
- The completion handler which will be notified upon successful
completion of this Promise
.Promise
that is guaranted to be completed once the provided
callback has been executed.public LdapPromise<R> thenOnResultOrException(Runnable onResultOrException)
Promise
Promise
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 in
try...catch
expressions.
This method is equivalent to Promise.thenAlways(Runnable)
.
thenOnResultOrException
in interface LdapPromise<R>
thenOnResultOrException
in interface Promise<R,LdapException>
onResultOrException
- The runnable which will be notified regardless of the final
outcome of this Promise
.Promise
that is guaranted to be completed once the provided
callback has been executed.public <VOUT> LdapPromise<VOUT> then(Function<? super R,VOUT,LdapException> onResult)
Promise
Promise
has
completed with a result, and returns a new Promise
representing
the outcome of the function. If this Promise
does not
complete with a result then the function will not be invoked and the exception
will be forwarded to the returned Promise
.
This method can be used for transforming the result of an asynchronous task.
then
in interface LdapPromise<R>
then
in interface Promise<R,LdapException>
VOUT
- The type of the function's result, or Void
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 this Promise
.onResult
- The function which will be executed upon successful completion
of this Promise
.Promise
representing the outcome of the
function.public <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> then(Function<? super R,VOUT,EOUT> onResult, Function<? super LdapException,VOUT,EOUT> onException)
Promise
Promise
has completed (with a result or an exception), and returns a new
Promise
representing the outcome of the invoked function. If
this Promise
completes with a result then onResult
will be invoked with the result, otherwise onException
will
be invoked with the exception that occurred.
This method can be used for transforming the outcome of an asynchronous task.
then
in interface Promise<R,LdapException>
VOUT
- The type of the functions' result, or Void
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 this Promise
.EOUT
- The type of the exception thrown by the functions if they
fail, or NeverThrowsException
if they cannot fail.
Note that the type may be different to the type of this
Promise
.onResult
- The function which will be executed upon successful completion
of this Promise
.onException
- The function which will be executed upon failure of this
Promise
.Promise
representing the outcome of the
invoked function.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)
Promise
Promise
has completed (with a result or an exception or a RuntimeException
), and returns a new
Promise
representing the outcome of the invoked function. If
this Promise
completes with a result then onResult
will be invoked with the result, with a RuntimeException
then onRuntimeException
will be invoked with the runtime exception that occurred, otherwise onException
will
be invoked with the exception that occurred.
This method can be used for transforming the outcome of an asynchronous task.
then
in interface Promise<R,LdapException>
VOUT
- The type of the functions' result, or Void
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 this Promise
.EOUT
- The type of the exception thrown by the functions if they
fail, or NeverThrowsException
if they cannot fail.
Note that the type may be different to the type of this
Promise
.onResult
- The function which will be executed upon successful completion
of this Promise
.onException
- The function which will be executed upon failure of this
Promise
.onRuntimeException
- The function which will be executed upon failure with
RuntimeException
of this Promise
.Promise
representing the outcome of the
invoked function.public LdapPromise<R> thenOnResultOrException(ResultHandler<? super R> onResult, ExceptionHandler<? super LdapException> onException)
Promise
Promise
has completed (with a result or an exception). If this
Promise
completes with a result then onResult
will be
notified with the result, otherwise onException
will be notified
with the exception that occurred.
This method can be used for asynchronous completion notification.
thenOnResultOrException
in interface LdapPromise<R>
thenOnResultOrException
in interface Promise<R,LdapException>
onResult
- The completion handler which will be notified upon completion
with a result of this Promise
.onException
- The completion handler which will be notified upon failure of
this Promise
.Promise
that is guaranted to be completed once the provided
callback has been executed.public LdapPromise<R> thenAlways(Runnable onResultOrException)
Promise
Promise
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 in
try...catch
expressions.
This method is equivalent to Promise.thenOnResultOrException(Runnable)
.
thenAlways
in interface LdapPromise<R>
thenAlways
in interface Promise<R,LdapException>
onResultOrException
- The runnable which will be notified regardless of the final
outcome of this Promise
.Promise
that is guaranted to be completed once the provided
callback has been executed.public <VOUT> LdapPromise<VOUT> thenAsync(AsyncFunction<? super R,VOUT,LdapException> onResult)
Promise
Promise
has completed with a result, and returns a new
Promise
representing the outcome of the function. If
this Promise
complete with an exception then the function
will not be invoked and the error will be forwarded to the returned
Promise
.
This method may be used for chaining together a series of asynchronous tasks.
thenAsync
in interface LdapPromise<R>
thenAsync
in interface Promise<R,LdapException>
VOUT
- The type of the function's result, or Void
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 this Promise
.onResult
- The asynchronous function which will be executed upon
successful completion of this Promise
.Promise
representing the outcome of the
function.public <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> thenAsync(AsyncFunction<? super R,VOUT,EOUT> onResult, AsyncFunction<? super LdapException,VOUT,EOUT> onException)
Promise
Promise
has completed, and returns a new Promise
representing the outcome of the invoked function. If this
Promise
completes with a result then onResult
will be
invoked with the result, otherwise onException
will be invoked with
the exception that occurred.
This method may be used for chaining together a series of asynchronous tasks.
thenAsync
in interface Promise<R,LdapException>
VOUT
- The type of the functions' result, or Void
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 this Promise
.EOUT
- The type of the exception thrown by the functions if they
fail, or NeverThrowsException
if they cannot fail.
Note that the type may be different to the type of this
Promise
.onResult
- The asynchronous function which will be executed upon
successful completion of this Promise
.onException
- The asynchronous function which will be executed upon failure
of this Promise
.Promise
representing the outcome of the
invoked function.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)
Promise
Promise
has completed, and returns a new Promise
representing the outcome of the invoked function. If this
Promise
completes with a result then onResult
will be
invoked with the result, otherwise onException
will be invoked with
the exception that occurred, or onRuntimeException
will be invoked with
the runtime exception that occurred.
This method may be used for chaining together a series of asynchronous tasks.
thenAsync
in interface Promise<R,LdapException>
VOUT
- The type of the functions' result, or Void
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 this Promise
.EOUT
- The type of the exception thrown by the functions if they
fail, or NeverThrowsException
if they cannot fail.
Note that the type may be different to the type of this
Promise
.onResult
- The asynchronous function which will be executed upon
successful completion of this Promise
.onException
- The asynchronous function which will be executed upon failure
of this Promise
.onRuntimeException
- The asynchronous function which will be executed upon failure
with RuntimeException
of this Promise
.Promise
representing the outcome of the
invoked function.public <EOUT extends Exception> Promise<R,EOUT> thenCatch(Function<? super LdapException,R,EOUT> onException)
Promise
Promise
has
not completed with a result (has completed with an exception), and returns
a new Promise
representing the outcome of the function.
If this Promise
completes with a result then the function will not
be invoked and the result notification will be forwarded to the returned
Promise
.
This method can be used for transforming the result of an asynchronous task.
thenCatch
in interface Promise<R,LdapException>
EOUT
- The type of the exception thrown by the function if it
fails, or NeverThrowsException
if it cannot fails.
Note that the type may be different to the type of this
Promise
.onException
- The function which will be executed upon failure completion
of this Promise
.Promise
representing the outcome of the
function.public Promise<R,LdapException> thenCatchRuntimeException(Function<? super RuntimeException,R,LdapException> onRuntimeException)
Promise
Promise
has
not completed with a result nor with an exception but with a RuntimeException
, and returns
a new Promise
representing the outcome of the function.
If this Promise
completes with a result or an exception then the function will not
be invoked and the result notification will be forwarded to the returned
Promise
.
This method can be used for transforming the result of an asynchronous task.
thenCatchRuntimeException
in interface Promise<R,LdapException>
onRuntimeException
- The function which will be executed upon failure completion
of this Promise
.Promise
representing the outcome of the
function.public Promise<R,LdapException> thenCatchRuntimeExceptionAsync(AsyncFunction<? super RuntimeException,R,LdapException> onRuntimeException)
Promise
Promise
has completed with a RuntimeException
, and returns a new
Promise
representing the outcome of the function. If this
Promise
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.
thenCatchRuntimeExceptionAsync
in interface Promise<R,LdapException>
onRuntimeException
- The asynchronous function which will be executed upon failure completion
with a RuntimeException
of this Promise
.Promise
representing the outcome of the
function.public LdapPromise<R> thenFinally(Runnable onResultOrException)
Promise
Promise
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 in
try...catch
expressions.
This method is equivalent to Promise.thenAlways(Runnable)
.
thenFinally
in interface LdapPromise<R>
thenFinally
in interface Promise<R,LdapException>
onResultOrException
- The runnable which will be notified regardless of the final
outcome of this Promise
.Promise
that is guaranted to be completed once the provided
callback has been executed.public <EOUT extends Exception> Promise<R,EOUT> thenCatchAsync(AsyncFunction<? super LdapException,R,EOUT> onException)
Promise
Promise
has completed with an exception, and returns a new
Promise
representing the outcome of the function. If
this Promise
completes with a result then the function
will not be invoked and the exception will be forwarded to the returned
Promise
.
This method may be used for chaining together a series of asynchronous tasks.
thenCatchAsync
in interface Promise<R,LdapException>
EOUT
- The type of the exception thrown by the function if it
fails, or NeverThrowsException
if it cannot fails.
Note that the type may be different to the type of this
Promise
.onException
- The asynchronous function which will be executed upon failure completion
of this Promise
.Promise
representing the outcome of the
function.Copyright © 2010-2018, ForgeRock All Rights Reserved.