Top Description Inners Fields Constructors Methods
reactor.core

public final Class Disposables

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collection, .LinkedList, .List, .Objects, java.util.concurrent.atomic.AtomicBoolean, .AtomicReferenceFieldUpdater, java.util.stream.Stream, reactor.util.annotation.Nullable

A support class that offers factory methods for implementations of the specialized Disposable sub-interfaces (Disposable.Composite, Disposable.Swap).
Authors
Simon Baslé, Stephane Maldini

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Disposables.AlwaysDisposable

Immutable disposable that is always disposed.

pack-priv static class
pack-priv static class
Disposables.NeverDisposable

Immutable disposable that is never disposed.

pack-priv static class
Disposables.SimpleDisposable

A very simple Disposable that only wraps a mutable boolean for isDisposed().

pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final Disposable
DISPOSED

A singleton Disposable that represents a disposed instance.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Disposable.Composite

Returns:

an empty atomic Disposable.Composite
composite
()

Create a new empty Disposable.Composite with atomic guarantees on all mutative operations.

public static Disposable.Composite

Returns:

a pre-filled atomic Disposable.Composite
composite
(Disposable... disposables)

Create and initialize a new Disposable.Composite with atomic guarantees on all mutative operations.

public static Disposable.Composite

Returns:

a pre-filled atomic Disposable.Composite
composite
(Iterable<? extends Disposable> disposables)

Create and initialize a new Disposable.Composite with atomic guarantees on all mutative operations.

pack-priv static <T> boolean

Returns:

true if the Disposable held by the field was properly disposed
dispose
(AtomicReferenceFieldUpdater<T, Disposable>
the target field updater
updater
,
T
the target instance holding the field
holder
)

Atomically dispose the Disposable in the field if not already disposed.

public static Disposable

Returns:

a new disposed Disposable.
disposed
()

Return a new Disposable that is already disposed.

pack-priv static boolean

Returns:

true if d is DISPOSED
isDisposed
(Disposable
the disposable to check
d
)

Check if the given Disposable is the singleton DISPOSED.

public static Disposable

Returns:

a new Disposable that can never be disposed.
never
()

Return a new Disposable that can never be disposed.

pack-priv static <T> boolean

Returns:

true if the operation succeeded, false if the target field contained the common DISPOSED instance and the given disposable is not null but is disposed.
replace
(AtomicReferenceFieldUpdater<T, Disposable>
the target field updater
updater
,
T
the target instance holding the field
holder
,
Disposable
the new Disposable to set, null allowed
newValue
)

Atomically replace the Disposable in the field with the given new Disposable but do not dispose the old one.

pack-priv static <T> boolean

Returns:

true if successful, false if the field contains the DISPOSED instance.
set
(AtomicReferenceFieldUpdater<T, Disposable>
the target field updater
updater
,
T
the target instance holding the field
holder
,
Disposable
the new Disposable to set
newValue
)

Atomically set the field to a Disposable and dispose the old content.

public static Disposable

Returns:

a new Disposable initially not yet disposed.
single
()

Return a new simple Disposable instance that is initially not disposed but can be by calling Disposable#dispose().

public static Disposable.Swap

Returns:

an empty atomic Disposable.Swap
swap
()

Create a new empty Disposable.Swap with atomic guarantees on all mutative operations.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DISPOSEDback to summary
pack-priv static final Disposable DISPOSED

A singleton Disposable that represents a disposed instance. Should not be leaked to clients.

Constructor Detail

Disposablesback to summary
private Disposables()

Method Detail

compositeback to summary
public static Disposable.Composite composite()

Create a new empty Disposable.Composite with atomic guarantees on all mutative operations.

Returns:Disposable.Composite

an empty atomic Disposable.Composite

compositeback to summary
public static Disposable.Composite composite(Disposable... disposables)

Create and initialize a new Disposable.Composite with atomic guarantees on all mutative operations.

Returns:Disposable.Composite

a pre-filled atomic Disposable.Composite

compositeback to summary
public static Disposable.Composite composite(Iterable<? extends Disposable> disposables)

Create and initialize a new Disposable.Composite with atomic guarantees on all mutative operations.

Returns:Disposable.Composite

a pre-filled atomic Disposable.Composite

disposeback to summary
pack-priv static <T> boolean dispose(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder)

Atomically dispose the Disposable in the field if not already disposed.

Parameters
updater:AtomicReferenceFieldUpdater<T, Disposable>

the target field updater

holder:T

the target instance holding the field

Returns:boolean

true if the Disposable held by the field was properly disposed

disposedback to summary
public static Disposable disposed()

Return a new Disposable that is already disposed.

Returns:Disposable

a new disposed Disposable.

isDisposedback to summary
pack-priv static boolean isDisposed(Disposable d)

Check if the given Disposable is the singleton DISPOSED.

Parameters
d:Disposable

the disposable to check

Returns:boolean

true if d is DISPOSED

neverback to summary
public static Disposable never()

