Interface Callback
- All Superinterfaces:
Invocable
- All Known Subinterfaces:
Blocker.Callback, Callback.Completing, HttpStream
- All Known Implementing Classes:
AsyncMiddleManServlet.ProxyReader, AsyncMiddleManServlet.ProxyReader, AsyncMiddleManServlet.ProxyReader, AsyncMiddleManServlet.ProxyResponseListener, AsyncMiddleManServlet.ProxyResponseListener, AsyncMiddleManServlet.ProxyResponseListener, AsyncMiddleManServlet.ProxyWriter, AsyncMiddleManServlet.ProxyWriter, AsyncMiddleManServlet.ProxyWriter, AsyncProxyServlet.StreamReader, AsyncProxyServlet.StreamReader, AsyncProxyServlet.StreamReader, Callback.Completable, Callback.Nested, ControlFlusher, CountingCallback, DemandingFlusher, FutureCallback, GzipResponseAndCallback, HTTP2Session.Entry, HTTP2Stream, HttpDestination, HttpInput.Content, HttpInput.Content, HttpInput.EofContent, HttpInput.EofContent, HttpInput.ErrorContent, HttpInput.ErrorContent, HttpInput.SpecialContent, HttpInput.SpecialContent, HttpInput.WrappingContent, HttpInput.WrappingContent, HttpStream.Wrapper, InstructionFlusher, IteratingCallback, IteratingNestedCallback, MessageFlusher, ProxyHandler.ProxyResponseListener, ProxyProtocolClientConnectionFactory.ProxyProtocolConnection, SendHandlerCallback, SendHandlerCallback, SendHandlerCallback, SharedBlockingCallback.Blocker
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 ClassesModifier and TypeInterfaceDescriptionstatic classACompletableFuturethat is also aCallback.static interfaceA Callback implementation that calls theCallback.Completing.completed()method when it either succeeds or fails.static classNested Completing Callback that completes after completing the nested callbackNested classes/interfaces inherited from interface Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CallbackInstance 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 Invocable
__nonBlocking -
Method Summary
Modifier and TypeMethodDescriptionstatic Callbackdefault voidcompleteWith(CompletableFuture<?> completable) Completes this callback with the givenCompletableFuture.default voidCallback invoked when the operation fails.static CallbackCreates a callback that runs completed when it succeeds or failsstatic CallbackCreates a callback from the given success and failure lambdas.static CallbackCreates a callback that runs theRunnableargument before completing the callback argument.static Callbackfrom(CompletableFuture<?> completable) Creates a non-blocking callback from the given incomplete CompletableFuture.static Callbackfrom(CompletableFuture<?> completable, Invocable.InvocationType invocation) Creates a callback from the given incomplete CompletableFuture, with the givenblockingcharacteristic.static CallbackCreates a callback that runs theRunnableargument after completing the callback argument.static CallbackCreates a callback which always fails the callback argument on completion.static CallbackCreates a callback that runs theConsumerargument after completing the callback argument.static CallbackCreates a callback which combines two other callbacks and will succeed or fail them both.static Callbackfrom(Invocable.InvocationType invocationType, Runnable completed) Creates a Callback with the giveninvocationType, that runs the givenRunnablewhen it succeeds or fails.static Callbackfrom(Invocable.InvocationType invocationType, Runnable success, Consumer<Throwable> failure) Creates a callback with the given InvocationType from the given success and failure lambdas.default voidCallback invoked when the operation completes.Methods inherited from interface Invocable
getInvocationType
-
Field Details
-
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 Details
-
completeWith
Completes this callback with the given
CompletableFuture.When the CompletableFuture completes normally, this callback is succeeded; when the CompletableFuture completes exceptionally, this callback is failed.
- Parameters:
completable- the CompletableFuture that completes this callback
-
succeeded
default void succeeded()Callback invoked when the operation completes.
- See Also:
-
failed
Callback invoked when the operation fails.
- Parameters:
x- the reason for the operation failure
-
from
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
Creates a callback from the given incomplete CompletableFuture, with the given
blockingcharacteristic.- 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
-
from
static Callback from(Invocable.InvocationType invocationType, Runnable success, Consumer<Throwable> failure) Creates a callback with the given InvocationType from the given success and failure lambdas.- Parameters:
invocationType- the Callback invocation typesuccess- Called when the callback succeedsfailure- Called when the callback fails- Returns:
- a new Callback
-
from
-
from
Creates a Callback with the given
invocationType, that runs the givenRunnablewhen it succeeds or fails.- Parameters:
invocationType- the invocation type of the returned Callbackcompleted- the Runnable to run when the callback either succeeds or fails- Returns:
- a new Callback with the given invocation type
-
from
Creates a callback that runs the
Runnableargument after completing the callback argument.The
Runnableis assumed to beNON_BLOCKING, so theInvocable.InvocationTypeof the returned callback is the same as the callback argument.- Parameters:
callback- The nested callbackcompleted- TheRunnableto run after the nested callback is completed- Returns:
- a new callback
-
from
Creates a callback that runs the
Consumerargument after completing the callback argument.The
Consumerreceivesnullif the callback succeeded, or theThrowablefailure if the callback failed.The
Consumeris assumed to beNON_BLOCKING, so theInvocable.InvocationTypeof the returned callback is the same as the callback parameter.- Parameters:
callback- The nested callbackcompleted- TheConsumerto run after the nested callback is completed- Returns:
- a new callback
-
from
Creates a callback that runs theRunnableargument before completing the callback argument.The
Runnableis assumed to beNON_BLOCKING, so theInvocable.InvocationTypeof the returned callback is the same as the callback argument. -
from
Creates a callback which always fails the callback argument on completion.
- Parameters:
callback- The nested callbackfailure- The cause to fail the nested callback; if the new callback is failed, the cause will be added to the failure argument as a suppressed exception.- Returns:
- a new callback.
-
from
-
combine
-