Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.Flowable;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.internal.fuseable.HasUpstreamPublisher;
/* loaded from: classes2.dex */
abstract class AbstractFlowableWithUpstream<T, R> extends Flowable<R> implements HasUpstreamPublisher<T> {
protected final Flowable<T> b;
AbstractFlowableWithUpstream(Flowable<T> flowable) {
ObjectHelper.a(flowable, "source is null");
this.b = flowable;
}
}

View File

@@ -0,0 +1,61 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
/* loaded from: classes2.dex */
public final class FlowableFromObservable<T> extends Flowable<T> {
private final Observable<T> b;
static final class SubscriberObserver<T> implements Observer<T>, Subscription {
final Subscriber<? super T> a;
Disposable b;
SubscriberObserver(Subscriber<? super T> subscriber) {
this.a = subscriber;
}
@Override // org.reactivestreams.Subscription
public void cancel() {
this.b.dispose();
}
@Override // io.reactivex.Observer
public void onComplete() {
this.a.onComplete();
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
this.a.onError(th);
}
@Override // io.reactivex.Observer
public void onNext(T t) {
this.a.onNext(t);
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
this.b = disposable;
this.a.onSubscribe(this);
}
@Override // org.reactivestreams.Subscription
public void request(long j) {
}
}
public FlowableFromObservable(Observable<T> observable) {
this.b = observable;
}
@Override // io.reactivex.Flowable
protected void b(Subscriber<? super T> subscriber) {
this.b.subscribe(new SubscriberObserver(subscriber));
}
}

View File

