Package reactor.core

Interface Disposable.Composite

All Superinterfaces:
Disposable
Enclosing interface:
Disposable

public static interface Disposable.Composite extends Disposable
A container of Disposable that is itself Disposable. Accumulate disposables and dispose them all in one go by using dispose(). Using the add(Disposable) methods give ownership to the container, which is now responsible for disposing them. You can however retake ownership of individual elements by keeping a reference and using remove(Disposable), which puts the responsibility of disposing said elements back in your hands. Note that once disposed, the container cannot be reused and you will need a new Disposable.Composite.
Author:
Simon Baslé
  • Nested Class Summary

    Nested classes/interfaces inherited from interface reactor.core.Disposable

    Disposable.Composite, Disposable.Swap
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Add a Disposable to this container, if it is not disposed.
    default boolean
    addAll(Collection<? extends Disposable> ds)
    Adds the given collection of Disposables to the container or disposes them all if the container has been disposed.
    void
    Atomically mark the container as disposed, clear it and then dispose all the previously contained Disposables.
    boolean
    Indicates if the container has already been disposed.
    boolean
    Delete the Disposable from this container, without disposing it.
    int
    Returns the number of currently held Disposables.
  • Method Details

    • add

      boolean add(Disposable d)
      Add a Disposable to this container, if it is not disposed. Otherwise d is disposed immediately.
      Parameters:
      d - the Disposable to add.
      Returns:
      true if the disposable could be added, false otherwise.
    • addAll

      default boolean addAll(Collection<? extends Disposable> ds)
      Adds the given collection of Disposables to the container or disposes them all if the container has been disposed.
      Parameters:
      ds - the collection of Disposables
      Returns:
      true if the operation was successful, false if the container has been disposed
      Implementation Note:
      The default implementation is not atomic, meaning that if the container is disposed while the content of the collection is added, first elements might be effectively added. Stronger consistency is enforced by composites created via Disposables.composite() variants.
    • dispose

      void dispose()
      Atomically mark the container as disposed, clear it and then dispose all the previously contained Disposables. From there on the container cannot be reused, as add(Disposable) and addAll(Collection) methods will immediately return false.
      Specified by:
      dispose in interface Disposable
    • isDisposed

      boolean isDisposed()
      Indicates if the container has already been disposed.

      Note that if that is the case, attempts to add new disposable to it via add(Disposable) and addAll(Collection) will be rejected.

      Specified by:
      isDisposed in interface Disposable
      Returns:
      true if the container has been disposed, false otherwise.
    • remove

      boolean remove(Disposable d)
      Delete the Disposable from this container, without disposing it.

      It becomes the responsibility of the caller to dispose the value themselves, which they can do by a simple call to Disposable.dispose() on said value (probably guarded by a check that this method returned true, meaning the disposable was actually in the container).

      Parameters:
      d - the Disposable to remove.
      Returns:
      true if the disposable was successfully deleted, false otherwise.
    • size

      int size()
      Returns the number of currently held Disposables.
      Returns:
      the number of currently held Disposables