T - The data type the DataObserver subscribes to.public class SubscriptionBuilder<T>
extends java.lang.Object
DataSubscription for a DataObserver passed via observer(DataObserver).
Note that the call to observer(DataObserver) is mandatory to create the subscription -
if you forget it, nothing will happen.
When subscribing to a data source such as Query, this builder allows to configure:
weak()transform(DataTransformer)onError(ErrorObserver)Scheduler (e.g. Android main thread) via on(Scheduler)Note: the order of methods called in this do not matter. Unlike Rx's Observeable, this builder just collects all info. For example, on(scheduler).transform(transformer) is the same as transform(transformer).on(scheduler).
| Constructor and Description |
|---|
SubscriptionBuilder(DataPublisher<T> publisher,
java.lang.Object param,
java.util.concurrent.ExecutorService threadPool) |
| Modifier and Type | Method and Description |
|---|---|
SubscriptionBuilder<T> |
dataSubscriptionList(DataSubscriptionList dataSubscriptionList) |
DataSubscription |
observer(DataObserver<T> observer)
The given observer is subscribed to the publisher.
|
SubscriptionBuilder<T> |
on(Scheduler scheduler)
Changes the thread in which the
DataObserver (and potentially @ErrorObserver) is called. |
SubscriptionBuilder<T> |
onError(ErrorObserver errorObserver)
The given
ErrorObserver is notified when the DataTransformer
(transform(DataTransformer)) or DataObserver (observer(DataObserver))
threw an exception. |
SubscriptionBuilder<T> |
onlyChanges() |
SubscriptionBuilder<T> |
single() |
<TO> SubscriptionBuilder<TO> |
transform(DataTransformer<T,TO> transformer)
Transforms the original data from the publisher to something that is more helpful to your application.
|
SubscriptionBuilder<T> |
weak()
Uses a weak reference for the observer.
|
@Internal public SubscriptionBuilder(DataPublisher<T> publisher, @Nullable java.lang.Object param, java.util.concurrent.ExecutorService threadPool)
public SubscriptionBuilder<T> weak()
public SubscriptionBuilder<T> single()
public SubscriptionBuilder<T> onlyChanges()
public <TO> SubscriptionBuilder<TO> transform(DataTransformer<T,TO> transformer)
on(Scheduler).
This is roughly equivalent to the map operator as known in Rx and Kotlin.
TO - The class the data is transformed topublic SubscriptionBuilder<T> onError(ErrorObserver errorObserver)
ErrorObserver is notified when the DataTransformer
(transform(DataTransformer)) or DataObserver (observer(DataObserver))
threw an exception.public SubscriptionBuilder<T> on(Scheduler scheduler)
DataObserver (and potentially @ErrorObserver) is called.
In the Android package, there is a class AndroidScheduler with a MAIN_THREAD Scheduler implementation. Using MAIN_THREAD, observers will be called in Android's main thread, which is required for UI updates.
public DataSubscription observer(DataObserver<T> observer)
Note: you must keep the returned DataSubscription to cancel it.
public SubscriptionBuilder<T> dataSubscriptionList(DataSubscriptionList dataSubscriptionList)