186 lines
5.6 KiB
Java
186 lines
5.6 KiB
Java
package j0.q;
|
|
|
|
import j0.g;
|
|
import j0.k.a;
|
|
import j0.l.a.e;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import rx.Observable;
|
|
import rx.Subscriber;
|
|
import rx.functions.Action1;
|
|
/* compiled from: SubjectSubscriptionManager */
|
|
public final class c<T> extends AtomicReference<a<T>> implements Observable.a<T> {
|
|
private static final long serialVersionUID = 6035251036011671568L;
|
|
public boolean active = true;
|
|
public volatile Object latest;
|
|
public Action1<b<T>> onAdded;
|
|
public Action1<b<T>> onStart;
|
|
public Action1<b<T>> onTerminated;
|
|
|
|
/* compiled from: SubjectSubscriptionManager */
|
|
public static final class a<T> {
|
|
public static final b[] a;
|
|
public static final a b;
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public static final a f2867c;
|
|
public final boolean d;
|
|
public final b[] e;
|
|
|
|
static {
|
|
b[] bVarArr = new b[0];
|
|
a = bVarArr;
|
|
b = new a(true, bVarArr);
|
|
f2867c = new a(false, bVarArr);
|
|
}
|
|
|
|
public a(boolean z2, b[] bVarArr) {
|
|
this.d = z2;
|
|
this.e = bVarArr;
|
|
}
|
|
}
|
|
|
|
/* compiled from: SubjectSubscriptionManager */
|
|
public static final class b<T> implements g<T> {
|
|
public final Subscriber<? super T> i;
|
|
public boolean j = true;
|
|
public boolean k;
|
|
public List<Object> l;
|
|
public boolean m;
|
|
|
|
public b(Subscriber<? super T> subscriber) {
|
|
this.i = subscriber;
|
|
}
|
|
|
|
public void a(Object obj) {
|
|
if (!this.m) {
|
|
synchronized (this) {
|
|
this.j = false;
|
|
if (this.k) {
|
|
if (this.l == null) {
|
|
this.l = new ArrayList();
|
|
}
|
|
this.l.add(obj);
|
|
return;
|
|
}
|
|
}
|
|
this.m = true;
|
|
}
|
|
e.a(this.i, obj);
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onCompleted() {
|
|
this.i.onCompleted();
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onError(Throwable th) {
|
|
this.i.onError(th);
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onNext(T t) {
|
|
this.i.onNext(t);
|
|
}
|
|
}
|
|
|
|
public c() {
|
|
super(a.f2867c);
|
|
a.C0319a aVar = j0.k.a.a;
|
|
this.onStart = aVar;
|
|
this.onAdded = aVar;
|
|
this.onTerminated = aVar;
|
|
}
|
|
|
|
public void a(b<T> bVar) {
|
|
a<T> aVar;
|
|
a<T> aVar2;
|
|
do {
|
|
aVar = get();
|
|
if (!aVar.d) {
|
|
b<T>[] bVarArr = aVar.e;
|
|
int length = bVarArr.length;
|
|
if (length == 1 && bVarArr[0] == bVar) {
|
|
aVar2 = a.f2867c;
|
|
} else {
|
|
if (length != 0) {
|
|
int i = length - 1;
|
|
b[] bVarArr2 = new b[i];
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
while (true) {
|
|
if (i2 < length) {
|
|
b<T> bVar2 = bVarArr[i2];
|
|
if (bVar2 != bVar) {
|
|
if (i3 == i) {
|
|
break;
|
|
}
|
|
bVarArr2[i3] = bVar2;
|
|
i3++;
|
|
}
|
|
i2++;
|
|
} else if (i3 == 0) {
|
|
aVar2 = a.f2867c;
|
|
} else {
|
|
if (i3 < i) {
|
|
b[] bVarArr3 = new b[i3];
|
|
System.arraycopy(bVarArr2, 0, bVarArr3, 0, i3);
|
|
bVarArr2 = bVarArr3;
|
|
}
|
|
aVar2 = new a<>(aVar.d, bVarArr2);
|
|
}
|
|
}
|
|
}
|
|
aVar2 = aVar;
|
|
}
|
|
if (aVar2 == aVar) {
|
|
return;
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
} while (!compareAndSet(aVar, aVar2));
|
|
}
|
|
|
|
public b<T>[] b(Object obj) {
|
|
this.latest = obj;
|
|
this.active = false;
|
|
return get().d ? a.a : getAndSet(a.b).e;
|
|
}
|
|
|
|
@Override // rx.functions.Action1
|
|
public void call(Object obj) {
|
|
boolean z2;
|
|
Subscriber subscriber = (Subscriber) obj;
|
|
b<T> bVar = new b<>(subscriber);
|
|
subscriber.add(new j0.r.a(new b(this, bVar)));
|
|
this.onStart.call(bVar);
|
|
if (!subscriber.isUnsubscribed()) {
|
|
while (true) {
|
|
a<T> aVar = get();
|
|
z2 = false;
|
|
if (!aVar.d) {
|
|
b[] bVarArr = aVar.e;
|
|
int length = bVarArr.length;
|
|
b[] bVarArr2 = new b[(length + 1)];
|
|
System.arraycopy(bVarArr, 0, bVarArr2, 0, length);
|
|
bVarArr2[length] = bVar;
|
|
if (compareAndSet(aVar, new a(aVar.d, bVarArr2))) {
|
|
this.onAdded.call(bVar);
|
|
z2 = true;
|
|
break;
|
|
}
|
|
} else {
|
|
this.onTerminated.call(bVar);
|
|
break;
|
|
}
|
|
}
|
|
if (z2 && subscriber.isUnsubscribed()) {
|
|
a(bVar);
|
|
}
|
|
}
|
|
}
|
|
}
|