31
31
* All methods of this class are thread-safe.
32
32
*/
33
33
public final class CompositeSubscription implements Subscription {
34
-
34
+
35
35
private Set <Subscription > subscriptions ;
36
36
private volatile boolean unsubscribed ;
37
-
37
+
38
38
public CompositeSubscription () {
39
39
}
40
-
40
+
41
41
public CompositeSubscription (final Subscription ... subscriptions ) {
42
42
this .subscriptions = new HashSet <Subscription >(Arrays .asList (subscriptions ));
43
43
}
44
-
44
+
45
45
@ Override
46
46
public boolean isUnsubscribed () {
47
47
return unsubscribed ;
48
48
}
49
-
49
+
50
50
/**
51
51
* Adds a new {@link Subscription} to this {@code CompositeSubscription} if the
52
52
* {@code CompositeSubscription} is not yet unsubscribed. If the {@code CompositeSubscription} <em>is</em>
@@ -74,7 +74,7 @@ public void add(final Subscription s) {
74
74
// call after leaving the synchronized block so we're not holding a lock while executing this
75
75
s .unsubscribe ();
76
76
}
77
-
77
+
78
78
/**
79
79
* Adds collection of {@link Subscription} to this {@code CompositeSubscription} if the
80
80
* {@code CompositeSubscription} is not yet unsubscribed. If the {@code CompositeSubscription} <em>is</em>
@@ -91,7 +91,7 @@ public void addAll(final Subscription... subscriptions) {
91
91
subscriptionList .add (s );
92
92
}
93
93
}
94
-
94
+
95
95
if (!unsubscribed ) {
96
96
synchronized (this ) {
97
97
if (!unsubscribed ) {
@@ -103,12 +103,12 @@ public void addAll(final Subscription... subscriptions) {
103
103
}
104
104
}
105
105
}
106
-
106
+
107
107
for (Subscription s : subscriptionList ) {
108
108
s .unsubscribe ();
109
109
}
110
110
}
111
-
111
+
112
112
/**
113
113
* Removes a {@link Subscription} from this {@code CompositeSubscription}, and unsubscribes the
114
114
* {@link Subscription}.
@@ -131,7 +131,7 @@ public void remove(final Subscription s) {
131
131
}
132
132
}
133
133
}
134
-
134
+
135
135
/**
136
136
* Unsubscribes any subscriptions that are currently part of this {@code CompositeSubscription} and remove
137
137
* them from the {@code CompositeSubscription} so that the {@code CompositeSubscription} is empty and
@@ -151,7 +151,7 @@ public void clear() {
151
151
unsubscribeFromAll (unsubscribe );
152
152
}
153
153
}
154
-
154
+
155
155
/**
156
156
* Unsubscribes itself and all inner subscriptions.
157
157
* <p>After call of this method, new {@code Subscription}s added to {@link CompositeSubscription}
@@ -173,7 +173,7 @@ public void unsubscribe() {
173
173
unsubscribeFromAll (unsubscribe );
174
174
}
175
175
}
176
-
176
+
177
177
private static void unsubscribeFromAll (Collection <Subscription > subscriptions ) {
178
178
if (subscriptions == null ) {
179
179
return ;
@@ -191,7 +191,7 @@ private static void unsubscribeFromAll(Collection<Subscription> subscriptions) {
191
191
}
192
192
Exceptions .throwIfAny (es );
193
193
}
194
-
194
+
195
195
/**
196
196
* Returns true if this composite is not unsubscribed and contains subscriptions.
197
197
*
0 commit comments