Top Description Inners Fields Methods
org.eclipse.jetty.util

public Interface Promise<C>

Known Direct Implementers
org.eclipse.jetty.util.Promise.Adapter, org.eclipse.jetty.util.Promise.Completable, org.eclipse.jetty.util.Promise.Wrapper, org.eclipse.jetty.util.FuturePromise
Type Parameters
<C>
the type of the context object
Imports
java.util.Objects, java.util.concurrent.CompletableFuture, java.util.function.Consumer, org.slf4j.LoggerFactory

A callback abstraction that handles completed/failed events of asynchronous operations.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Promise.Adapter<
the type of the result
U
>

Empty implementation of Promise.

public static class
Promise.Completable<
the type of the result
S
>

A CompletableFuture that is also a Promise.

public static class

Field Summary

Modifier and TypeField and Description
public static final Promise<Object>

Method Summary

Modifier and TypeMethod and Description
public default void
completeWith(CompletableFuture<C>
the CompletableFuture that completes this promise
completable
)

Completes this promise with the given CompletableFuture.

public default void
failed(Throwable
the reason for the operation failure
x
)

Callback invoked when the operation fails.

public static <
the type of the result
T
>
Promise<T>

Returns:

a new Promise wrapping the success and failure consumers.
from
(Consumer<T>
the consumer invoked when the promise is succeeded
success
,
Consumer<Throwable>
the consumer invoked when the promise is failed
failure
)

Creates a Promise from the given success and failure consumers.

public static <
the type of the result
T
>
Promise<T>

Returns:

a promise that when completed, completes the given CompletableFuture
from
(CompletableFuture<? super T>
the CompletableFuture to convert into a promise
completable
)

Creates a promise from the given incomplete CompletableFuture.

public static <T> Promise<T>
noop()

public default void
succeeded(C
the context
result
)

Callback invoked when the operation completes.

Field Detail

NOOPback to summary
public static final Promise<Object> NOOP

Method Detail

completeWithback to summary
public default void completeWith(CompletableFuture<C> completable)

Completes this promise with the given CompletableFuture.

When the CompletableFuture completes normally, this promise is succeeded; when the CompletableFuture completes exceptionally, this promise is failed.

Parameters
completable:CompletableFuture<C>

the CompletableFuture that completes this promise

failedback to summary
public default void failed(Throwable x)

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

fromback to summary
public static <T> Promise<T> from(Consumer<T> success, Consumer<Throwable> failure)

Creates a Promise from the given success and failure consumers.

Parameters
<T>
the type of the result
success:Consumer<T>

the consumer invoked when the promise is succeeded

failure:Consumer<Throwable>

the consumer invoked when the promise is failed

Returns:Promise<T>

a new Promise wrapping the success and failure consumers.

fromback to summary
public static <T> Promise<T> from(CompletableFuture<? super T> completable)

Creates a promise from the given incomplete CompletableFuture.

When the promise completes, either succeeding or failing, the CompletableFuture is also completed, respectively via CompletableFuture#complete(Object) or CompletableFuture#completeExceptionally(Throwable).

Parameters
<T>
the type of the result
completable:CompletableFuture<? super T>

the CompletableFuture to convert into a promise

Returns:Promise<T>

a promise that when completed, completes the given CompletableFuture

noopback to summary
public static <T> Promise<T> noop()
Annotations
@SuppressWarnings:unchecked
succeededback to summary
public default void succeeded(C result)

Callback invoked when the operation completes.

Parameters
result:C

the context

See Also
failed(Throwable)
org.eclipse.jetty.util back to summary

public Class Promise.Adapter<U>

extends Object
implements Promise<U>
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Promise
Type Parameters
<U>
the type of the result

Empty implementation of Promise.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
failed(Throwable
the reason for the operation failure
x
)

Overrides default org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Adapterback to summary
public Adapter()

Method Detail

failedback to summary
public void failed(Throwable x)

Overrides default org.eclipse.jetty.util.Promise.failed.

Doc from org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
org.eclipse.jetty.util back to summary

public Class Promise.Completable<S>

extends CompletableFuture<S>
implements Promise<S>
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Promise
Type Parameters
<S>
the type of the result