@@ -0,0 +1,323 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.flowables.GroupedFlowable;
import io.reactivex.functions.Function;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.internal.queue.SpscLinkedArrayQueue;
import io.reactivex.internal.subscriptions.BasicIntQueueSubscription;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import io.reactivex.internal.util.BackpressureHelper;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.Iterator;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
/* loaded from: classes2.dex */
public final class FlowableGroupBy$GroupBySubscriber<T, K, V> extends BasicIntQueueSubscription<GroupedFlowable<K, V>> implements FlowableSubscriber<T> {
static final Object NULL_KEY = new Object();
private static final long serialVersionUID = -3688291656102519502L;
final int bufferSize;
final boolean delayError;
boolean done;
final Subscriber<? super GroupedFlowable<K, V>> downstream;
Throwable error;
final Queue<FlowableGroupBy$GroupedUnicast<K, V>> evictedGroups;
volatile boolean finished;
final Map<Object, FlowableGroupBy$GroupedUnicast<K, V>> groups;
final Function<? super T, ? extends K> keySelector;
boolean outputFused;
final SpscLinkedArrayQueue<GroupedFlowable<K, V>> queue;
Subscription upstream;
final Function<? super T, ? extends V> valueSelector;
final AtomicBoolean cancelled = new AtomicBoolean();
final AtomicLong requested = new AtomicLong();
final AtomicInteger groupCount = new AtomicInteger(1);
public FlowableGroupBy$GroupBySubscriber(Subscriber<? super GroupedFlowable<K, V>> subscriber, Function<? super T, ? extends K> function, Function<? super T, ? extends V> function2, int i, boolean z, Map<Object, FlowableGroupBy$GroupedUnicast<K, V>> map, Queue<FlowableGroupBy$GroupedUnicast<K, V>> queue) {
this.downstream = subscriber;
this.keySelector = function;
this.valueSelector = function2;
this.bufferSize = i;
this.delayError = z;
this.groups = map;
this.evictedGroups = queue;
this.queue = new SpscLinkedArrayQueue<>(i);
}
private void completeEvictions() {
if (this.evictedGroups != null) {
int i = 0;
while (true) {
FlowableGroupBy$GroupedUnicast<K, V> poll = this.evictedGroups.poll();
if (poll == null) {
break;
}
poll.e();
i++;
}
if (i != 0) {
this.groupCount.addAndGet(-i);
}
}
}
@Override // org.reactivestreams.Subscription
public void cancel() {
if (this.cancelled.compareAndSet(false, true)) {
completeEvictions();
if (this.groupCount.decrementAndGet() == 0) {
this.upstream.cancel();
}
}
}
boolean checkTerminated(boolean z, boolean z2, Subscriber<?> subscriber, SpscLinkedArrayQueue<?> spscLinkedArrayQueue) {
if (this.cancelled.get()) {
spscLinkedArrayQueue.clear();
return true;
}
if (this.delayError) {
if (!z || !z2) {
return false;
}
Throwable th = this.error;
if (th != null) {
subscriber.onError(th);
} else {
subscriber.onComplete();
}
return true;
}
if (!z) {
return false;
}
Throwable th2 = this.error;
if (th2 != null) {
spscLinkedArrayQueue.clear();
subscriber.onError(th2);
return true;
}
if (!z2) {
return false;
}
subscriber.onComplete();
return true;
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public void clear() {
this.queue.clear();
}
void drain() {
if (getAndIncrement() != 0) {
return;
}
if (this.outputFused) {
drainFused();
} else {
drainNormal();
}
}
void drainFused() {
Throwable th;
SpscLinkedArrayQueue<GroupedFlowable<K, V>> spscLinkedArrayQueue = this.queue;
Subscriber<? super GroupedFlowable<K, V>> subscriber = this.downstream;
int i = 1;
while (!this.cancelled.get()) {
boolean z = this.finished;
if (z && !this.delayError && (th = this.error) != null) {
spscLinkedArrayQueue.clear();
subscriber.onError(th);
return;
}
subscriber.onNext(null);
if (z) {
Throwable th2 = this.error;
if (th2 != null) {
subscriber.onError(th2);
return;
} else {
subscriber.onComplete();
return;
}
}
i = addAndGet(-i);
if (i == 0) {
return;
}
}
spscLinkedArrayQueue.clear();
}
void drainNormal() {
SpscLinkedArrayQueue<GroupedFlowable<K, V>> spscLinkedArrayQueue = this.queue;
Subscriber<? super GroupedFlowable<K, V>> subscriber = this.downstream;
int i = 1;
do {
long j = this.requested.get();
long j2 = 0;
while (j2 != j) {
boolean z = this.finished;
GroupedFlowable<K, V> poll = spscLinkedArrayQueue.poll();
boolean z2 = poll == null;
if (checkTerminated(z, z2, subscriber, spscLinkedArrayQueue)) {
return;
}
if (z2) {
break;
}
subscriber.onNext(poll);
j2++;
}
if (j2 == j && checkTerminated(this.finished, spscLinkedArrayQueue.isEmpty(), subscriber, spscLinkedArrayQueue)) {
return;
}
if (j2 != 0) {
if (j != Long.MAX_VALUE) {
this.requested.addAndGet(-j2);
}
this.upstream.request(j2);
}
i = addAndGet(-i);
} while (i != 0);
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean isEmpty() {
return this.queue.isEmpty();
}
@Override // org.reactivestreams.Subscriber
public void onComplete() {
if (this.done) {
return;
}
Iterator<FlowableGroupBy$GroupedUnicast<K, V>> it = this.groups.values().iterator();
while (it.hasNext()) {
it.next().e();
}
this.groups.clear();
Queue<FlowableGroupBy$GroupedUnicast<K, V>> queue = this.evictedGroups;
if (queue != null) {
queue.clear();
}
this.done = true;
this.finished = true;
drain();
}
@Override // org.reactivestreams.Subscriber
public void onError(Throwable th) {
if (this.done) {
RxJavaPlugins.b(th);
return;
}
this.done = true;
Iterator<FlowableGroupBy$GroupedUnicast<K, V>> it = this.groups.values().iterator();
while (it.hasNext()) {
it.next().a(th);
}
this.groups.clear();
Queue<FlowableGroupBy$GroupedUnicast<K, V>> queue = this.evictedGroups;
if (queue != null) {
queue.clear();
}
this.error = th;
this.finished = true;
drain();
}
@Override // org.reactivestreams.Subscriber
public void onNext(T t) {
if (this.done) {
return;
}
SpscLinkedArrayQueue<GroupedFlowable<K, V>> spscLinkedArrayQueue = this.queue;
try {
K apply = this.keySelector.apply(t);
boolean z = false;
Object obj = apply != null ? apply : NULL_KEY;
FlowableGroupBy$GroupedUnicast<K, V> flowableGroupBy$GroupedUnicast = this.groups.get(obj);
if (flowableGroupBy$GroupedUnicast == null) {
if (this.cancelled.get()) {
return;
}
flowableGroupBy$GroupedUnicast = FlowableGroupBy$GroupedUnicast.a(apply, this.bufferSize, this, this.delayError);
this.groups.put(obj, flowableGroupBy$GroupedUnicast);
this.groupCount.getAndIncrement();
z = true;
}
try {
V apply2 = this.valueSelector.apply(t);
ObjectHelper.a(apply2, "The valueSelector returned null");
flowableGroupBy$GroupedUnicast.a((FlowableGroupBy$GroupedUnicast<K, V>) apply2);
completeEvictions();
if (z) {
spscLinkedArrayQueue.offer(flowableGroupBy$GroupedUnicast);
drain();
}
} catch (Throwable th) {
Exceptions.b(th);
this.upstream.cancel();
onError(th);
}
} catch (Throwable th2) {
Exceptions.b(th2);
this.upstream.cancel();
onError(th2);
}
}
@Override // org.reactivestreams.Subscriber
public void onSubscribe(Subscription subscription) {
if (SubscriptionHelper.validate(this.upstream, subscription)) {
this.upstream = subscription;
this.downstream.onSubscribe(this);
subscription.request(this.bufferSize);
}
}
@Override // org.reactivestreams.Subscription
public void request(long j) {
if (SubscriptionHelper.validate(j)) {
BackpressureHelper.a(this.requested, j);
drain();
}
}
@Override // io.reactivex.internal.fuseable.QueueFuseable
public int requestFusion(int i) {
if ((i & 2) == 0) {
return 0;
}
this.outputFused = true;
return 2;
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public GroupedFlowable<K, V> poll() {
return this.queue.poll();
}
public void cancel(K k) {
if (k == null) {
k = (K) NULL_KEY;
}
this.groups.remove(k);
if (this.groupCount.decrementAndGet() == 0) {
this.upstream.cancel();
if (getAndIncrement() == 0) {
this.queue.clear();
}
}
}
}

View File

@@ -0,0 +1,35 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.flowables.GroupedFlowable;
import org.reactivestreams.Subscriber;
/* loaded from: classes2.dex */
final class FlowableGroupBy$GroupedUnicast<K, T> extends GroupedFlowable<K, T> {
final FlowableGroupBy$State<T, K> b;
protected FlowableGroupBy$GroupedUnicast(K k, FlowableGroupBy$State<T, K> flowableGroupBy$State) {
super(k);
this.b = flowableGroupBy$State;
}
public static <T, K> FlowableGroupBy$GroupedUnicast<K, T> a(K k, int i, FlowableGroupBy$GroupBySubscriber<?, K, T> flowableGroupBy$GroupBySubscriber, boolean z) {
return new FlowableGroupBy$GroupedUnicast<>(k, new FlowableGroupBy$State(i, flowableGroupBy$GroupBySubscriber, k, z));
}
@Override // io.reactivex.Flowable
protected void b(Subscriber<? super T> subscriber) {
this.b.a(subscriber);
}
public void e() {
this.b.onComplete();
}
public void a(T t) {
this.b.onNext(t);
}
public void a(Throwable th) {
this.b.onError(th);
}
}

View File

@@ -0,0 +1,237 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.internal.queue.SpscLinkedArrayQueue;
import io.reactivex.internal.subscriptions.BasicIntQueueSubscription;
import io.reactivex.internal.subscriptions.EmptySubscription;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import io.reactivex.internal.util.BackpressureHelper;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
/* loaded from: classes2.dex */
final class FlowableGroupBy$State<T, K> extends BasicIntQueueSubscription<T> implements Publisher<T> {
final K a;
final SpscLinkedArrayQueue<T> b;
final FlowableGroupBy$GroupBySubscriber<?, K, T> c;
final boolean d;
volatile boolean f;
Throwable g;
boolean k;
int l;
final AtomicLong e = new AtomicLong();
final AtomicBoolean h = new AtomicBoolean();
final AtomicReference<Subscriber<? super T>> i = new AtomicReference<>();
final AtomicBoolean j = new AtomicBoolean();
FlowableGroupBy$State(int i, FlowableGroupBy$GroupBySubscriber<?, K, T> flowableGroupBy$GroupBySubscriber, K k, boolean z) {
this.b = new SpscLinkedArrayQueue<>(i);
this.c = flowableGroupBy$GroupBySubscriber;
this.a = k;
this.d = z;
}
@Override // org.reactivestreams.Publisher
public void a(Subscriber<? super T> subscriber) {
if (!this.j.compareAndSet(false, true)) {
EmptySubscription.error(new IllegalStateException("Only one Subscriber allowed!"), subscriber);
return;
}
subscriber.onSubscribe(this);
this.i.lazySet(subscriber);
drain();
}
@Override // org.reactivestreams.Subscription
public void cancel() {
if (this.h.compareAndSet(false, true)) {
this.c.cancel(this.a);
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public void clear() {
this.b.clear();
}
void drain() {
if (getAndIncrement() != 0) {
return;
}
if (this.k) {
drainFused();
} else {
drainNormal();
}
}
void drainFused() {
Throwable th;
SpscLinkedArrayQueue<T> spscLinkedArrayQueue = this.b;
Subscriber<? super T> subscriber = this.i.get();
int i = 1;
while (true) {
if (subscriber != null) {
if (this.h.get()) {
spscLinkedArrayQueue.clear();
return;
}
boolean z = this.f;
if (z && !this.d && (th = this.g) != null) {
spscLinkedArrayQueue.clear();
subscriber.onError(th);
return;
}
subscriber.onNext(null);
if (z) {
Throwable th2 = this.g;
if (th2 != null) {
subscriber.onError(th2);
return;
} else {
subscriber.onComplete();
return;
}
}
}
i = addAndGet(-i);
if (i == 0) {
return;
}
if (subscriber == null) {
subscriber = this.i.get();
}
}
}
void drainNormal() {
SpscLinkedArrayQueue<T> spscLinkedArrayQueue = this.b;
boolean z = this.d;
Subscriber<? super T> subscriber = this.i.get();
int i = 1;
while (true) {
if (subscriber != null) {
long j = this.e.get();
long j2 = 0;
while (j2 != j) {
boolean z2 = this.f;
T poll = spscLinkedArrayQueue.poll();
boolean z3 = poll == null;
if (a(z2, z3, subscriber, z)) {
return;
}
if (z3) {
break;
}
subscriber.onNext(poll);
j2++;
}
if (j2 == j && a(this.f, spscLinkedArrayQueue.isEmpty(), subscriber, z)) {
return;
}
if (j2 != 0) {
if (j != Long.MAX_VALUE) {
this.e.addAndGet(-j2);
}
this.c.upstream.request(j2);
}
}
i = addAndGet(-i);
if (i == 0) {
return;
}
if (subscriber == null) {
subscriber = this.i.get();
}
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean isEmpty() {
return this.b.isEmpty();
}
public void onComplete() {
this.f = true;
drain();
}
public void onError(Throwable th) {
this.g = th;
this.f = true;
drain();
}
public void onNext(T t) {
this.b.offer(t);
drain();
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public T poll() {
T poll = this.b.poll();
if (poll != null) {
this.l++;
return poll;
}
int i = this.l;
if (i == 0) {
return null;
}
this.l = 0;
this.c.upstream.request(i);
return null;
}
@Override // org.reactivestreams.Subscription
public void request(long j) {
if (SubscriptionHelper.validate(j)) {
BackpressureHelper.a(this.e, j);
drain();
}
}
@Override // io.reactivex.internal.fuseable.QueueFuseable
public int requestFusion(int i) {
if ((i & 2) == 0) {
return 0;
}
this.k = true;
return 2;
}
boolean a(boolean z, boolean z2, Subscriber<? super T> subscriber, boolean z3) {
if (this.h.get()) {
this.b.clear();
return true;
}
if (!z) {
return false;
}
if (z3) {
if (!z2) {
return false;
}
Throwable th = this.g;
if (th != null) {
subscriber.onError(th);
} else {
subscriber.onComplete();
}
return true;
}
Throwable th2 = this.g;
if (th2 != null) {
this.b.clear();
subscriber.onError(th2);
return true;
}
if (!z2) {
return false;
}
subscriber.onComplete();
return true;
}
}

View File

@@ -0,0 +1,14 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.functions.Consumer;
import org.reactivestreams.Subscription;
/* loaded from: classes2.dex */
public enum FlowableInternalHelper$RequestMax implements Consumer<Subscription> {
INSTANCE;
@Override // io.reactivex.functions.Consumer
public void accept(Subscription subscription) throws Exception {
subscription.request(Long.MAX_VALUE);
}
}

View File

@@ -0,0 +1,222 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.exceptions.MissingBackpressureException;
import io.reactivex.functions.Action;
import io.reactivex.internal.fuseable.SimplePlainQueue;
import io.reactivex.internal.queue.SpscArrayQueue;
import io.reactivex.internal.queue.SpscLinkedArrayQueue;
import io.reactivex.internal.subscriptions.BasicIntQueueSubscription;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import io.reactivex.internal.util.BackpressureHelper;
import java.util.concurrent.atomic.AtomicLong;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
/* loaded from: classes2.dex */
public final class FlowableOnBackpressureBuffer<T> extends AbstractFlowableWithUpstream<T, T> {
final int c;
final boolean d;
final boolean e;
final Action f;
static final class BackpressureBufferSubscriber<T> extends BasicIntQueueSubscription<T> implements FlowableSubscriber<T> {
final Subscriber<? super T> a;
final SimplePlainQueue<T> b;
final boolean c;
final Action d;
Subscription e;
volatile boolean f;
volatile boolean g;
Throwable h;
final AtomicLong i = new AtomicLong();
boolean j;
BackpressureBufferSubscriber(Subscriber<? super T> subscriber, int i, boolean z, boolean z2, Action action) {
this.a = subscriber;
this.d = action;
this.c = z2;
this.b = z ? new SpscLinkedArrayQueue<>(i) : new SpscArrayQueue<>(i);
}
boolean a(boolean z, boolean z2, Subscriber<? super T> subscriber) {
if (this.f) {
this.b.clear();
return true;
}
if (!z) {
return false;
}
if (this.c) {
if (!z2) {
return false;
}
Throwable th = this.h;
if (th != null) {
subscriber.onError(th);
} else {
subscriber.onComplete();
}
return true;
}
Throwable th2 = this.h;
if (th2 != null) {
this.b.clear();
subscriber.onError(th2);
return true;
}
if (!z2) {
return false;
}
subscriber.onComplete();
return true;
}
@Override // org.reactivestreams.Subscription
public void cancel() {
if (this.f) {
return;
}
this.f = true;
this.e.cancel();
if (getAndIncrement() == 0) {
this.b.clear();
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public void clear() {
this.b.clear();
}
void drain() {
if (getAndIncrement() == 0) {
SimplePlainQueue<T> simplePlainQueue = this.b;
Subscriber<? super T> subscriber = this.a;
int i = 1;
while (!a(this.g, simplePlainQueue.isEmpty(), subscriber)) {
long j = this.i.get();
long j2 = 0;
while (j2 != j) {
boolean z = this.g;
T poll = simplePlainQueue.poll();
boolean z2 = poll == null;
if (a(z, z2, subscriber)) {
return;
}
if (z2) {
break;
}
subscriber.onNext(poll);
j2++;
}
if (j2 == j && a(this.g, simplePlainQueue.isEmpty(), subscriber)) {
return;
}
if (j2 != 0 && j != Long.MAX_VALUE) {
this.i.addAndGet(-j2);
}
i = addAndGet(-i);
if (i == 0) {
return;
}
}
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean isEmpty() {
return this.b.isEmpty();
}
@Override // org.reactivestreams.Subscriber
public void onComplete() {
this.g = true;
if (this.j) {
this.a.onComplete();
} else {
drain();
}
}
@Override // org.reactivestreams.Subscriber
public void onError(Throwable th) {
this.h = th;
this.g = true;
if (this.j) {
this.a.onError(th);
} else {
drain();
}
}
@Override // org.reactivestreams.Subscriber
public void onNext(T t) {
if (this.b.offer(t)) {
if (this.j) {
this.a.onNext(null);
return;
} else {
drain();
return;
}
}
this.e.cancel();
MissingBackpressureException missingBackpressureException = new MissingBackpressureException("Buffer is full");
try {
this.d.run();
} catch (Throwable th) {
Exceptions.b(th);
missingBackpressureException.initCause(th);
}
onError(missingBackpressureException);
}
@Override // org.reactivestreams.Subscriber
public void onSubscribe(Subscription subscription) {
if (SubscriptionHelper.validate(this.e, subscription)) {
this.e = subscription;
this.a.onSubscribe(this);
subscription.request(Long.MAX_VALUE);
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public T poll() throws Exception {
return this.b.poll();
}
@Override // org.reactivestreams.Subscription
public void request(long j) {
if (this.j || !SubscriptionHelper.validate(j)) {
return;
}
BackpressureHelper.a(this.i, j);
drain();
}
@Override // io.reactivex.internal.fuseable.QueueFuseable
public int requestFusion(int i) {
if ((i & 2) == 0) {
return 0;
}
this.j = true;
return 2;
}
}
public FlowableOnBackpressureBuffer(Flowable<T> flowable, int i, boolean z, boolean z2, Action action) {
super(flowable);
this.c = i;
this.d = z;
this.e = z2;
this.f = action;
}
@Override // io.reactivex.Flowable
protected void b(Subscriber<? super T> subscriber) {
this.b.a((FlowableSubscriber) new BackpressureBufferSubscriber(subscriber, this.c, this.d, this.e, this.f));
}
}

View File

@@ -0,0 +1,102 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.Consumer;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import io.reactivex.internal.util.BackpressureHelper;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicLong;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
/* loaded from: classes2.dex */
public final class FlowableOnBackpressureDrop<T> extends AbstractFlowableWithUpstream<T, T> implements Consumer<T> {
final Consumer<? super T> c;
static final class BackpressureDropSubscriber<T> extends AtomicLong implements FlowableSubscriber<T>, Subscription {
final Subscriber<? super T> a;
final Consumer<? super T> b;
Subscription c;
boolean d;
BackpressureDropSubscriber(Subscriber<? super T> subscriber, Consumer<? super T> consumer) {
this.a = subscriber;
this.b = consumer;
}
@Override // org.reactivestreams.Subscription
public void cancel() {
this.c.cancel();
}
@Override // org.reactivestreams.Subscriber
public void onComplete() {
if (this.d) {
return;
}
this.d = true;
this.a.onComplete();
}
@Override // org.reactivestreams.Subscriber
public void onError(Throwable th) {
if (this.d) {
RxJavaPlugins.b(th);
} else {
this.d = true;
this.a.onError(th);
}
}
@Override // org.reactivestreams.Subscriber
public void onNext(T t) {
if (this.d) {
return;
}
if (get() != 0) {
this.a.onNext(t);
BackpressureHelper.b(this, 1L);
return;
}
try {
this.b.accept(t);
} catch (Throwable th) {
Exceptions.b(th);
cancel();
onError(th);
}
}
@Override // org.reactivestreams.Subscriber
public void onSubscribe(Subscription subscription) {
if (SubscriptionHelper.validate(this.c, subscription)) {
this.c = subscription;
this.a.onSubscribe(this);
subscription.request(Long.MAX_VALUE);
}
}
@Override // org.reactivestreams.Subscription
public void request(long j) {
if (SubscriptionHelper.validate(j)) {
BackpressureHelper.a(this, j);
}
}
}
public FlowableOnBackpressureDrop(Flowable<T> flowable) {
super(flowable);
this.c = this;
}
@Override // io.reactivex.functions.Consumer
public void accept(T t) {
}
@Override // io.reactivex.Flowable
protected void b(Subscriber<? super T> subscriber) {
this.b.a((FlowableSubscriber) new BackpressureDropSubscriber(subscriber, this.c));
}
}

View File

@@ -0,0 +1,87 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.exceptions.MissingBackpressureException;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import io.reactivex.internal.util.BackpressureHelper;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicLong;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
/* loaded from: classes2.dex */
public final class FlowableOnBackpressureError<T> extends AbstractFlowableWithUpstream<T, T> {
static final class BackpressureErrorSubscriber<T> extends AtomicLong implements FlowableSubscriber<T>, Subscription {
final Subscriber<? super T> a;
Subscription b;
boolean c;
BackpressureErrorSubscriber(Subscriber<? super T> subscriber) {
this.a = subscriber;
}
@Override // org.reactivestreams.Subscription
public void cancel() {
this.b.cancel();
}
@Override // org.reactivestreams.Subscriber
public void onComplete() {
if (this.c) {
return;
}
this.c = true;
this.a.onComplete();
}
@Override // org.reactivestreams.Subscriber
public void onError(Throwable th) {
if (this.c) {
RxJavaPlugins.b(th);
} else {
this.c = true;
this.a.onError(th);
}
}
@Override // org.reactivestreams.Subscriber
public void onNext(T t) {
if (this.c) {
return;
}
if (get() == 0) {
onError(new MissingBackpressureException("could not emit value due to lack of requests"));
} else {
this.a.onNext(t);
BackpressureHelper.b(this, 1L);
}
}
@Override // org.reactivestreams.Subscriber
public void onSubscribe(Subscription subscription) {
if (SubscriptionHelper.validate(this.b, subscription)) {
this.b = subscription;
this.a.onSubscribe(this);
subscription.request(Long.MAX_VALUE);
}
}
@Override // org.reactivestreams.Subscription
public void request(long j) {
if (SubscriptionHelper.validate(j)) {
BackpressureHelper.a(this, j);
}
}
}
public FlowableOnBackpressureError(Flowable<T> flowable) {
super(flowable);
}
@Override // io.reactivex.Flowable
protected void b(Subscriber<? super T> subscriber) {
this.b.a((FlowableSubscriber) new BackpressureErrorSubscriber(subscriber));
}
}

View File

@@ -0,0 +1,144 @@
package io.reactivex.internal.operators.flowable;
import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import io.reactivex.internal.util.BackpressureHelper;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
/* loaded from: classes2.dex */
public final class FlowableOnBackpressureLatest<T> extends AbstractFlowableWithUpstream<T, T> {
public FlowableOnBackpressureLatest(Flowable<T> flowable) {
super(flowable);
}
@Override // io.reactivex.Flowable
protected void b(Subscriber<? super T> subscriber) {
this.b.a((FlowableSubscriber) new BackpressureLatestSubscriber(subscriber));
}
static final class BackpressureLatestSubscriber<T> extends AtomicInteger implements FlowableSubscriber<T>, Subscription {
final Subscriber<? super T> a;
Subscription b;
volatile boolean c;
Throwable d;
volatile boolean e;
final AtomicLong f = new AtomicLong();
final AtomicReference<T> g = new AtomicReference<>();
BackpressureLatestSubscriber(Subscriber<? super T> subscriber) {
this.a = subscriber;
}
void a() {
if (getAndIncrement() != 0) {
return;
}
Subscriber<? super T> subscriber = this.a;
AtomicLong atomicLong = this.f;
AtomicReference<T> atomicReference = this.g;
int i = 1;
do {
long j = 0;
while (true) {
if (j == atomicLong.get()) {
break;
}
boolean z = this.c;
T andSet = atomicReference.getAndSet(null);
boolean z2 = andSet == null;
if (a(z, z2, subscriber, atomicReference)) {
return;
}
if (z2) {
break;
}
subscriber.onNext(andSet);
j++;
}
if (j == atomicLong.get()) {
if (a(this.c, atomicReference.get() == null, subscriber, atomicReference)) {
return;
}
}
if (j != 0) {
BackpressureHelper.b(atomicLong, j);
}
i = addAndGet(-i);
} while (i != 0);
}
@Override // org.reactivestreams.Subscription
public void cancel() {
if (this.e) {
return;
}
this.e = true;
this.b.cancel();
if (getAndIncrement() == 0) {
this.g.lazySet(null);
}
}
@Override // org.reactivestreams.Subscriber
public void onComplete() {
this.c = true;
a();
}
@Override // org.reactivestreams.Subscriber
public void onError(Throwable th) {
this.d = th;
this.c = true;
a();
}
@Override // org.reactivestreams.Subscriber
public void onNext(T t) {
this.g.lazySet(t);
a();
}
@Override // org.reactivestreams.Subscriber
public void onSubscribe(Subscription subscription) {
if (SubscriptionHelper.validate(this.b, subscription)) {
this.b = subscription;
this.a.onSubscribe(this);
subscription.request(Long.MAX_VALUE);
}
}
@Override // org.reactivestreams.Subscription
public void request(long j) {
if (SubscriptionHelper.validate(j)) {
BackpressureHelper.a(this.f, j);
a();
}
}
boolean a(boolean z, boolean z2, Subscriber<?> subscriber, AtomicReference<T> atomicReference) {
if (this.e) {
atomicReference.lazySet(null);
return true;
}
if (!z) {
return false;
}
Throwable th = this.d;
if (th != null) {
atomicReference.lazySet(null);
subscriber.onError(th);
return true;
}
if (!z2) {
return false;
}
subscriber.onComplete();
return true;
}
}
}