T - the type of itempublic class MultiOnFailure<T> extends Object
The upstream multi has sent us a failure, this class lets you decide what need to be done in this case. Typically,
you can recover with a fallback item (recoverWithItem(Object)), or with another Multi
(recoverWithMulti(Multi)), or simply completes the stream (recoverWithCompletion()). You can also
retry (retry()). Maybe, you just want to look at the failure (invoke(Consumer)).
You can configure the type of failure on which your handler is called using:
multi.onFailure(IOException.class).recoverWithItem("boom")
multi.onFailure(IllegalStateException.class).recoverWithItem("kaboom")
multi.onFailure(NoMoreDataException.class).recoverWithCompletion()
multi.onFailure(t -> accept(t)).recoverWithItem("another boom")
| Constructor and Description |
|---|
MultiOnFailure(Multi<T> upstream,
Predicate<? super Throwable> predicate) |
| Modifier and Type | Method and Description |
|---|---|
Multi<T> |
apply(Function<? super Throwable,? extends Throwable> mapper)
Deprecated.
|
Multi<T> |
invoke(Consumer<Throwable> callback)
|
Multi<T> |
invokeUni(Function<Throwable,? extends Uni<?>> action)
Produces a new
Multi invoking the given @{code action} when a failure event is received. |
Multi<T> |
recoverWithCompletion()
Recovers from the received failure (matching the predicate if set) by completing the stream.
|
Multi<T> |
recoverWithItem(Function<? super Throwable,? extends T> function)
Recovers from the received failure (matching the predicate if set) by using a item generated by the given
function.
|
Multi<T> |
recoverWithItem(Supplier<T> supplier)
Recovers from the received failure (matching the predicate if set) by using a item generated by the given
supplier.
|
Multi<T> |
recoverWithItem(T fallback)
Recovers from the received failure (matching the predicate if set) by using a fallback item.
|
Multi<T> |
recoverWithMulti(Function<? super Throwable,? extends Multi<? extends T>> function)
Recovers from the received failure (matching the predicate if set) with another
Multi. |
Multi<T> |
recoverWithMulti(Multi<? extends T> fallback)
Recovers from the received failure (matching the predicate if set) with another given
Multi. |
Multi<T> |
recoverWithMulti(Supplier<? extends Multi<? extends T>> supplier)
Recovers from the received failure (matching the predicate if set) with another
Multi. |
MultiRetry<T> |
retry()
Configures the retry strategy.
|
Multi<T> |
transform(Function<? super Throwable,? extends Throwable> mapper)
|
public Multi<T> invoke(Consumer<Throwable> callback)
Multi invoking the given callback when the upstream Multi emits a failure
(matching the predicate if set).
If the callback throws an exception, a CompositeException is propagated downstream.
This exception is composed by the received failure and the thrown exception.
callback - the callback, must not be nullMultipublic Multi<T> invokeUni(Function<Throwable,? extends Uni<?>> action)
Multi invoking the given @{code action} when a failure event is received.
Unlike invoke(Consumer), the passed function returns a Uni. When the produced Uni sends
its result, the result is discarded, and the original failure is forwarded downstream. If the produced
Uni fails, a CompositeException composed by the original failure and the
caught failure is propagated downstream.
If the asynchronous action throws an exception, this exception is propagated downstream as a
CompositeException composed with the original failure and the caught exception.
This method preserves the order of the items, meaning that the downstream received the items in the same order as the upstream has emitted them.
@Deprecated public Multi<T> apply(Function<? super Throwable,? extends Throwable> mapper)
transform(Function)Multi invoking the given function when the current Multi propagates a failure. The
function can transform the received failure into another exception that will be fired as failure downstream.mapper - the mapper function, must not be null, must not return nullMultipublic Multi<T> transform(Function<? super Throwable,? extends Throwable> mapper)
Multi invoking the given function when the current Multi propagates a failure. The
function can transform the received failure into another exception that will be fired as failure downstream.mapper - the mapper function, must not be null, must not return nullMultipublic Multi<T> recoverWithItem(T fallback)
fallback - the fallback, can be nullMulti that would emit the given fallback in case the upstream sends us a failure.public Multi<T> recoverWithItem(Supplier<T> supplier)
If the supplier throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
supplier - the supplier providing the fallback item. Must not be null, must not return null.Multi that would emit the produced item in case the upstream sends a failure.public Multi<T> recoverWithItem(Function<? super Throwable,? extends T> function)
If the function throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
function - the function providing the fallback item. Must not be null, must not return null.Multi that would emit the produced item in case the upstream sends a failure.public Multi<T> recoverWithCompletion()
Multi that would complete in case the upstream sends a failure.public Multi<T> recoverWithMulti(Function<? super Throwable,? extends Multi<? extends T>> function)
Multi. This multi
is produced by the given function. The function must not return null.
In case of failure, the downstream switches to the produced Multi.
If the function throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
function - the function providing the fallback Multi. Must not be null, must not return null.Multi that would emit events from the multi produced by the given function in case the
upstream sends a failure.public Multi<T> recoverWithMulti(Supplier<? extends Multi<? extends T>> supplier)
Multi. This multi
is produced by the given function. The supplier must not return null.
In case of failure, the downstream switches to the produced Multi.
If the supplier throws an exception, a CompositeException containing both the received
failure and the thrown exception is propagated downstream.
supplier - the function supplier the fallback Multi. Must not be null, must not return null.Multi that would emit events from the multi produced by the given supplier in case the
upstream sends a failure.public Multi<T> recoverWithMulti(Multi<? extends T> fallback)
Multi.
In case of failure, the downstream switches to the given Multi.
fallback - the fallback Multi. Must not be null.Multi that would emit events from the passed multi in case the upstream sends a failure.public MultiRetry<T> retry()
Copyright © 2019–2020 SmallRye. All rights reserved.