98 lines
2.6 KiB
Java
98 lines
2.6 KiB
Java
|
package rx.subscriptions;
|
||
|
|
||
|
import c.q.a.k.a;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Collection;
|
||
|
import java.util.HashSet;
|
||
|
import java.util.Set;
|
||
|
import rx.Subscription;
|
||
|
public final class CompositeSubscription implements Subscription {
|
||
|
public Set<Subscription> i;
|
||
|
public volatile boolean j;
|
||
|
|
||
|
public static void d(Collection<Subscription> collection) {
|
||
|
if (collection != null) {
|
||
|
ArrayList arrayList = null;
|
||
|
for (Subscription subscription : collection) {
|
||
|
try {
|
||
|
subscription.unsubscribe();
|
||
|
} catch (Throwable th) {
|
||
|
if (arrayList == null) {
|
||
|
arrayList = new ArrayList();
|
||
|
}
|
||
|
arrayList.add(th);
|
||
|
}
|
||
|
}
|
||
|
a.Z(arrayList);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void a(Subscription subscription) {
|
||
|
if (!subscription.isUnsubscribed()) {
|
||
|
if (!this.j) {
|
||
|
synchronized (this) {
|
||
|
if (!this.j) {
|
||
|
if (this.i == null) {
|
||
|
this.i = new HashSet(4);
|
||
|
}
|
||
|
this.i.add(subscription);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
subscription.unsubscribe();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void b() {
|
||
|
if (!this.j) {
|
||
|
synchronized (this) {
|
||
|
if (!this.j) {
|
||
|
Set<Subscription> set = this.i;
|
||
|
if (set != null) {
|
||
|
this.i = null;
|
||
|
d(set);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void c(Subscription subscription) {
|
||
|
boolean remove;
|
||
|
if (!this.j) {
|
||
|
synchronized (this) {
|
||
|
if (!this.j) {
|
||
|
Set<Subscription> set = this.i;
|
||
|
if (set != null) {
|
||
|
remove = set.remove(subscription);
|
||
|
}
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
if (remove) {
|
||
|
subscription.unsubscribe();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // rx.Subscription
|
||
|
public boolean isUnsubscribed() {
|
||
|
return this.j;
|
||
|
}
|
||
|
|
||
|
@Override // rx.Subscription
|
||
|
public void unsubscribe() {
|
||
|
if (!this.j) {
|
||
|
synchronized (this) {
|
||
|
if (!this.j) {
|
||
|
this.j = true;
|
||
|
Set<Subscription> set = this.i;
|
||
|
this.i = null;
|
||
|
d(set);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|