Interface DisposableContainer

All Superinterfaces:
AutoCloseable, Disposable
All Known Implementing Classes:
CompositeDisposable, DisposableContainer.NeverDisposableContainer

public interface DisposableContainer extends Disposable
Common interface to add and remove disposables from a container.
Since:
2.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    Implementation of a never disposable container.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final DisposableContainer
    The container implementation that just ignores everything, for cases where the dispose signal has no side-effects to work with.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Adds a disposable to this container or disposes it if the container has been disposed.
    void
    Removes and disposes all contained Disposables, making this container fresh without disposing the entire container.
    boolean
    Removes but does not dispose the given disposable if it is part of this container.
    default Disposable
    Registers a Disposable with this container so that it can be removed and disposed via a simple Disposable.dispose() call to the returned Disposable.
    boolean
    Removes and disposes the given disposable if it is part of this container.
    void
    Removes all contained Disposables without disposing them, making this container fresh.
    default Disposable
    Registers a Disposable with this container so that it can be deleted, not disposed via a simple Disposable.dispose() call to the returned Disposable.

    Methods inherited from interface Disposable

    close, dispose, isDisposed
    Modifier and Type
    Method
    Description
    default void
    Dispose the resource, the operation should be idempotent.
    void
    Dispose the resource, the operation should be idempotent.
    boolean
    Returns true if this resource has been disposed.
  • Field Details

    • NEVER

      static final DisposableContainer NEVER
      The container implementation that just ignores everything, for cases where the dispose signal has no side-effects to work with.
      Since:
      4.0.0
  • Method Details

    • add

      boolean add(Disposable d)
      Adds a disposable to this container or disposes it if the container has been disposed.
      Parameters:
      d - the disposable to add, not null
      Returns:
      true if successful, false if this container has been disposed
    • remove

      boolean remove(Disposable d)
      Removes and disposes the given disposable if it is part of this container.
      Parameters:
      d - the disposable to remove and dispose, not null
      Returns:
      true if the operation was successful
    • delete

      boolean delete(Disposable d)
      Removes but does not dispose the given disposable if it is part of this container.
      Parameters:
      d - the disposable to remove, not null
      Returns:
      true if the operation was successful
    • reset

      void reset()
      Removes all contained Disposables without disposing them, making this container fresh.
      Since:
      4.0.0
    • clear

      void clear()
      Removes and disposes all contained Disposables, making this container fresh without disposing the entire container.
    • register

      default Disposable register(Disposable d)
      Registers a Disposable with this container so that it can be removed and disposed via a simple Disposable.dispose() call to the returned Disposable.
      Parameters:
      d - the disposable to register
      Returns:
      the Disposable to trigger a remove(Disposable)
      Since:
      4.0.0
      See Also:
    • subscribe

      default Disposable subscribe(Disposable d)
      Registers a Disposable with this container so that it can be deleted, not disposed via a simple Disposable.dispose() call to the returned Disposable.
      Parameters:
      d - the disposable to register
      Returns:
      the Disposable to trigger a remove(Disposable)
      Since:
      4.0.0
      See Also: