T - the value typepublic abstract class NbpAsyncObserver<T> extends java.lang.Object implements NbpObservable.NbpSubscriber<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 |
|---|
NbpAsyncObserver()
Constructs an AsyncObserver with resource support.
|
NbpAsyncObserver(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 main disposable (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(Disposable s) |
boolean |
supportsResources()
Returns true if this AsyncObserver supports resources added via the add() method.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonComplete, onError, onNextpublic NbpAsyncObserver()
public NbpAsyncObserver(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(Disposable s)
onSubscribe in interface NbpObservable.NbpSubscriber<T>protected void onStart()
You can perform initialization at this moment. The default implementation does nothing.
protected final void cancel()
This method can be called before the upstream calls onSubscribe at which case the main Disposable will be immediately disposed.
public final void dispose()
Disposabledispose in interface Disposablepublic final boolean isDisposed()