Class ErrorDeflector


  • public final class ErrorDeflector
    extends java.lang.Object
    Provides 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 the publishException(Throwable) method. Further it will be included in the errors stream pair in case the two factory methods for these are used (stream(Publisher) or streamNonEmpty(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 ErrorDeflector create()
      Factory method to create a new error deflector.
      void deflectExceptions​(java.lang.Runnable runnable)
      Deflects all exceptions appearing in the execution of the runnable onto the error stream.
      <T> T deflectExceptions​(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)
      <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)
      <T> io.reactivex.functions.Predicate<T> falseOnException​(java.util.function.Predicate<T> predicate)  
      void publishException​(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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 strem
        defaultValue - 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)
      • 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)
      • 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)