Skip to content

Commit c99832e

Browse files
Update subscriber and transformer documentation.
1 parent 24a5e82 commit c99832e

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

objectbox-java/src/main/java/io/objectbox/reactive/DataTransformer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616

1717
package io.objectbox.reactive;
1818

19-
import javax.annotation.Nullable;
20-
2119
/**
2220
* Transforms or processes data before it is given to subscribed {@link DataObserver}s. A transformer is set via
2321
* {@link SubscriptionBuilder#transform(DataTransformer)}.
24-
*
22+
* <p>
2523
* Note that a transformer is not required to actually "transform" any data.
2624
* Technically, it's fine to return the same data it received and just do some processing with it.
27-
*
28-
* Threading notes: Note that the transformer is always executed asynchronously.
29-
* It is OK to perform long lasting operations.
25+
* <p>
26+
* Threading notes: transformations are executed sequentially on a background thread
27+
* owned by the subscription publisher. It is OK to perform long lasting operations,
28+
* however this will block notifications to all other observers until finished.
3029
*
3130
* @param <FROM> Data type this transformer receives
3231
* @param <TO> Type of transformed data

objectbox-java/src/main/java/io/objectbox/reactive/SubscriptionBuilder.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
import javax.annotation.Nullable;
2020

2121
import io.objectbox.annotation.apihint.Internal;
22+
import io.objectbox.query.Query;
2223

2324
/**
2425
* Builds a {@link DataSubscription} for a {@link DataObserver} passed via {@link #observer(DataObserver)}.
2526
* Note that the call to {@link #observer(DataObserver)} is mandatory to create the subscription -
2627
* if you forget it, nothing will happen.
2728
* <p>
28-
* When subscribing to a data source such as {@link io.objectbox.query.Query}, this builder allows to configure:
29+
* When subscribing to a data source such as {@link Query}, this builder allows to configure:
2930
* <ul>
3031
* <li>weakly referenced observer via {@link #weak()}</li>
3132
* <li>a data transform operation via {@link #transform(DataTransformer)}</li>
@@ -78,11 +79,21 @@ public SubscriptionBuilder<T> weak() {
7879
return this;
7980
}
8081

82+
/**
83+
* Only deliver the latest data once, do not subscribe for data changes.
84+
*
85+
* @see #onlyChanges()
86+
*/
8187
public SubscriptionBuilder<T> single() {
8288
single = true;
8389
return this;
8490
}
8591

92+
/**
93+
* Upon subscribing do not deliver the latest data, only once there are changes.
94+
*
95+
* @see #single()
96+
*/
8697
public SubscriptionBuilder<T> onlyChanges() {
8798
onlyChanges = true;
8899
return this;
@@ -94,14 +105,12 @@ public SubscriptionBuilder<T> onlyChanges() {
94105
// }
95106

96107
/**
97-
* Transforms the original data from the publisher to something that is more helpful to your application.
98-
* The transformation is done in an asynchronous thread.
99-
* The observer will be called in the same asynchronous thread unless a Scheduler is defined using
100-
* {@link #on(Scheduler)}.
108+
* Transforms the original data from the publisher to some other type.
109+
* All transformations run sequentially in an asynchronous thread owned by the publisher.
101110
* <p>
102-
* This is roughly equivalent to the map operator as known in Rx and Kotlin.
111+
* This is similar to the map operator of Rx and Kotlin.
103112
*
104-
* @param <TO> The class the data is transformed to
113+
* @param <TO> The type data is transformed to.
105114
*/
106115
public <TO> SubscriptionBuilder<TO> transform(final DataTransformer<T, TO> transformer) {
107116
if (this.transformer != null) {
@@ -139,11 +148,16 @@ public SubscriptionBuilder<T> on(Scheduler scheduler) {
139148
}
140149

141150
/**
142-
* The given observer is subscribed to the publisher. This method MUST be called to complete a subscription.
151+
* Sets the observer for this subscription and requests the latest data to be delivered immediately
152+
* and subscribes to the publisher for data updates, unless configured differently
153+
* using {@link #single()} or {@link #onlyChanges()}.
154+
* <p>
155+
* Results are delivered on a background thread owned by the publisher,
156+
* unless a scheduler was set using {@link #on(Scheduler)}.
143157
* <p>
144-
* Note: you must keep the returned {@link DataSubscription} to cancel it.
158+
* The returned {@link DataSubscription} must be canceled once the observer should no longer receive notifications.
145159
*
146-
* @return an subscription object used for canceling further notifications to the observer
160+
* @return A {@link DataSubscription} to cancel further notifications to the observer.
147161
*/
148162
public DataSubscription observer(DataObserver<T> observer) {
149163
WeakDataObserver<T> weakObserver = null;

0 commit comments

Comments
 (0)