- Type Parameters:
T- the type of item
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionProduces a newMultiinvoking the given @{code action} when afailureevent is received.Produces a newMultiinvoking the given @{code action} when afailureevent is received.Recovers from the received failure (matching the predicate if set) by completing the stream.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.recoverWithItem(Supplier<T> supplier) Recovers from the received failure (matching the predicate if set) by using a item generated by the given supplier.recoverWithItem(T fallback) Recovers from the received failure (matching the predicate if set) by using a fallback item.recoverWithMulti(Multi<? extends T> fallback) Recovers from the received failure (matching the predicate if set) with another givenMulti.recoverWithMulti(Function<? super Throwable, Multi<? extends T>> function) Recovers from the received failure (matching the predicate if set) with anotherMulti.recoverWithMulti(Supplier<Multi<? extends T>> supplier) Recovers from the received failure (matching the predicate if set) with anotherMulti.retry()Configures the retry strategy.
-
Constructor Details
-
MultiOnFailure
-
-
Method Details
-
invoke
Produces a newMultiinvoking the given callback when the upstreamMultiemits a failure (matching the predicate if set).If the callback throws an exception, a
CompositeExceptionis propagated downstream. This exception is composed by the received failure and the thrown exception.- Parameters:
callback- the callback, must not benull- Returns:
- the new
Multi
-
invoke
Produces a newMultiinvoking the given callback when the upstreamMultiemits a failure (matching the predicate if set), and ignoring the failure in the callback.If the callback throws an exception, a
CompositeExceptionis propagated downstream. This exception is composed by the received failure and the thrown exception.- Parameters:
callback- the callback, must not benull- Returns:
- the new
Multi
-
call
Produces a newMultiinvoking the given @{code action} when afailureevent is received.Unlike
invoke(Consumer), the passed function returns aUni. When the producedUnisends its result, the result is discarded, and the originalfailureis forwarded downstream. If the producedUnifails, aCompositeExceptioncomposed 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
CompositeExceptioncomposed 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.
-
call
Produces a newMultiinvoking the given @{code action} when afailureevent is received.Unlike
invoke(Consumer), the passed function returns aUni. When the producedUnisends its result, the result is discarded, and the originalfailureis forwarded downstream. If the producedUnifails, aCompositeExceptioncomposed 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
CompositeExceptioncomposed 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.
-
transform
Produces a newMultiinvoking the given function when the currentMultipropagates a failure. The function can transform the received failure into another exception that will be fired as failure downstream.- Parameters:
mapper- the mapper function, must not benull, must not returnnull- Returns:
- the new
Multi
-
recoverWithItem
Recovers from the received failure (matching the predicate if set) by using a fallback item.- Parameters:
fallback- the fallback, can benull- Returns:
- the new
Multithat would emit the given fallback in case the upstream sends us a failure.
-
recoverWithItem
Recovers from the received failure (matching the predicate if set) by using a item generated by the given supplier. The supplier is called when the failure is received.If the supplier throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
supplier- the supplier providing the fallback item. Must not benull, must not returnnull.- Returns:
- the new
Multithat would emit the produced item in case the upstream sends a failure.
-
recoverWithItem
Recovers from the received failure (matching the predicate if set) by using a item generated by the given function. The function is called when the failure is received.If the function throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
function- the function providing the fallback item. Must not benull, must not returnnull.- Returns:
- the new
Multithat would emit the produced item in case the upstream sends a failure.
-
recoverWithCompletion
Recovers from the received failure (matching the predicate if set) by completing the stream. Upon failure, it sends the completion event downstream.- Returns:
- the new
Multithat would complete in case the upstream sends a failure.
-
recoverWithMulti
@CheckReturnValue public Multi<T> recoverWithMulti(Function<? super Throwable, Multi<? extends T>> function) Recovers from the received failure (matching the predicate if set) with anotherMulti. Thismultiis produced by the given function. The function must not returnnull.In case of failure, the downstream switches to the produced
Multi.If the function throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
function- the function providing the fallback Multi. Must not benull, must not returnnull.- Returns:
- the new
Multithat would emit events from the multi produced by the given function in case the upstream sends a failure.
-
recoverWithMulti
Recovers from the received failure (matching the predicate if set) with anotherMulti. Thismultiis produced by the given function. The supplier must not returnnull.In case of failure, the downstream switches to the produced
Multi.If the supplier throws an exception, a
CompositeExceptioncontaining both the received failure and the thrown exception is propagated downstream.- Parameters:
supplier- the function supplier the fallback Multi. Must not benull, must not returnnull.- Returns:
- the new
Multithat would emit events from the multi produced by the given supplier in case the upstream sends a failure.
-
recoverWithMulti
Recovers from the received failure (matching the predicate if set) with another givenMulti.In case of failure, the downstream switches to the given
Multi.- Parameters:
fallback- the fallback Multi. Must not benull.- Returns:
- the new
Multithat would emit events from the passed multi in case the upstream sends a failure.
-
retry
Configures the retry strategy.- Returns:
- the object to configure the retry.
-