jimu-decompiled/sources/io/reactivex/internal/operators/observable/ObservableSwitchMap.java
2025-05-13 19:24:51 +02:00

229 lines
8.2 KiB
Java

package io.reactivex.internal.operators.observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.Function;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.internal.fuseable.QueueDisposable;
import io.reactivex.internal.fuseable.SimpleQueue;
import io.reactivex.internal.queue.SpscLinkedArrayQueue;
import io.reactivex.internal.util.AtomicThrowable;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
/* loaded from: classes2.dex */
public final class ObservableSwitchMap<T, R> extends AbstractObservableWithUpstream<T, R> {
final Function<? super T, ? extends ObservableSource<? extends R>> b;
final int c;
final boolean d;
static final class SwitchMapInnerObserver<T, R> extends AtomicReference<Disposable> implements Observer<R> {
final SwitchMapObserver<T, R> a;
final long b;
final int c;
volatile SimpleQueue<R> d;
volatile boolean e;
SwitchMapInnerObserver(SwitchMapObserver<T, R> switchMapObserver, long j, int i) {
this.a = switchMapObserver;
this.b = j;
this.c = i;
}
public void a() {
DisposableHelper.dispose(this);
}
@Override // io.reactivex.Observer
public void onComplete() {
if (this.b == this.a.j) {
this.e = true;
this.a.b();
}
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
this.a.a(this, th);
}
@Override // io.reactivex.Observer
public void onNext(R r) {
if (this.b == this.a.j) {
if (r != null) {
this.d.offer(r);
}
this.a.b();
}
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
if (DisposableHelper.setOnce(this, disposable)) {
if (disposable instanceof QueueDisposable) {
QueueDisposable queueDisposable = (QueueDisposable) disposable;
int requestFusion = queueDisposable.requestFusion(7);
if (requestFusion == 1) {
this.d = queueDisposable;
this.e = true;
this.a.b();
return;
} else if (requestFusion == 2) {
this.d = queueDisposable;
return;
}
}
this.d = new SpscLinkedArrayQueue(this.c);
}
}
}
public ObservableSwitchMap(ObservableSource<T> observableSource, Function<? super T, ? extends ObservableSource<? extends R>> function, int i, boolean z) {
super(observableSource);
this.b = function;
this.c = i;
this.d = z;
}
@Override // io.reactivex.Observable
public void subscribeActual(Observer<? super R> observer) {
if (ObservableScalarXMap.a(this.a, observer, this.b)) {
return;
}
this.a.subscribe(new SwitchMapObserver(observer, this.b, this.c, this.d));
}
static final class SwitchMapObserver<T, R> extends AtomicInteger implements Observer<T>, Disposable {
static final SwitchMapInnerObserver<Object, Object> k = new SwitchMapInnerObserver<>(null, -1, 1);
final Observer<? super R> a;
final Function<? super T, ? extends ObservableSource<? extends R>> b;
final int c;
final boolean d;
volatile boolean f;
volatile boolean g;
Disposable h;
volatile long j;
final AtomicReference<SwitchMapInnerObserver<T, R>> i = new AtomicReference<>();
final AtomicThrowable e = new AtomicThrowable();
static {
k.a();
}
SwitchMapObserver(Observer<? super R> observer, Function<? super T, ? extends ObservableSource<? extends R>> function, int i, boolean z) {
this.a = observer;
this.b = function;
this.c = i;
this.d = z;
}
void a() {
SwitchMapInnerObserver<Object, Object> switchMapInnerObserver;
SwitchMapInnerObserver<T, R> switchMapInnerObserver2 = this.i.get();
SwitchMapInnerObserver<Object, Object> switchMapInnerObserver3 = k;
if (switchMapInnerObserver2 == switchMapInnerObserver3 || (switchMapInnerObserver = (SwitchMapInnerObserver) this.i.getAndSet(switchMapInnerObserver3)) == k || switchMapInnerObserver == null) {
return;
}
switchMapInnerObserver.a();
}
/* JADX WARN: Removed duplicated region for block: B:71:0x00e9 A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:77:0x000f A[SYNTHETIC] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
void b() {
/*
Method dump skipped, instructions count: 241
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: io.reactivex.internal.operators.observable.ObservableSwitchMap.SwitchMapObserver.b():void");
}
@Override // io.reactivex.disposables.Disposable
public void dispose() {
if (this.g) {
return;
}
this.g = true;
this.h.dispose();
a();
}
@Override // io.reactivex.Observer
public void onComplete() {
if (this.f) {
return;
}
this.f = true;
b();
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
if (this.f || !this.e.addThrowable(th)) {
RxJavaPlugins.b(th);
return;
}
if (!this.d) {
a();
}
this.f = true;
b();
}
@Override // io.reactivex.Observer
public void onNext(T t) {
SwitchMapInnerObserver<T, R> switchMapInnerObserver;
long j = this.j + 1;
this.j = j;
SwitchMapInnerObserver<T, R> switchMapInnerObserver2 = this.i.get();
if (switchMapInnerObserver2 != null) {
switchMapInnerObserver2.a();
}
try {
ObservableSource<? extends R> apply = this.b.apply(t);
ObjectHelper.a(apply, "The ObservableSource returned is null");
ObservableSource<? extends R> observableSource = apply;
SwitchMapInnerObserver<T, R> switchMapInnerObserver3 = new SwitchMapInnerObserver<>(this, j, this.c);
do {
switchMapInnerObserver = this.i.get();
if (switchMapInnerObserver == k) {
return;
}
} while (!this.i.compareAndSet(switchMapInnerObserver, switchMapInnerObserver3));
observableSource.subscribe(switchMapInnerObserver3);
} catch (Throwable th) {
Exceptions.b(th);
this.h.dispose();
onError(th);
}
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
if (DisposableHelper.validate(this.h, disposable)) {
this.h = disposable;
this.a.onSubscribe(this);
}
}
void a(SwitchMapInnerObserver<T, R> switchMapInnerObserver, Throwable th) {
if (switchMapInnerObserver.b == this.j && this.e.addThrowable(th)) {
if (!this.d) {
this.h.dispose();
}
switchMapInnerObserver.e = true;
b();
return;
}
RxJavaPlugins.b(th);
}
}
}