A CompletableFuture that is also a Promise.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
failed(Throwable
the reason for the operation failure
x
)

Overrides default org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

public void
succeeded(S
the context
result
)

Overrides default org.eclipse.jetty.util.Promise.succeeded.

Callback invoked when the operation completes.

public static <
the type of the result
R
>
Promise.Completable<R>

Returns:

the newly created Completable
with
(Consumer<Promise<R>>
the code that consumes the newly created Completable
consumer
)

Creates a new Completable to be consumed by the given consumer, then returns the newly created Completable.

Inherited from java.util.concurrent.CompletableFuture:
acceptEitheracceptEitherAsyncacceptEitherAsyncallOfanyOfapplyToEitherapplyToEitherAsyncapplyToEitherAsynccancelcompletecompleteAsynccompleteAsynccompletedFuturecompletedStagecompleteExceptionallycompleteOnTimeoutcopydefaultExecutordelayedExecutordelayedExecutorexceptionallyexceptionallyAsyncexceptionallyAsyncexceptionallyComposeexceptionallyComposeAsyncexceptionallyComposeAsyncexceptionNowfailedFuturefailedStagegetgetgetNowgetNumberOfDependentshandlehandleAsynchandleAsyncisCancelledisCompletedExceptionallyisDonejoinminimalCompletionStagenewIncompleteFutureobtrudeExceptionobtrudeValueorTimeoutresultNowrunAfterBothrunAfterBothAsyncrunAfterBothAsyncrunAfterEitherrunAfterEitherAsyncrunAfterEitherAsyncrunAsyncrunAsyncstatesupplyAsyncsupplyAsyncthenAcceptthenAcceptAsyncthenAcceptAsyncthenAcceptBoththenAcceptBothAsyncthenAcceptBothAsyncthenApplythenApplyAsyncthenApplyAsyncthenCombinethenCombineAsyncthenCombineAsyncthenComposethenComposeAsyncthenComposeAsyncthenRunthenRunAsyncthenRunAsynctoCompletableFuturetoStringwhenCompletewhenCompleteAsyncwhenCompleteAsync

Constructor Detail

Completableback to summary
public Completable()

Method Detail

failedback to summary
public void failed(Throwable x)

Overrides default org.eclipse.jetty.util.Promise.failed.

Doc from org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
succeededback to summary
public void succeeded(S result)

Overrides default org.eclipse.jetty.util.Promise.succeeded.

Doc from org.eclipse.jetty.util.Promise.succeeded.

Callback invoked when the operation completes.

Parameters
result:S

the context

Annotations
@Override
withback to summary
public static <R> Promise.Completable<R> with(Consumer<Promise<R>> consumer)

Creates a new Completable to be consumed by the given consumer, then returns the newly created Completable.

Parameters
<R>
the type of the result
consumer:Consumer<Promise<R>>

the code that consumes the newly created Completable

Returns:Promise.Completable<R>

the newly created Completable

org.eclipse.jetty.util back to summary

public Class Promise.Wrapper<W>

extends Object
implements Promise<W>
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Promise

Field Summary

Modifier and TypeField and Description
private final Promise<W>

Constructor Summary

AccessConstructor and Description
public
Wrapper(Promise<W> promise)

Method Summary

Modifier and TypeMethod and Description
public void
failed(Throwable
the reason for the operation failure
x
)

Overrides default org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

public Promise<W>
public void
succeeded(W
the context
result
)

Overrides default org.eclipse.jetty.util.Promise.succeeded.

Callback invoked when the operation completes.

public Promise<W>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

promiseback to summary
private final Promise<W> promise

Constructor Detail

Wrapperback to summary
public Wrapper(Promise<W> promise)

Method Detail

failedback to summary
public void failed(Throwable x)

Overrides default org.eclipse.jetty.util.Promise.failed.

Doc from org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
getPromiseback to summary
public Promise<W> getPromise()
succeededback to summary
public void succeeded(W result)

Overrides default org.eclipse.jetty.util.Promise.succeeded.

Doc from org.eclipse.jetty.util.Promise.succeeded.

Callback invoked when the operation completes.

Parameters
result:W

the context

Annotations
@Override
unwrapback to summary
public Promise<W> unwrap()