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

public Interface Callback

extends Invocable
Known Direct Subinterfaces
org.eclipse.jetty.util.Callback.Completing, org.eclipse.jetty.util.Blocker.Callback
Known Direct Implementers
org.eclipse.jetty.util.Callback.Completable, org.eclipse.jetty.util.FutureCallback, org.eclipse.jetty.util.IteratingCallback, org.eclipse.jetty.util.SharedBlockingCallback.Blocker
Imports
java.util.Objects, java.util.concurrent.CompletableFuture, java.util.function.Consumer, org.eclipse.jetty.util.thread.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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static interface
Callback.Completing

A Callback implementation that calls the completed() method when it either succeeds or fails.

public static class
Callback.Nested

Nested Completing Callback that completes after completing the nested callback

Field Summary

Modifier and TypeField and Description
public static final Callback
NOOP

Hides org.eclipse.jetty.util.thread.Invocable.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.
Inherited from org.eclipse.jetty.util.thread.Invocable:
__nonBlocking

Method Summary

Modifier and TypeMethod and Description
public static Callback
public default void
completeWith(CompletableFuture<?>
the CompletableFuture that completes this callback
completable
)

Completes this callback with the given CompletableFuture.

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

Callback invoked when the operation fails.

public static Callback

Returns:

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

Creates a non-blocking callback from the given incomplete CompletableFuture.

public static Callback

Returns:

a callback that when completed, completes the given CompletableFuture
from
(CompletableFuture<?>
the CompletableFuture to convert into a callback
completable
,
Invocable.InvocationType
whether the callback is blocking
invocation
)

Creates a callback from the given incomplete CompletableFuture, with the given blocking characteristic.

public static Callback

Returns:

a new Callback
from
(Runnable
Called when the callback succeeds
success
,
Consumer<Throwable>
Called when the callback fails
failure
)

Creates a callback from the given success and failure lambdas.

public static Callback

Returns:

a new Callback
from
(Invocable.InvocationType
the Callback invocation type
invocationType
,
Runnable
Called when the callback succeeds
success
,
Consumer<Throwable>
Called when the callback fails
failure
)

Creates a callback with the given InvocationType from the given success and failure lambdas.

public static Callback

Returns:

a new callback
from
(Runnable
The completion to run on success or failure
completed
)

Creates a callback that runs completed when it succeeds or fails

public static Callback

Returns:

a new Callback with the given invocation type
from
(Invocable.InvocationType
the invocation type of the returned Callback
invocationType
,
Runnable
the Runnable to run when the callback either succeeds or fails
completed
)

Hides org.eclipse.jetty.util.thread.Invocable.from.

Creates a Callback with the given invocationType, that runs the given Runnable when it succeeds or fails.

public static Callback

Returns:

a new callback.
from
(Callback
The nested callback
callback
,
Runnable
The completion to run after the nested callback is completed
completed
)

Creates a nested callback that runs completed after completing the nested callback.

public static Callback

Returns:

a new callback.
from
(Callback
The nested callback
callback
,
Consumer<Throwable>
The completion to run after the nested callback is completed
completed
)

Creates a nested callback that runs completed after completing the nested callback.

public static Callback

Returns:

a new callback.
from
(Runnable
The completion to run before the nested callback is completed. Any exceptions thrown from completed will result in a callback failure.
completed
,
Callback
The nested callback
callback
)

Creates a nested callback that runs completed before completing the nested callback.

public static Callback

Returns:

a new callback.
from
(Callback
The nested callback
callback
,
Throwable
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.
cause
)

Creates a nested callback which always fails the nested callback on completion.

public static Callback

Returns:

a new callback.
from
(Callback
The first callback
callback1
,
Callback
The second callback
callback2
)

Creates a callback which combines two other callbacks and will succeed or fail them both.

public default void
succeeded()

Callback invoked when the operation completes.

Inherited from org.eclipse.jetty.util.thread.Invocable:
combinecombinegetInvocationTypegetInvocationTypeinvokeNonBlockingisNonBlockingInvocation

Field Detail

NOOPback to summary
public static final Callback NOOP

Hides org.eclipse.jetty.util.thread.Invocable.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

