Class ArrayCompositeDisposable

java.lang.Object
java.util.concurrent.atomic.AtomicReferenceArray<Disposable>
io.reactivex.rxjava3.internal.disposables.ArrayCompositeDisposable
All Implemented Interfaces:
Disposable, Serializable

public final class ArrayCompositeDisposable extends AtomicReferenceArray<Disposable> implements Disposable
A composite disposable with a fixed number of slots.

Note that since the implementation leaks the methods of AtomicReferenceArray, one must be careful to only call setResource, replaceResource and dispose on it. All other methods may lead to undefined behavior and should be used by internal means only.

See Also:
  • Field Details

  • Constructor Details

    • ArrayCompositeDisposable

      public ArrayCompositeDisposable(int capacity)
  • Method Details

    • setResource

      public boolean setResource(int index, Disposable resource)
      Sets the resource at the specified index and disposes the old resource.
      Parameters:
      index - the index of the resource to set
      resource - the new resource
      Returns:
      true if the resource has ben set, false if the composite has been disposed
    • replaceResource

      public Disposable replaceResource(int index, Disposable resource)
      Replaces the resource at the specified index and returns the old resource.
      Parameters:
      index - the index of the resource to replace
      resource - the new resource
      Returns:
      the old resource, can be null
    • 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