T
- the value typepublic abstract class ResourceSubscriber<T> extends java.lang.Object implements org.reactivestreams.Subscriber<T>, Disposable
This implementation let's you chose if the AsyncObserver manages resources or not, thus saving memory on cases where there is no need for that.
All pre-implemented final methods are thread-safe.
Constructor and Description |
---|
ResourceSubscriber() |
Modifier and Type | Method and Description |
---|---|
void |
add(Disposable resource)
Adds a resource to this AsyncObserver.
|
protected void |
cancel()
Cancels the subscription (if any) and disposes the resources associated with
this AsyncObserver (if any).
|
void |
dispose()
Dispose the resource, the operation should be idempotent.
|
boolean |
isDisposed()
Returns true if this AsyncObserver has been disposed/cancelled.
|
protected void |
onStart()
Called once the upstream sets a Subscription on this AsyncObserver.
|
void |
onSubscribe(org.reactivestreams.Subscription s) |
protected void |
request(long n)
Request the specified amount of elements from upstream.
|
public final void add(Disposable resource)
resource
- the resource to addjava.lang.NullPointerException
- if resource is nullpublic final void onSubscribe(org.reactivestreams.Subscription s)
onSubscribe
in interface org.reactivestreams.Subscriber<T>
protected void onStart()
You can perform initialization at this moment. The default implementation requests Long.MAX_VALUE from upstream.
protected final void request(long n)
This method can be called before the upstream calls onSubscribe(). When the subscription happens, all missed requests are requested.
n
- the request amount, must be positiveprotected final void cancel()
This method can be called before the upstream calls onSubscribe at which case the Subscription will be immediately cancelled.
public final void dispose()
Disposable
dispose
in interface Disposable
public final boolean isDisposed()
isDisposed
in interface Disposable