Package org.streamingpool.core.domain
Class ErrorDeflector
- java.lang.Object
-
- org.streamingpool.core.domain.ErrorDeflector
-
public final class ErrorDeflector extends java.lang.ObjectProvides different ways to intercept exceptions from streams (or lambdas) and deflect the caught exceptions onto an error stream. The error stream (subject) is created internally. An external event can be pushed onto it bu using thepublishException(Throwable)method. Further it will be included in the errors stream pair in case the two factory methods for these are used (stream(Publisher)orstreamNonEmpty(Publisher)).Since one error stream usually corresponds to one data stream, each time a new stream is created, a new instance of an error deflector should be created, so that the contained error stream is not shared between different data streams.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ErrorDeflectorcreate()Factory method to create a new error deflector.voiddeflectExceptions(java.lang.Runnable runnable)Deflects all exceptions appearing in the execution of the runnable onto the error stream.<T> TdeflectExceptions(java.util.function.Supplier<T> supplier, T defaultValue)Deflects all exceptions appearing in the supplier onto the error stream.<S,T>
io.reactivex.functions.Function<S,java.util.Optional<T>>emptyOnError(java.util.function.Function<S,T> function)Deprecated.<S,T>
io.reactivex.functions.Function<S,java.util.Optional<T>>emptyOnException(java.util.function.Function<S,T> function)<T> java.util.Optional<T>emptyOnException(java.util.function.Supplier<T> callable)<T> io.reactivex.functions.Predicate<T>falseOnError(java.util.function.Predicate<T> predicate)Deprecated.<T> io.reactivex.functions.Predicate<T>falseOnException(java.util.function.Predicate<T> predicate)voidpublishException(java.lang.Throwable exception)<T> ErrorStreamPair<T>stream(org.reactivestreams.Publisher<T> dataPublisher)<T> ErrorStreamPair<T>streamNonEmpty(org.reactivestreams.Publisher<java.util.Optional<T>> optionalPublisher)
-
-
-
Method Detail
-
create
public static final ErrorDeflector create()
Factory method to create a new error deflector. Each error deflector contains its own instance of an error stream.- Returns:
- a new error deflector.
-
deflectExceptions
public void deflectExceptions(java.lang.Runnable runnable)
Deflects all exceptions appearing in the execution of the runnable onto the error stream.- Parameters:
runnable- the runnable which shall be executed and whose exceptions shall be deflected
-
deflectExceptions
public <T> T deflectExceptions(java.util.function.Supplier<T> supplier, T defaultValue)Deflects all exceptions appearing in the supplier onto the error stream. In case an exception occures, then the given default value is returned.- Parameters:
supplier- the supplier which shall be executed and whose errors shall be deflected onto the error stremdefaultValue- the default value to return in case an exception occured- Returns:
- the value from the supplier or the default one.
-
emptyOnException
public <T> java.util.Optional<T> emptyOnException(java.util.function.Supplier<T> callable)
-
emptyOnException
public <S,T> io.reactivex.functions.Function<S,java.util.Optional<T>> emptyOnException(java.util.function.Function<S,T> function)
-
emptyOnError
@Deprecated public <S,T> io.reactivex.functions.Function<S,java.util.Optional<T>> emptyOnError(java.util.function.Function<S,T> function)
Deprecated.
-
falseOnException
public <T> io.reactivex.functions.Predicate<T> falseOnException(java.util.function.Predicate<T> predicate)
-
falseOnError
@Deprecated public <T> io.reactivex.functions.Predicate<T> falseOnError(java.util.function.Predicate<T> predicate)
Deprecated.
-
publishException
public void publishException(java.lang.Throwable exception)
-
stream
public <T> ErrorStreamPair<T> stream(org.reactivestreams.Publisher<T> dataPublisher)
-
streamNonEmpty
public <T> ErrorStreamPair<T> streamNonEmpty(org.reactivestreams.Publisher<java.util.Optional<T>> optionalPublisher)
-
-