public final class Observers
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Observer<T> |
newAsyncAwaiter(java.util.concurrent.CountDownLatch latch)
Creates an observer which counts down the latch by one
in case of an error() or finish() event.
|
static <T> Observer<T> |
newAsyncAwaiter(java.util.concurrent.locks.Lock lock,
java.util.concurrent.locks.Condition cond)
Creates an observer which signals the condition
in case of an error() or finish() event.
|
static <T> Observer<T> |
newAsyncAwaiter(java.lang.Object syncObject)
Creates an observer which calls notifyAll on the supplied synchronization object
in case of an error() or finish() event.
|
static <T> Observer<T> |
newAsyncAwaiter(java.lang.Runnable onDone)
Creates an observer which calls the supplied callback
in case of an error() or finish() event.
|
static <T> Observer<T> |
newAsyncAwaiter0(Action0 onDone)
Creates an observer which calls the supplied callback
in case of an error() or finish() event.
|
static <T> Observer<T> |
print()
Creates an observer with debugging purposes.
|
static <T> Observer<T> |
print(java.lang.String separator,
int maxLineLength)
Creates an observer with debugging purposes.
|
static <T> Observer<T> |
println()
Creates an observer with debugging purposes.
|
static <T> Observer<T> |
println(java.lang.String prefix)
Creates an observer with debugging purposes.
|
static <T> java.io.Closeable |
registerSafe(Observable<? extends T> source,
Observer<? super T> observer)
Registers the observer with the source in a way
that if the registration call throws an exception,
it is routed to the observer via the error() method.
|
static <T> java.io.Closeable |
registerWith(java.lang.Iterable<T> iterable,
Observer<? super T> observer)
"Registers" the observer with the iterable source
and iterates over the source iterable in the current
thread.
|
static <T> java.io.Closeable |
registerWith(java.lang.Iterable<T> iterable,
Observer<? super T> observer,
Scheduler scheduler)
"Registers" an observer with the given iterable
and iterates over it on the given scheduler.
|
static <T> java.io.Closeable |
registerWith(Observable<T> observable,
java.util.Observer javaObserver)
Convenience method to register a java-observable with a reactive-observable.
|
static java.io.Closeable |
registerWith(java.util.Observable javaObservable,
java.util.Observer javaObserver)
Convenience method to register a java-observer with a java-observable in the
same style as the reactive counterpart do.
|
static <T> java.io.Closeable |
registerWith(java.util.Observable javaObservable,
Observer<T> observer)
Convenience method to let a reactive-observer register with
a java-observable.
|
static <T,U> Observer<U> |
select(Observer<? super T> observer,
Func1<? super U,? extends T> selector)
Modifies the source observer to use the selector
to compute a new value from the received one.
|
static <T> java.util.Observer |
toJavaObserver(Observer<T> observer)
Wraps the reactive-observer into a java-observer.
|
static <T> Observer<T> |
toObserver(Action1<? super T> action)
Wraps the given action as an observable which reacts only to
next() events. |
static <T> Observer<T> |
toObserver(Action1<? super T> next,
Action1<? super java.lang.Throwable> error,
Action0 finish)
Creates an observer which calls the given functions on its similarly named methods.
|
static OriginalObserverWrapper |
toObserver(java.util.Observer javaObserver,
java.util.Observable javaObservable)
Converts the original Java Observer into a reactive-observer.
|
@Nonnull public static <T> Observer<T> toObserver(@Nonnull Action1<? super T> action)
next() events.T - the type of the valuesaction - the action to wrap@Nonnull public static <T> Observer<T> toObserver(@Nonnull Action1<? super T> next, @Nonnull Action1<? super java.lang.Throwable> error, @Nonnull Action0 finish)
T - the value type to receivenext - the action to invoke on next()error - the action to invoke on error()finish - the action to invoke on finish()@Nonnull public static <T> Observer<T> print()
T - the value type@Nonnull public static <T> Observer<T> print(java.lang.String separator, int maxLineLength)
T - the value typeseparator - the separator to use between subsequent valuesmaxLineLength - how many characters to print into each line@Nonnull public static <T> Observer<T> println()
T - the value type@Nonnull public static <T> Observer<T> println(java.lang.String prefix)
T - the value typeprefix - the prefix to use when printing@Nonnull public static <T> Observer<T> newAsyncAwaiter(@Nonnull java.lang.Runnable onDone)
T - the element typeonDone - the callback to invoke on completion@Nonnull public static <T> Observer<T> newAsyncAwaiter0(@Nonnull Action0 onDone)
T - the element typeonDone - the callback to invoke on completion@Nonnull public static <T> Observer<T> newAsyncAwaiter(@Nonnull java.util.concurrent.CountDownLatch latch)
T - the element typelatch - the latch to count down by one@Nonnull public static <T> Observer<T> newAsyncAwaiter(@Nonnull java.util.concurrent.locks.Lock lock, @Nonnull java.util.concurrent.locks.Condition cond)
T - the element typelock - the lock owning the conditioncond - the condition to signal@Nonnull public static <T> Observer<T> newAsyncAwaiter(@Nonnull java.lang.Object syncObject)
T - the element typesyncObject - the synchronization object@Nonnull public static <T,U> Observer<U> select(@Nonnull Observer<? super T> observer, @Nonnull Func1<? super U,? extends T> selector)
The error and finish events are forwarded without modification.
T - the source element typeU - the result element typeobserver - the observer to modify behavior onselector - the selector to change the observed value@Nonnull public static OriginalObserverWrapper toObserver(@Nonnull java.util.Observer javaObserver, @Nullable java.util.Observable javaObservable)
The observer deregisters from the sender observable in case of error or finish.
javaObserver - the java observerjavaObservable - the sender java observable@Nonnull public static <T> java.util.Observer toJavaObserver(Observer<T> observer)
Note that since java-observer is non generic, ClassCastException might occur on the chain of reactive-observers in case an inproper object is propagated.
T - the element typeobserver - the reactive-observer to wrap@Nonnull
public static <T> java.io.Closeable registerWith(@Nonnull
java.util.Observable javaObservable,
@Nonnull
Observer<T> observer)
The observer won't receive any error or finish events since java-observables don't have these concepts.
Note that java-observables are not generic, therefore ClassCastException might occur if inproper values are sent through the reactive-observable chain.
T - the element typejavaObservable - the observable used to register with.observer - the observer to use@Nonnull
public static java.io.Closeable registerWith(@Nonnull
java.util.Observable javaObservable,
@Nonnull
java.util.Observer javaObserver)
Note that java-observable prevents multiple registrations with the same java-observer instance, but there is no way to know if an observer is already registered. Therefore, in duplicate case the subsequent close handle will close the single registration.
javaObservable - the java-observable instancejavaObserver - the java-observer instance@Nonnull
public static <T> java.io.Closeable registerWith(@Nonnull
Observable<T> observable,
@Nonnull
java.util.Observer javaObserver)
T - the element type of the reactive-observableobservable - the reactive-observable to register withjavaObserver - the java-observer to register@Nonnull
public static <T> java.io.Closeable registerWith(@Nonnull
java.lang.Iterable<T> iterable,
@Nonnull
Observer<? super T> observer)
T - the element typeiterable - the iterable sequenceobserver - the observer@Nonnull
public static <T> java.io.Closeable registerWith(@Nonnull
java.lang.Iterable<T> iterable,
@Nonnull
Observer<? super T> observer,
@Nonnull
Scheduler scheduler)
T - the element typeiterable - the iterable sourceobserver - the observerscheduler - the scheduler@Nonnull
public static <T> java.io.Closeable registerSafe(@Nonnull
Observable<? extends T> source,
@Nonnull
Observer<? super T> observer)
T - the element typesource - the source observableobserver - the observer to register