File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
objectbox-java/src/main/java/io/objectbox/reactive Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11package io .objectbox .reactive ;
22
3+ import java .util .ArrayList ;
34import 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+ */
515public 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 }
You can’t perform that action at this time.
0 commit comments