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>
resource
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description AsyncSubscription()
AsyncSubscription(Disposable resource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
void
dispose()
Dispose the resource, the operation should be idempotent.boolean
isDisposed()
Returns true if this resource has been disposed.boolean
replaceResource(Disposable r)
Replaces the currently held resource with the given new one without disposing the old.void
request(long n)
boolean
setResource(Disposable r)
Sets a new resource and disposes the currently held resource.void
setSubscription(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:
request
in interfaceorg.reactivestreams.Subscription
-
cancel
public void cancel()
- Specified by:
cancel
in interfaceorg.reactivestreams.Subscription
-
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
-
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
-
-