-
- All Superinterfaces:
Invocable
- All Known Subinterfaces:
Callback.InvocableCallback
- All Known Implementing Classes:
Callback.Completable
,Callback.Completing
,Callback.Nested
,CountingCallback
,FutureCallback
,IteratingCallback
,IteratingNestedCallback
,SharedBlockingCallback.Blocker
public interface Callback extends Invocable
A callback abstraction that handles completed/failed events of asynchronous operations.
Semantically this is equivalent to an optimise Promise<Void>, but callback is a more meaningful name than EmptyPromise
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Callback.Completable
A CompletableFuture that is also a Callback.static class
Callback.Completing
static interface
Callback.InvocableCallback
static class
Callback.Nested
Nested Completing Callback that completes after completing the nested callback-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.InvocationType
-
-
Field Summary
Fields Modifier and Type Field Description static Callback
NOOP
Instance of Adapter that can be used when the callback methods need an empty implementation without incurring in the cost of allocating a new Adapter object.-
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static Callback
combine(Callback cb1, Callback cb2)
default void
failed(java.lang.Throwable x)
Callback invoked when the operation fails.static Callback
from(java.lang.Runnable completed)
Creaste a callback that runs completed when it succeeds or failsstatic Callback
from(java.lang.Runnable success, java.util.function.Consumer<java.lang.Throwable> failure)
Create a callback from the passed success and failurestatic Callback
from(java.lang.Runnable completed, Callback callback)
Create a nested callback that runs completed before completing the nested callback.static Callback
from(java.util.concurrent.CompletableFuture<?> completable)
Creates a non-blocking callback from the given incomplete CompletableFuture.static Callback
from(java.util.concurrent.CompletableFuture<?> completable, Invocable.InvocationType invocation)
Creates a callback from the given incomplete CompletableFuture, with the givenblocking
characteristic.static Callback
from(Callback callback, java.lang.Runnable completed)
Create a nested callback that runs completed after completing the nested callback.static Callback
from(Callback callback, java.lang.Throwable cause)
Create a nested callback which always fails the nested callback on completion.static Callback
from(Callback callback1, Callback callback2)
Create a callback which combines two other callbacks and will succeed or fail them both.default void
succeeded()
Callback invoked when the operation completes.-
Methods inherited from interface org.eclipse.jetty.util.thread.Invocable
getInvocationType
-
-
-
-
Field Detail
-
NOOP
static final Callback NOOP
Instance of Adapter that can be used when the callback methods need an empty implementation without incurring in the cost of allocating a new Adapter object.
-
-
Method Detail
-
succeeded
default void succeeded()
Callback invoked when the operation completes.
- See Also:
failed(Throwable)
-
failed
default void failed(java.lang.Throwable x)
Callback invoked when the operation fails.
- Parameters:
x
- the reason for the operation failure
-
from
static Callback from(java.util.concurrent.CompletableFuture<?> completable)
Creates a non-blocking callback from the given incomplete CompletableFuture.
When the callback completes, either succeeding or failing, the CompletableFuture is also completed, respectively via
CompletableFuture.complete(Object)
orCompletableFuture.completeExceptionally(Throwable)
.- Parameters:
completable
- the CompletableFuture to convert into a callback- Returns:
- a callback that when completed, completes the given CompletableFuture
-
from
static Callback from(java.util.concurrent.CompletableFuture<?> completable, Invocable.InvocationType invocation)
Creates a callback from the given incomplete CompletableFuture, with the given
blocking
characteristic.- Parameters:
completable
- the CompletableFuture to convert into a callbackinvocation
- whether the callback is blocking- Returns:
- a callback that when completed, completes the given CompletableFuture
-
from
static Callback from(java.lang.Runnable success, java.util.function.Consumer<java.lang.Throwable> failure)
Create a callback from the passed success and failure- Parameters:
success
- Called when the callback succeedsfailure
- Called when the callback fails- Returns:
- a new Callback
-
from
static Callback from(java.lang.Runnable completed)
Creaste a callback that runs completed when it succeeds or fails- Parameters:
completed
- The completion to run on success or failure- Returns:
- a new callback
-
from
static Callback from(Callback callback, java.lang.Runnable completed)
Create a nested callback that runs completed after completing the nested callback.- Parameters:
callback
- The nested callbackcompleted
- The completion to run after the nested callback is completed- Returns:
- a new callback.
-
from
static Callback from(java.lang.Runnable completed, Callback callback)
Create a nested callback that runs completed before completing the nested callback.- Parameters:
callback
- The nested callbackcompleted
- The completion to run before the nested callback is completed. Any exceptions thrown from completed will result in a callback failure.- Returns:
- a new callback.
-
from
static Callback from(Callback callback, java.lang.Throwable cause)
Create a nested callback which always fails the nested callback on completion.- Parameters:
callback
- The nested callbackcause
- The cause to fail the nested callback, if the new callback is failed the reason will be added to this cause as a suppressed exception.- Returns:
- a new callback.
-
from
static Callback from(Callback callback1, Callback callback2)
Create a callback which combines two other callbacks and will succeed or fail them both.- Parameters:
callback1
- The first callbackcallback2
- The second callback- Returns:
- a new callback.
-
-