Interface | Description |
---|---|
ExceptionHandler<E> |
A completion handler for consuming exceptions which occur during the execution of
asynchronous tasks.
|
Promise<V,E extends Exception> |
A
Promise represents the result of an asynchronous task. |
ResultHandler<V> |
A completion handler for consuming the results of asynchronous tasks.
|
RuntimeExceptionHandler |
A completion handler for consuming runtime exceptions which occur during the
execution of asynchronous tasks.
|
Class | Description |
---|---|
PromiseImpl<V,E extends Exception> |
An implementation of
Promise which can be used as is, or as the basis
for more complex asynchronous behavior. |
Promises |
Utility methods for creating and composing
Promise s. |
Exception | Description |
---|---|
NeverThrowsException |
The
NeverThrowsException class is an uninstantiable placeholder
exception which should be used for indicating that a Function or
AsyncFunction never throws an exception (i.e. |
Promise
API in Java. Promises provide a simple
API for chaining together asynchronous tasks and result transformation.
Example using CREST:
final ConnectionFactory server = getConnectionFactory(); final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); final Promise<Resource, ResourceException> promise = server.getConnectionAsync() .thenAsync(new AsyncFunction<Connection, Resource, ResourceException>() { // Read resource. public Promise<Resource, ResourceException> apply(final Connection connection) throws ResourceException { connectionHolder.set(connection); // Save connection for later. return connection.readAsync(ctx(), Requests.newReadRequest("users/1")); } }).thenAsync(new AsyncFunction<Resource, Resource, ResourceException>() { // Update resource. public Promise<Resource, ResourceException> apply(final Resource user) throws ResourceException { return connectionHolder.get().updateAsync(ctx(), Requests.newUpdateRequest("users/1", userAliceWithIdAndRev(1, 1))); } }).then(new SuccessHandler<Resource>() { // Check updated resource. public void handleResult(final Resource user) { // Update successful! } }).thenAlways(new Runnable() { // Close the connection. public void run() { final Connection connection = connectionHolder.get(); if (connection != null) { connection.close(); } } });
Copyright © 2010-2018, ForgeRock All Rights Reserved.