T - the element typepublic abstract class DefaultObserverEx<T> extends DefaultObserver<T>
Note when overriding onClose, you should always call super.onClose()
to close any remaining subObservers.
| Modifier and Type | Field and Description |
|---|---|
protected TaggedCompositeCloseable |
subObservers
The container for the tagged observers.
|
closeOnTermination, completed, lock| Constructor and Description |
|---|
DefaultObserverEx()
Constructor.
|
DefaultObserverEx(boolean complete)
Constructor.
|
DefaultObserverEx(java.util.concurrent.locks.Lock lock,
boolean complete)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.Object token,
java.io.Closeable handler)
Adds or replaces a new closeable with a token to the sub-observer list.
|
protected void |
init()
Implementations might override this method to initialize some other
resources outside the onRegister's lock, before onRegister.
|
protected void |
onClose()
Called by close to close down any associated resources with this instance.
|
protected void |
onRegister()
Called internally with the global lock held to ensure any dependent registrations succeed to
store the closeable reference before returning.
|
java.io.Closeable |
registerWith(Observable<? extends T> source)
While holding the global lock, executes the onRegister method then
registers this instance with the supplied source observable with the
this token. |
void |
remove(java.lang.Object token)
Removes and closes the close handler associated with the token.
|
static <T> DefaultObserverEx<T> |
wrap(Observer<? super T> observer)
Wraps the supplied observer into a DefaultObservableEx and
simply forwards onNext, onError, onFinish events to the raw
next, error and finish methods.
|
close, error, finish, getLock, isCompleted, next, onError, onFinish, onNext@Nonnull protected final TaggedCompositeCloseable subObservers
public DefaultObserverEx()
public DefaultObserverEx(boolean complete)
complete - should the observer close its sub-resources automatically on error/finish?public DefaultObserverEx(@Nonnull
java.util.concurrent.locks.Lock lock,
boolean complete)
lock - the external lock to use when synchronizing the message methodscomplete - should the observer close its sub-resources automatically on error/finish?public void add(java.lang.Object token,
java.io.Closeable handler)
token - the reference tokenhandler - the closeable handlerprotected void onRegister()
@Nonnull
public java.io.Closeable registerWith(@Nonnull
Observable<? extends T> source)
this token.
If the this token is already registered, the previous handle is closed.source - the source observablepublic void remove(@Nonnull
java.lang.Object token)
token - the token to the closeable handlerprotected void onClose()
DefaultObserverThe close() method ensures that the lock is held this code executes.
onClose in class DefaultObserver<T>public static <T> DefaultObserverEx<T> wrap(@Nonnull Observer<? super T> observer)
T - the observed element typeobserver - the observer to wrapprotected void init()