Return a new Disposable that can never be disposed. Calling Disposable#dispose() is a NO-OP and Disposable#isDisposed() always return false.

Returns:Disposable

a new Disposable that can never be disposed.

replaceback to summary
pack-priv static <T> boolean replace(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, Disposable newValue)

Atomically replace the Disposable in the field with the given new Disposable but do not dispose the old one.

Parameters
updater:AtomicReferenceFieldUpdater<T, Disposable>

the target field updater

holder:T

the target instance holding the field

newValue:Disposable

the new Disposable to set, null allowed

Returns:boolean

true if the operation succeeded, false if the target field contained the common DISPOSED instance and the given disposable is not null but is disposed.

setback to summary
pack-priv static <T> boolean set(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, Disposable newValue)

Atomically set the field to a Disposable and dispose the old content.

Parameters
updater:AtomicReferenceFieldUpdater<T, Disposable>

the target field updater

holder:T

the target instance holding the field

newValue:Disposable

the new Disposable to set

Returns:boolean

true if successful, false if the field contains the DISPOSED instance.

singleback to summary
public static Disposable single()

Return a new simple Disposable instance that is initially not disposed but can be by calling Disposable#dispose().

Returns:Disposable

a new Disposable initially not yet disposed.

swapback to summary
public static Disposable.Swap swap()

Create a new empty Disposable.Swap with atomic guarantees on all mutative operations.

Returns:Disposable.Swap

an empty atomic Disposable.Swap

reactor.core back to summary

pack-priv final Class Disposables.AlwaysDisposable

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
reactor.core.Disposable

Immutable disposable that is always disposed. Calling dispose() does nothing, and isDisposed() always return true.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AlwaysDisposableback to summary
pack-priv AlwaysDisposable()

Method Detail

disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
reactor.core back to summary

pack-priv final Class Disposables.ListCompositeDisposable

extends Object
implements Composite, Scannable
Class Inheritance
All Implemented Interfaces
reactor.core.Scannable, reactor.core.Disposable.Composite, reactor.core.Disposable

Authors
David Karnok, Simon Baslé

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv List<Disposable>

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
add(Disposable
the Disposable to add.
d
)

Implements reactor.core.Disposable.Composite.add.

Add a Disposable to this container, if it is not disposed.
public boolean
addAll(Collection<? extends Disposable>
the collection of Disposables
ds
)

Overrides default reactor.core.Disposable.Composite.addAll.

Adds the given collection of Disposables to the container or disposes them all if the container has been disposed.
pack-priv Stream<Disposable>
public void
public void
dispose()

Implements reactor.core.Disposable.Composite.dispose.

Atomically mark the container as disposed, clear it and then dispose all the previously contained Disposables.
pack-priv void
public Stream<? extends Scannable>
inners()

Overrides default reactor.core.Scannable.inners.

Return a Stream of referenced inners (flatmap, multicast etc)
public boolean
isDisposed()

Implements reactor.core.Disposable.Composite.isDisposed.

Indicates if the container has already been disposed.
public boolean
remove(Disposable
the Disposable to remove.
d
)

Implements reactor.core.Disposable.Composite.remove.

Delete the Disposable from this container, without disposing it.
public Object
scanUnsafe(Scannable.Attr<T>
a Attr to resolve for the component.
key
)

Implements reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place.
public int
size()

Implements reactor.core.Disposable.Composite.size.

Returns the number of currently held Disposables.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

disposedback to summary
pack-priv volatile boolean disposed
resourcesback to summary
pack-priv List<Disposable> resources
Annotations
@Nullable

Constructor Detail

ListCompositeDisposableback to summary
pack-priv ListCompositeDisposable()
ListCompositeDisposableback to summary
pack-priv ListCompositeDisposable(Disposable... resources)
ListCompositeDisposableback to summary
pack-priv ListCompositeDisposable(Iterable<? extends Disposable> resources)

Method Detail

addback to summary
public boolean add(Disposable d)

Implements reactor.core.Disposable.Composite.add.

Doc from reactor.core.Disposable.Composite.add.

Add a Disposable to this container, if it is not disposed. Otherwise d is disposed immediately.

Parameters
d:Disposable

the Disposable to add.

Returns:boolean

true if the disposable could be added, false otherwise.

Annotations
@Override
addAllback to summary
public boolean addAll(Collection<? extends Disposable> ds)

Overrides default reactor.core.Disposable.Composite.addAll.

Doc from reactor.core.Disposable.Composite.addAll.

Adds the given collection of Disposables to the container or disposes them all if the container has been disposed.

Parameters
ds:Collection<? extends Disposable>

the collection of Disposables

Returns:boolean

true if the operation was successful, false if the container has been disposed

Annotations
@Override
asStreamback to summary
pack-priv Stream<Disposable> asStream()
clearback to summary
public void clear()
disposeback to summary
public void dispose()

Implements reactor.core.Disposable.Composite.dispose.

Doc from reactor.core.Disposable.Composite.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.

