Interface Callback

All Superinterfaces:
Invocable
All Known Subinterfaces:
Callback.InvocableCallback
All Known Implementing Classes:
AbstractConnection.ReadCallback, Callback.Completable, Callback.Completing, Callback.Nested, CompletableCallback, CountingCallback, DeferredContentProvider, DeferredContentProvider.DeferredContentProviderIterator, FutureCallback, GzipHttpOutputInterceptor.GzipBufferCB, HttpChannel.Send100Callback, HttpChannel.SendCallback, HttpConnection.AsyncReadCallback, HttpConnection.BlockingReadCallback, HttpConnection.Content, HttpConnection.SendCallback, HttpContent, HttpDestination, HttpDestinationOverHTTP, HttpInput.Content, HttpInput.EofContent, HttpInput.SentinelContent, HttpOutput.AsyncFlush, HttpOutput.AsyncWrite, HttpOutput.ChannelWriteCB, HttpOutput.InputStreamWritingCB, HttpOutput.NestedChannelWriteCB, HttpOutput.ReadableByteChannelWritingCB, HttpOutput.WriteCompleteCB, HttpSender.CommitCallback, HttpSender.ContentCallback, HttpSender.LastCallback, HttpSenderOverHTTP.ByteBufferRecyclerCallback, HttpSenderOverHTTP.HeadersCallback, InputStreamContentProvider, IteratingCallback, IteratingNestedCallback, MultiPartContentProvider.MultiPartIterator, MultiplexHttpDestination, OutputStreamContentProvider, PoolingHttpDestination, ProxyProtocolClientConnectionFactory.ProxyProtocolConnection, ProxyProtocolClientConnectionFactory.ProxyProtocolConnectionV1, ProxyProtocolClientConnectionFactory.ProxyProtocolConnectionV2, SharedBlockingCallback.Blocker, Socks4Proxy.Socks4ProxyConnection, SslConnection.DecryptedEndPoint.IncompleteWriteCallback

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

  • Field Details

    • 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 Details

    • succeeded

      default void succeeded()

      Callback invoked when the operation completes.

      See Also:
    • failed

      default void failed(Throwable x)

      Callback invoked when the operation fails.

      Parameters:
      x - the reason for the operation failure
    • from

      static Callback from(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) or CompletableFuture.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(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 callback
      invocation - whether the callback is blocking
      Returns:
      a callback that when completed, completes the given CompletableFuture
    • from

      static Callback from(Runnable success, Consumer<Throwable> failure)
      Create a callback from the passed success and failure
      Parameters:
      success - Called when the callback succeeds
      failure - Called when the callback fails
      Returns:
      a new Callback
    • from

      static Callback from(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, Runnable completed)
      Create a nested callback that runs completed after completing the nested callback.
      Parameters:
      callback - The nested callback
      completed - The completion to run after the nested callback is completed
      Returns:
      a new callback.
    • from

      static Callback from(Runnable completed, Callback callback)
      Create a nested callback that runs completed before completing the nested callback.
      Parameters:
      completed - The completion to run before the nested callback is completed. Any exceptions thrown from completed will result in a callback failure.
      callback - The nested callback
      Returns:
      a new callback.
    • combine

      static Callback combine(Callback cb1, Callback cb2)