Class SequentialDisposable

  • All Implemented Interfaces:
    Disposable, java.io.Serializable

    public final class SequentialDisposable
    extends java.util.concurrent.atomic.AtomicReference<Disposable>
    implements Disposable
    A Disposable container that allows updating/replacing a Disposable atomically and with respect of disposing the container itself.

    The class extends AtomicReference directly so watch out for the API leak!

    Since:
    2.0
    See Also:
    Serialized Form
    • Field Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()
      Dispose the resource, the operation should be idempotent.
      boolean isDisposed()
      Returns true if this resource has been disposed.
      boolean replace​(Disposable next)
      Atomically: set the next disposable on this container but don't dispose the previous one (if any) or dispose next if the container has been disposed.
      boolean update​(Disposable next)
      Atomically: set the next disposable on this container and dispose the previous one (if any) or dispose next if the container has been disposed.
      • 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

      • SequentialDisposable

        public SequentialDisposable()
        Constructs an empty SequentialDisposable.
      • SequentialDisposable

        public SequentialDisposable​(Disposable initial)
        Construct a SequentialDisposable with the initial Disposable provided.
        Parameters:
        initial - the initial disposable, null allowed
    • Method Detail

      • update

        public boolean update​(Disposable next)
        Atomically: set the next disposable on this container and dispose the previous one (if any) or dispose next if the container has been disposed.
        Parameters:
        next - the Disposable to set, may be null
        Returns:
        true if the operation succeeded, false if the container has been disposed
        See Also:
        replace(Disposable)
      • replace

        public boolean replace​(Disposable next)
        Atomically: set the next disposable on this container but don't dispose the previous one (if any) or dispose next if the container has been disposed.
        Parameters:
        next - the Disposable to set, may be null
        Returns:
        true if the operation succeeded, false if the container has been disposed
        See Also:
        update(Disposable)
      • dispose

        public void dispose()
        Description copied from interface: Disposable
        Dispose the resource, the operation should be idempotent.
        Specified by:
        dispose in interface Disposable
      • isDisposed

        public boolean isDisposed()
        Description copied from interface: Disposable
        Returns true if this resource has been disposed.
        Specified by:
        isDisposed in interface Disposable
        Returns:
        true if this resource has been disposed