Annotations
@Override
disposeback to summary
pack-priv void dispose(List<Disposable> set)
innersback to summary
public Stream<? extends Scannable> inners()

Overrides default reactor.core.Scannable.inners.

Doc from reactor.core.Scannable.inners.

Return a Stream of referenced inners (flatmap, multicast etc)

Returns:Stream<? extends Scannable>

a Stream of referenced inners (flatmap, multicast etc)

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements reactor.core.Disposable.Composite.isDisposed.

Doc from reactor.core.Disposable.Composite.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.

Returns:boolean

true if the container has been disposed, false otherwise.

Annotations
@Override
removeback to summary
public boolean remove(Disposable d)

Implements reactor.core.Disposable.Composite.remove.

Doc from reactor.core.Disposable.Composite.remove.

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:Disposable

the Disposable to remove.

Returns:boolean

true if the disposable was successfully deleted, false otherwise.

Annotations
@Override
scanUnsafeback to summary
public Object scanUnsafe(Scannable.Attr<T> key)

Implements reactor.core.Scannable.scanUnsafe.

Doc from reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place. Although it is ignoring the generic type of the Attr key, implementors should take care to return values of the correct type, and return null if no specific value is available.

For public consumption of attributes, prefer using scan(Attr), which will return a typed value and fall back to the key's default if the component didn't define any mapping.

Parameters
key:Scannable.Attr<T>

a Attr to resolve for the component.

Returns:Object

the value associated to the key for that specific component, or null if none.

Annotations
@Nullable
@Override
sizeback to summary
public int size()

Implements reactor.core.Disposable.Composite.size.

Doc from reactor.core.Disposable.Composite.size.

Returns the number of currently held Disposables.

Returns:int

the number of currently held Disposables

Annotations
@Override
reactor.core back to summary

pack-priv final Class Disposables.NeverDisposable

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
reactor.core.Disposable

Immutable disposable that is never disposed. Calling dispose() does nothing, and isDisposed() always return false.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NeverDisposableback to summary
pack-priv NeverDisposable()

Method Detail

disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
reactor.core back to summary

pack-priv final Class Disposables.SimpleDisposable

extends AtomicBoolean
implements Disposable
Class Inheritance
All Implemented Interfaces
reactor.core.Disposable

A very simple Disposable that only wraps a mutable boolean for isDisposed().

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
Inherited from java.util.concurrent.atomic.AtomicBoolean:
compareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetgetgetAcquiregetAndSetgetOpaquegetPlainlazySetsetsetOpaquesetPlainsetReleasetoStringweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Constructor Detail

SimpleDisposableback to summary
pack-priv SimpleDisposable()

Method Detail

disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
reactor.core back to summary

pack-priv final Class Disposables.SwapDisposable

extends Object
implements Swap
Class Inheritance
All Implemented Interfaces
reactor.core.Disposable.Swap, java.util.function.Supplier, reactor.core.Disposable

Not public API. Implementation of a Swap.
Authors
Simon Baslé, David Karnok

Field Summary

Modifier and TypeField and Description
pack-priv volatile Disposable
pack-priv static final AtomicReferenceFieldUpdater<Disposables.SwapDisposable, Disposable>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public Disposable
get()

Implements java.util.function.Supplier.get.

Gets a result.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public boolean
replace(Disposable
the Disposable to set, may be null
next
)

Implements reactor.core.Disposable.Swap.replace.

Atomically set the next Disposable on this container but don't dispose the previous one (if any).
public boolean
update(Disposable
the Disposable to set, may be null
next
)

Implements reactor.core.Disposable.Swap.update.

Atomically set the next Disposable on this container and dispose the previous one (if any).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

innerback to summary
pack-priv volatile Disposable inner
INNERback to summary
pack-priv static final AtomicReferenceFieldUpdater<Disposables.SwapDisposable, Disposable> INNER

Constructor Detail

SwapDisposableback to summary
pack-priv SwapDisposable()

Method Detail

disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
getback to summary
public Disposable get()

Implements java.util.function.Supplier.get.

Doc from java.util.function.Supplier.get.

Gets a result.

Returns:Disposable

a result

Annotations
@Override
@Nullable
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
replaceback to summary
public boolean replace(Disposable next)

Implements reactor.core.Disposable.Swap.replace.

Doc from reactor.core.Disposable.Swap.replace.

Atomically set the next Disposable on this container but don't dispose the previous one (if any). If the container has been disposed, fall back to disposing next.

Parameters
next:Disposable

the Disposable to set, may be null

Returns:boolean

true if the operation succeeded, false if the container has been disposed

Annotations
@Override
updateback to summary
public boolean update(Disposable next)

Implements reactor.core.Disposable.Swap.update.

Doc from reactor.core.Disposable.Swap.update.

Atomically set the next Disposable on this container and dispose the previous one (if any). If the container has been disposed, fall back to disposing next.

Parameters
next:Disposable

the Disposable to set, may be null

Returns:boolean

true if the operation succeeded, false if the container has been disposed

Annotations
@Override