Skip to content

Commit 5e94f17

Browse files
committed
DataSubscriptionList: add clears canceled state, java docs
1 parent 31ed540 commit 5e94f17

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
package io.objectbox.reactive;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

6+
/**
7+
* Tracks any number of {@link DataSubscription} objects, which can be canceled with a single {@link #cancel()} call.
8+
* This is typically used in live cycle components like Android's Activity:
9+
* <ul>
10+
* <li>Make DataSubscriptionList a field</li>
11+
* <li>Call {@link #add(DataSubscription)} during onStart/onResume for each subscription</li>
12+
* <li>Call {@link #cancel()} during onStop/onPause</li>
13+
* </ul>
14+
*/
515
public class DataSubscriptionList implements DataSubscription {
16+
private final List<DataSubscription> subscriptions = new ArrayList<>();
617
private boolean canceled;
7-
List<DataSubscription> subscriptions;
818

19+
/** Add the given subscription to the list of tracked subscriptions. Clears any previous "canceled" state. */
920
public synchronized void add(DataSubscription subscription) {
1021
subscriptions.add(subscription);
22+
canceled = false;
1123
}
1224

25+
/** Cancels all tracked subscriptions and removes all references to them. */
1326
@Override
1427
public synchronized void cancel() {
1528
canceled = true;
@@ -19,11 +32,13 @@ public synchronized void cancel() {
1932
subscriptions.clear();
2033
}
2134

35+
/** Returns true if {@link #cancel()} was called without any subsequent calls to {@link #add(DataSubscription)}. */
2236
@Override
2337
public synchronized boolean isCanceled() {
2438
return canceled;
2539
}
2640

41+
/** Returns number of active (added) subscriptions (resets to 0 after {@link #cancel()}). */
2742
public synchronized int getActiveSubscriptionCount() {
2843
return subscriptions.size();
2944
}

0 commit comments

Comments
 (0)