Enum DisposableHelper
- java.lang.Object
-
- java.lang.Enum<DisposableHelper>
-
- io.reactivex.rxjava3.internal.disposables.DisposableHelper
-
- All Implemented Interfaces:
Disposable
,java.io.Serializable
,java.lang.Comparable<DisposableHelper>
public enum DisposableHelper extends java.lang.Enum<DisposableHelper> implements Disposable
Utility methods for working with Disposables atomically.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description DISPOSED
The singleton instance representing a terminal, disposed state, don't leak it.
-
Constructor Summary
Constructors Modifier Constructor Description private
DisposableHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Dispose the resource, the operation should be idempotent.static boolean
dispose(java.util.concurrent.atomic.AtomicReference<Disposable> field)
Atomically disposes the Disposable in the field if not already disposed.boolean
isDisposed()
Returns true if this resource has been disposed.static boolean
isDisposed(Disposable d)
Checks if the given Disposable is the commonDISPOSED
enum value.static boolean
replace(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically replaces the Disposable in the field with the given new Disposable but does not dispose the old one.static void
reportDisposableSet()
Reports that the disposable is already set to the RxJavaPlugins error handler.static boolean
set(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically sets the field and disposes the old contents.static boolean
setOnce(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically sets the field to the given non-null Disposable and returns true or returns false if the field is non-null.static boolean
trySet(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically tries to set the given Disposable on the field if it is null or disposes it if the field containsDISPOSED
.static boolean
validate(Disposable current, Disposable next)
Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.static DisposableHelper
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static DisposableHelper[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
DISPOSED
public static final DisposableHelper DISPOSED
The singleton instance representing a terminal, disposed state, don't leak it.
-
-
Method Detail
-
values
public static DisposableHelper[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DisposableHelper c : DisposableHelper.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DisposableHelper valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
isDisposed
public static boolean isDisposed(Disposable d)
Checks if the given Disposable is the commonDISPOSED
enum value.- Parameters:
d
- the disposable to check- Returns:
- true if d is
DISPOSED
-
set
public static boolean set(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically sets the field and disposes the old contents.- Parameters:
field
- the target fieldd
- the new Disposable to set- Returns:
- true if successful, false if the field contains the
DISPOSED
instance.
-
setOnce
public static boolean setOnce(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically sets the field to the given non-null Disposable and returns true or returns 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 RxJavaPlugins.onError hook.- Parameters:
field
- the target fieldd
- the disposable to set, not null- Returns:
- true if the operation succeeded, false
-
replace
public static boolean replace(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically replaces the Disposable in the field with the given new Disposable but does not dispose the old one.- Parameters:
field
- the target field to changed
- the new disposable, null allowed- Returns:
- true if the operation succeeded, false if the target field contained the common DISPOSED instance and the given disposable (if not null) is disposed.
-
dispose
public static boolean dispose(java.util.concurrent.atomic.AtomicReference<Disposable> field)
Atomically disposes the Disposable in the field if not already disposed.- Parameters:
field
- the target field- Returns:
- true if the current thread managed to dispose the Disposable
-
validate
public static boolean validate(Disposable current, Disposable next)
Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.- Parameters:
current
- the current Disposable, expected to be nullnext
- the next Disposable, expected to be non-null- Returns:
- true if the validation succeeded
-
reportDisposableSet
public static void reportDisposableSet()
Reports that the disposable is already set to the RxJavaPlugins error handler.
-
trySet
public static boolean trySet(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
Atomically tries to set the given Disposable on the field if it is null or disposes it if the field containsDISPOSED
.- Parameters:
field
- the target fieldd
- the disposable to set- Returns:
- true if successful, false otherwise
-
dispose
public void dispose()
Description copied from interface:Disposable
Dispose the resource, the operation should be idempotent.- Specified by:
dispose
in interfaceDisposable
-
isDisposed
public boolean isDisposed()
Description copied from interface:Disposable
Returns true if this resource has been disposed.- Specified by:
isDisposed
in interfaceDisposable
- Returns:
- true if this resource has been disposed
-
-