Top Description Fields Constructors Methods
reactor.core.publisher

pack-priv final Class OperatorDisposables

extends Object
Class Inheritance
Imports
java.util.Objects, java.util.concurrent.atomic.AtomicReferenceFieldUpdater, java.util.function.Consumer, reactor.core.Disposable, .Disposables, reactor.util.annotation.Nullable

Utility methods to work with Disposable atomically.
Authors
Simon Baslé, David Karnok

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
pack-priv

Method Summary

Modifier and TypeMethod and Description
public 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 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 <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.

public 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 <T> boolean

Returns:

true if the operation succeeded, false
setOnce
(AtomicReferenceFieldUpdater<T, Disposable>
the target field updater
updater
,
T
the target instance holding the field
holder
,
Disposable
the new Disposable to set, not null
newValue
,
Consumer<RuntimeException> errorCallback)

Atomically set the field to the given non-null Disposable and return true, or return false if the field is non-null.

public static <T> boolean

Returns:

true if successful, false otherwise
trySet
(AtomicReferenceFieldUpdater<T, Disposable>
the target field updater
updater
,
T
the target instance holding the field
holder
,
Disposable
the disposable to set
newValue
)

Atomically try to set the given Disposable on the field if it is null or disposes it if the field contains DISPOSED.

public static boolean

Returns:

true if the validation succeeded
validate
(Disposable
the current Disposable, expected to be null
current
,
Disposable
the next Disposable, expected to be non-null
next
,
Consumer<RuntimeException> errorCallback)

Verify that current is null and next is not null, otherwise signal a NullPointerException to the errorCallback and return false.

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

OperatorDisposablesback to summary
pack-priv OperatorDisposables()

Method Detail

disposeback to summary
public 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

isDisposedback to summary
public 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

replaceback to summary
public 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
public 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.

setOnceback to summary
public static <T> boolean setOnce(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, Disposable newValue, Consumer<RuntimeException> errorCallback)

Atomically set the field to the given non-null Disposable and return true, or return false if the field is non-null. If the target field contains the common DISPOSED instance, the supplied disposable is disposed. If the field contains other non-null Disposable, an IllegalStateException is signalled to the errorCallback.

Parameters
updater:AtomicReferenceFieldUpdater<T, Disposable>

the target field updater

holder:T

the target instance holding the field

newValue:Disposable

the new Disposable to set, not null

Returns:boolean

true if the operation succeeded, false

trySetback to summary
public static <T> boolean trySet(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, Disposable newValue)

Atomically try to set the given Disposable on the field if it is null or disposes it if the field contains DISPOSED.

Parameters
updater:AtomicReferenceFieldUpdater<T, Disposable>

the target field updater

holder:T

the target instance holding the field

newValue:Disposable

the disposable to set

Returns:boolean

true if successful, false otherwise

validateback to summary
public static boolean validate(Disposable current, Disposable next, Consumer<RuntimeException> errorCallback)

Verify that current is null and next is not null, otherwise signal a NullPointerException to the errorCallback and return false.

Parameters
current:Disposable

the current Disposable, expected to be null

next:Disposable

the next Disposable, expected to be non-null

Returns:boolean

true if the validation succeeded