Class AsyncSubscription
java.lang.Object
java.lang.Number
java.util.concurrent.atomic.AtomicLong
io.reactivex.rxjava3.internal.subscriptions.AsyncSubscription
- All Implemented Interfaces:
Disposable
,Serializable
,org.reactivestreams.Subscription
public final class AsyncSubscription
extends 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:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final AtomicReference
<org.reactivestreams.Subscription> (package private) final AtomicReference
<Disposable> private static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
void
dispose()
Dispose the resource, the operation should be idempotent.boolean
Returns true if this resource has been disposed.boolean
Replaces the currently held resource with the given new one without disposing the old.void
request
(long n) boolean
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
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
actual
-
resource
-
-
Constructor Details
-
AsyncSubscription
public AsyncSubscription() -
AsyncSubscription
-
-
Method Details
-
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
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
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
-