Package reactor.core
Interface Disposable.Composite
- All Superinterfaces:
Disposable
- Enclosing interface:
- 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 TypeMethodDescriptionbooleanadd(Disposable d) Add aDisposableto this container, if it is notdisposed.default booleanaddAll(Collection<? extends Disposable> ds) Adds the given collection of Disposables to the container or disposes them all if the container has been disposed.voiddispose()Atomically mark the container asdisposed, clear it and then dispose all the previously contained Disposables.booleanIndicates if the container has already been disposed.booleanremove(Disposable d) Delete theDisposablefrom this container, without disposing it.intsize()Returns the number of currently held Disposables.
-
Method Details
-
add
Add aDisposableto this container, if it is notdisposed. Otherwise d is disposed immediately.- Parameters:
d- theDisposableto add.- Returns:
- true if the disposable could be added, false otherwise.
-
addAll
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 asdisposed, clear it and then dispose all the previously contained Disposables. From there on the container cannot be reused, asadd(Disposable)andaddAll(Collection)methods will immediately return false.- Specified by:
disposein interfaceDisposable
-
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)andaddAll(Collection)will be rejected.- Specified by:
isDisposedin interfaceDisposable- Returns:
- true if the container has been disposed, false otherwise.
-
remove
Delete theDisposablefrom 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- theDisposableto 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
-