T - the value typepublic abstract class AsyncObserver<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 |
|---|
AsyncObserver()
Constructs an AsyncObserver with resource support.
|
AsyncObserver(boolean withResources)
Constructs an AsyncObserver and allows specifying if it should support resources or not.
|
| 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.
|
boolean |
supportsResources()
Returns true if this AsyncObserver supports resources added via the add() method.
|
public AsyncObserver()
public AsyncObserver(boolean withResources)
withResources - true if resource support should be on.public final void add(Disposable resource)
Note that if the AsyncObserver doesn't manage resources, this method will
throw an IllegalStateException. Use supportsResources() to determine if
this AsyncObserver manages resources or not.
resource - the resource to addjava.lang.NullPointerException - if resource is nulljava.lang.IllegalStateException - if this AsyncObserver doesn't manage resourcessupportsResources()public final boolean supportsResources()
add(Disposable)public 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()
Disposabledispose in interface Disposablepublic final boolean isDisposed()