Class AsyncSubscription
- java.lang.Object
-
- java.lang.Number
-
- java.util.concurrent.atomic.AtomicLong
-
- io.reactivex.rxjava3.internal.subscriptions.AsyncSubscription
-
- All Implemented Interfaces:
Disposable,java.io.Serializable,org.reactivestreams.Subscription
public final class AsyncSubscription extends java.util.concurrent.atomic.AtomicLong implements org.reactivestreams.Subscription, Disposable
A subscription implementation that arbitrates exactly one other Subscription and can hold a single disposable resource.All methods are thread-safe.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription>actual(package private) java.util.concurrent.atomic.AtomicReference<Disposable>resourceprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description AsyncSubscription()AsyncSubscription(Disposable resource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()voiddispose()Dispose the resource, the operation should be idempotent.booleanisDisposed()Returns true if this resource has been disposed.booleanreplaceResource(Disposable r)Replaces the currently held resource with the given new one without disposing the old.voidrequest(long n)booleansetResource(Disposable r)Sets a new resource and disposes the currently held resource.voidsetSubscription(org.reactivestreams.Subscription s)Sets the given subscription if there isn't any subscription held.-
Methods inherited from class java.util.concurrent.atomic.AtomicLong
accumulateAndGet, addAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAcquire, getAndAccumulate, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, getAndUpdate, getOpaque, getPlain, incrementAndGet, intValue, lazySet, longValue, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
actual
final java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> actual
-
resource
final java.util.concurrent.atomic.AtomicReference<Disposable> resource
-
-
Constructor Detail
-
AsyncSubscription
public AsyncSubscription()
-
AsyncSubscription
public AsyncSubscription(Disposable resource)
-
-
Method Detail
-
request
public void request(long n)
- Specified by:
requestin interfaceorg.reactivestreams.Subscription
-
cancel
public void cancel()
- Specified by:
cancelin interfaceorg.reactivestreams.Subscription
-
dispose
public void dispose()
Description copied from interface:DisposableDispose the resource, the operation should be idempotent.- Specified by:
disposein interfaceDisposable
-
isDisposed
public boolean isDisposed()
Description copied from interface:DisposableReturns true if this resource has been disposed.- Specified by:
isDisposedin interfaceDisposable- Returns:
- true if this resource has been disposed
-
setResource
public boolean setResource(Disposable r)
Sets a new resource and disposes the currently held resource.- Parameters:
r- the new resource to set- Returns:
- false if this AsyncSubscription has been cancelled/disposed
- See Also:
replaceResource(Disposable)
-
replaceResource
public boolean replaceResource(Disposable r)
Replaces the currently held resource with the given new one without disposing the old.- Parameters:
r- the new resource to set- Returns:
- false if this AsyncSubscription has been cancelled/disposed
-
setSubscription
public void setSubscription(org.reactivestreams.Subscription s)
Sets the given subscription if there isn't any subscription held.- Parameters:
s- the first and only subscription to set
-
-