combineback to summary
public static Callback combine(Callback cb1, Callback cb2)
completeWithback to summary
public default void completeWith(CompletableFuture<?> completable)

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:CompletableFuture<?>

the CompletableFuture that completes this callback

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 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:CompletableFuture<?>

the CompletableFuture to convert into a callback

Returns:Callback

a callback that when completed, completes the given CompletableFuture

fromback to summary
public static Callback from(CompletableFuture<?> completable, Invocable.InvocationType invocation)

Creates a callback from the given incomplete CompletableFuture, with the given blocking characteristic.

Parameters
completable:CompletableFuture<?>

the CompletableFuture to convert into a callback

invocation:Invocable.InvocationType

whether the callback is blocking

Returns:Callback

a callback that when completed, completes the given CompletableFuture

fromback to summary
public static Callback from(Runnable success, Consumer<Throwable> failure)

Creates a callback from the given success and failure lambdas.

Parameters
success:Runnable

Called when the callback succeeds

failure:Consumer<Throwable>

Called when the callback fails

Returns:Callback

a new Callback

fromback to summary
public 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:Invocable.InvocationType

the Callback invocation type

success:Runnable

Called when the callback succeeds

failure:Consumer<Throwable>

Called when the callback fails

Returns:Callback

a new Callback

fromback to summary
public static Callback from(Runnable completed)

Creates a callback that runs completed when it succeeds or fails

Parameters
completed:Runnable

The completion to run on success or failure

Returns:Callback

a new callback

fromback to summary
public static Callback from(Invocable.InvocationType invocationType, Runnable completed)

Hides org.eclipse.jetty.util.thread.Invocable.from.

Creates a Callback with the given invocationType, that runs the given Runnable when it succeeds or fails.

Parameters
invocationType:Invocable.InvocationType

the invocation type of the returned Callback

completed:Runnable

the Runnable to run when the callback either succeeds or fails

Returns:Callback

a new Callback with the given invocation type

fromback to summary
public static Callback from(Callback callback, Runnable completed)

Creates a nested callback that runs completed after completing the nested callback.

Parameters
callback:Callback

The nested callback

completed:Runnable

The completion to run after the nested callback is completed

Returns:Callback

a new callback.

fromback to summary
public static Callback from(Callback callback, Consumer<Throwable> completed)

Creates a nested callback that runs completed after completing the nested callback.

Parameters
callback:Callback

The nested callback

completed:Consumer<Throwable>

The completion to run after the nested callback is completed

Returns:Callback

a new callback.

fromback to summary
public static Callback from(Runnable completed, Callback callback)

Creates a nested callback that runs completed before completing the nested callback.

Parameters
completed:Runnable

The completion to run before the nested callback is completed. Any exceptions thrown from completed will result in a callback failure.

callback:Callback

The nested callback

Returns:Callback

a new callback.

fromback to summary
public static Callback from(Callback callback, Throwable cause)

Creates a nested callback which always fails the nested callback on completion.

Parameters
callback:Callback

The nested callback

cause:Throwable

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:Callback

a new callback.

fromback to summary
public static Callback from(Callback callback1, Callback callback2)

Creates a callback which combines two other callbacks and will succeed or fail them both.

Parameters
callback1:Callback

The first callback

callback2:Callback

The second callback

Returns:Callback

a new callback.

succeededback to summary
public default void succeeded()

Callback invoked when the operation completes.

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

public Class Callback.Completable

extends CompletableFuture<Void>
implements Callback
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Callback, org.eclipse.jetty.util.thread.Invocable

A CompletableFuture that is also a Callback.

Field Summary

Modifier and TypeField and Description
private final Invocable.InvocationType

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public Callback.Completable

Returns:

a new Completable passed to the consumer
compose
(Consumer<Callback.Completable>
the consumer that receives the Completable
consumer
)

Returns a new Completable that, when this Completable succeeds, is passed to the given consumer and then returned.

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

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

Callback invoked when the operation fails.

public static Callback.Completable

Returns:

a new Completable which will succeed this callback when completed.
from
(Callback
The nested callback.
callback
)

Creates a completable future given a callback.

public Invocable.InvocationType
public void
succeeded()

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

