Top Description Inners Fields Methods
org.eclipse.jetty.websocket.api

public Interface Callback

Known Direct Implementers
org.eclipse.jetty.websocket.api.Callback.Completable
Imports
java.util.concurrent.CompletableFuture, java.util.function.BiConsumer, .Consumer

A callback object that handles success/failure events of asynchronous operations.

Note

This interface is almost identical to org.eclipse.jetty.util.Callback, which however cannot be used in the Jetty WebSocket APIs for web application classloading reasons.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final Callback
NOOP

Empty implementation.

Method Summary

Modifier and TypeMethod and Description
public default BiConsumer<? super Void, ? super Throwable>

Returns:

a BiConsumer that completes this callback
asBiConsumer
()

Converts this callback into a BiConsumer that can be passed to CompletableFuture#whenComplete(BiConsumer).

public default void
fail(Throwable
the failure
x
)

Method to invoke to fail the callback.

public static Callback

Returns:

a new callback
from
(Runnable
the success action to invoke when the callback succeeds
success
,
Consumer<Throwable>
the failure consumer to invoke when the callback fails
failure
)

Creates a callback from the given success and failure lambdas.

public default void
succeed()

Method to invoke to succeed the callback.

Field Detail

NOOPback to summary
public static final Callback NOOP

Empty implementation.

Method Detail

asBiConsumerback to summary
public default BiConsumer<? super Void, ? super Throwable> asBiConsumer()

Converts this callback into a BiConsumer that can be passed to CompletableFuture#whenComplete(BiConsumer).

When the BiConsumer is accepted, this callback is completed.

Returns:BiConsumer<? super Void, ? super Throwable>

a BiConsumer that completes this callback

See Also
Completable#with(Consumer)
failback to summary
public default void fail(Throwable x)

Method to invoke to fail the callback.

Parameters
x:Throwable

the failure

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

the success action to invoke when the callback succeeds

failure:Consumer<Throwable>

the failure consumer to invoke when the callback fails

Returns:Callback

a new callback

succeedback to summary
public default void succeed()

Method to invoke to succeed the callback.

See Also
fail(Throwable)
org.eclipse.jetty.websocket.api back to summary

public Class Callback.Completable

extends CompletableFuture<Void>
implements Callback
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.api.Callback

A Callback that is also a CompletableFuture.

Applications can pass an instance of this class as a Callback, but also use the CompletableFuture APIs.

Constructor Summary

AccessConstructor and Description
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
fail(Throwable
the failure
x
)

Overrides default org.eclipse.jetty.websocket.api.Callback.fail.

Method to invoke to fail the callback.

public void
succeed()

Overrides default org.eclipse.jetty.websocket.api.Callback.succeed.

Method to invoke to succeed the callback.

public static Callback.Completable

Returns:

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

Convenience method that creates a Completable that is passed to the given consumer and then returned.

Inherited from java.util.concurrent.CompletableFuture:
acceptEitheracceptEitherAsyncacceptEitherAsyncallOfanyOfapplyToEitherapplyToEitherAsyncapplyToEitherAsynccancelcompletecompleteAsynccompleteAsynccompletedFuturecompletedStagecompleteExceptionallycompleteOnTimeoutcopydefaultExecutordelayedExecutordelayedExecutorexceptionallyexceptionallyAsyncexceptionallyAsyncexceptionallyComposeexceptionallyComposeAsyncexceptionallyComposeAsyncexceptionNowfailedFuturefailedStagegetgetgetNowgetNumberOfDependentshandlehandleAsynchandleAsyncisCancelledisCompletedExceptionallyisDonejoinminimalCompletionStagenewIncompleteFutureobtrudeExceptionobtrudeValueorTimeoutresultNowrunAfterBothrunAfterBothAsyncrunAfterBothAsyncrunAfterEitherrunAfterEitherAsyncrunAfterEitherAsyncrunAsyncrunAsyncstatesupplyAsyncsupplyAsyncthenAcceptthenAcceptAsyncthenAcceptAsyncthenAcceptBoththenAcceptBothAsyncthenAcceptBothAsyncthenApplythenApplyAsyncthenApplyAsyncthenCombinethenCombineAsyncthenCombineAsyncthenComposethenComposeAsyncthenComposeAsyncthenRunthenRunAsyncthenRunAsynctoCompletableFuturetoStringwhenCompletewhenCompleteAsyncwhenCompleteAsync

Constructor Detail

Completableback to summary
public Completable()

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.

For example:

Callback.Completable.with(completable1 -> session.sendPartialText("hello", false, completable1))
    .compose(completable2 -> session.sendPartialText(" ", false, completable2))
    .compose(completable3 -> session.sendPartialText("world", true, completable3))
    .thenRun(session::demand);
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)
failback to summary
public void fail(Throwable x)

Overrides default org.eclipse.jetty.websocket.api.Callback.fail.

Doc from org.eclipse.jetty.websocket.api.Callback.fail.

Method to invoke to fail the callback.

Parameters
x:Throwable

the failure

Annotations
@Override
succeedback to summary
public void succeed()

Overrides default org.eclipse.jetty.websocket.api.Callback.succeed.

Doc from org.eclipse.jetty.websocket.api.Callback.succeed.

Method to invoke to succeed the callback.

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

Convenience method that creates a Completable that is passed to the given consumer and then returned.

For example:

Completable.with(completable -> session.sendText("TEXT", completable))
    .thenRun(session::demand);
Parameters
consumer:Consumer<Callback.Completable>

the consumer that receives the completable

Returns:Callback.Completable

a new completable passed to the consumer

See Also
compose(Consumer)