Class AtomicThrowable

  • All Implemented Interfaces:
    java.io.Serializable

    public final class AtomicThrowable
    extends java.util.concurrent.atomic.AtomicReference<java.lang.Throwable>
    Atomic container for Throwables including combining and having a terminal state via ExceptionHelper.

    Watch out for the leaked AtomicReference methods!

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      AtomicThrowable()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isTerminated()  
      java.lang.Throwable terminate()
      Atomically terminate the container and return the contents of the last non-terminal Throwable of it.
      boolean tryAddThrowable​(java.lang.Throwable t)
      Atomically adds a Throwable to this container (combining with a previous Throwable is necessary).
      boolean tryAddThrowableOrReport​(java.lang.Throwable t)
      Atomically adds a Throwable to this container (combining with a previous Throwable is necessary) or reports the error the global error handler and no changes are made.
      void tryTerminateAndReport()
      Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and calls RxJavaPlugins.onError(Throwable) if there was a non-null, non-indicator exception contained within before.
      void tryTerminateConsumer​(CompletableObserver consumer)
      Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError).
      void tryTerminateConsumer​(Emitter<?> consumer)
      Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError).
      void tryTerminateConsumer​(MaybeObserver<?> consumer)
      Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError).
      void tryTerminateConsumer​(Observer<?> consumer)
      Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError).
      void tryTerminateConsumer​(SingleObserver<?> consumer)
      Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError).
      void tryTerminateConsumer​(org.reactivestreams.Subscriber<?> consumer)
      Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError).
      • Methods inherited from class java.util.concurrent.atomic.AtomicReference

        accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AtomicThrowable

        public AtomicThrowable()
    • Method Detail

      • tryAddThrowable

        public boolean tryAddThrowable​(java.lang.Throwable t)
        Atomically adds a Throwable to this container (combining with a previous Throwable is necessary).
        Parameters:
        t - the throwable to add
        Returns:
        true if successful, false if the container has been terminated
      • tryAddThrowableOrReport

        public boolean tryAddThrowableOrReport​(java.lang.Throwable t)
        Atomically adds a Throwable to this container (combining with a previous Throwable is necessary) or reports the error the global error handler and no changes are made.
        Parameters:
        t - the throwable to add
        Returns:
        true if successful, false if the container has been terminated
      • terminate

        public java.lang.Throwable terminate()
        Atomically terminate the container and return the contents of the last non-terminal Throwable of it.
        Returns:
        the last Throwable
      • isTerminated

        public boolean isTerminated()
      • tryTerminateAndReport

        public void tryTerminateAndReport()
        Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and calls RxJavaPlugins.onError(Throwable) if there was a non-null, non-indicator exception contained within before.
        Since:
        3.0.0
      • tryTerminateConsumer

        public void tryTerminateConsumer​(org.reactivestreams.Subscriber<?> consumer)
        Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError). If there was a terminated indicator, the consumer is not signaled.
        Parameters:
        consumer - the consumer to notify
      • tryTerminateConsumer

        public void tryTerminateConsumer​(Observer<?> consumer)
        Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError). If there was a terminated indicator, the consumer is not signaled.
        Parameters:
        consumer - the consumer to notify
      • tryTerminateConsumer

        public void tryTerminateConsumer​(MaybeObserver<?> consumer)
        Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError). If there was a terminated indicator, the consumer is not signaled.
        Parameters:
        consumer - the consumer to notify
      • tryTerminateConsumer

        public void tryTerminateConsumer​(SingleObserver<?> consumer)
        Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError). If there was a terminated indicator, the consumer is not signaled.
        Parameters:
        consumer - the consumer to notify
      • tryTerminateConsumer

        public void tryTerminateConsumer​(CompletableObserver consumer)
        Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError). If there was a terminated indicator, the consumer is not signaled.
        Parameters:
        consumer - the consumer to notify
      • tryTerminateConsumer

        public void tryTerminateConsumer​(Emitter<?> consumer)
        Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) and notifies the consumer if there was no error (onComplete) or there was a non-null, non-indicator exception contained before (onError). If there was a terminated indicator, the consumer is not signaled.
        Parameters:
        consumer - the consumer to notify