Callback invoked when the operation completes.

public static Callback.Completable

Returns:

the newly created Completable
with
(Consumer<Callback.Completable>
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

Field Detail

invocationback to summary
private final Invocable.InvocationType invocation

Constructor Detail

Completableback to summary
public Completable()
Completableback to summary
public Completable(Invocable.InvocationType invocation)

Method Detail

composeback to summary
public Callback.Completable compose(Consumer<Callback.Completable> consumer)

Returns a new Completable that, when this Completable succeeds, is passed to the given consumer and then returned.

If this Completable fails, the new Completable is also failed, and the consumer is not invoked.

Parameters
consumer:Consumer<Callback.Completable>

the consumer that receives the Completable

Returns:Callback.Completable

a new Completable passed to the consumer

See Also
with(Consumer)
failedback to summary
public void failed(Throwable x)

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

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

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
fromback to summary
public static Callback.Completable from(Callback callback)

Creates a completable future given a callback.

Parameters
callback:Callback

The nested callback.

Returns:Callback.Completable

a new Completable which will succeed this callback when completed.

getInvocationTypeback to summary
public Invocable.InvocationType getInvocationType()

Overrides default org.eclipse.jetty.util.thread.Invocable.getInvocationType.

Returns:Invocable.InvocationType

Doc from org.eclipse.jetty.util.thread.Invocable.getInvocationType.

The InvocationType of this object

Annotations
@Override
succeededback to summary
public void succeeded()

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

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

Callback invoked when the operation completes.

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

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

Parameters
consumer:Consumer<Callback.Completable>

the code that consumes the newly created Completable

Returns:Callback.Completable

the newly created Completable

org.eclipse.jetty.util back to summary

public Interface Callback.Completing

extends Callback
Known Direct Implementers
org.eclipse.jetty.util.Callback.Nested

A Callback implementation that calls the completed() method when it either succeeds or fails.

Field Summary

Inherited from org.eclipse.jetty.util.Callback:
NOOP

Method Summary

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

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

Callback invoked when the operation fails.

public default void
succeeded()

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

Callback invoked when the operation completes.

Inherited from org.eclipse.jetty.util.Callback:
combinecompleteWithfromfromfromfromfromfromfromfromfromfromfrom

Method Detail

completedback to summary
public void completed()
failedback to summary
public default void failed(Throwable x)

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

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

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
succeededback to summary
public default void succeeded()

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

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

Callback invoked when the operation completes.

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

public Class Callback.Nested

extends Object
implements Completing
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Callback.Completing, org.eclipse.jetty.util.Callback, org.eclipse.jetty.util.thread.Invocable
Known Direct Subclasses
org.eclipse.jetty.util.CountingCallback

Nested Completing Callback that completes after completing the nested callback

Field Summary

Modifier and TypeField and Description
private final Callback

Constructor Summary

AccessConstructor and Description
public
Nested(Callback callback)

Method Summary

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

Overrides default org.eclipse.jetty.util.Callback.Completing.failed.

Callback invoked when the operation fails.

public Callback
public Invocable.InvocationType
public void
succeeded()

Overrides default org.eclipse.jetty.util.Callback.Completing.succeeded.

Callback invoked when the operation completes.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

callbackback to summary
private final Callback callback

Constructor Detail

Nestedback to summary
public Nested(Callback callback)

Method Detail

completedback to summary
public void completed()

Implements org.eclipse.jetty.util.Callback.Completing.completed.

Annotations
@Override
failedback to summary
public void failed(Throwable x)

Overrides default org.eclipse.jetty.util.Callback.Completing.failed.

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

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
getCallbackback to summary
public Callback getCallback()
getInvocationTypeback to summary
public Invocable.InvocationType getInvocationType()

Overrides default org.eclipse.jetty.util.thread.Invocable.getInvocationType.

Returns:Invocable.InvocationType

Doc from org.eclipse.jetty.util.thread.Invocable.getInvocationType.

The InvocationType of this object

Annotations
@Override
succeededback to summary
public void succeeded()

Overrides default org.eclipse.jetty.util.Callback.Completing.succeeded.

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

Callback invoked when the operation completes.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override