hu.akarnokd.rxjava2.operators.FlowableOnBackpressureTimeout Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava2-extensions Show documentation
Show all versions of rxjava2-extensions Show documentation
rxjava2-extensions developed by David Karnok
/*
* Copyright 2016 David Karnok
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hu.akarnokd.rxjava2.operators;
import java.util.ArrayDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.*;
import org.reactivestreams.*;
import io.reactivex.*;
import io.reactivex.Scheduler.Worker;
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;
/**
* If the downstream doesn't request, it buffers events and times out
* old elements from the front of the buffer.
*/
final class FlowableOnBackpressureTimeout extends Flowable
implements FlowableTransformer {
final Publisher source;
final int maxSize;
final long timeout;
final TimeUnit unit;
final Scheduler scheduler;
final Consumer super T> onEvict;
FlowableOnBackpressureTimeout(Publisher source, int maxSize, long timeout, TimeUnit unit,
Scheduler scheduler, Consumer super T> onEvict) {
this.source = source;
this.maxSize = maxSize;
this.timeout = timeout;
this.unit = unit;
this.scheduler = scheduler;
this.onEvict = onEvict;
}
@Override
public Publisher apply(Flowable upstream) {
return new FlowableOnBackpressureTimeout(upstream, maxSize, timeout, unit, scheduler, onEvict);
}
@Override
protected void subscribeActual(Subscriber super T> s) {
source.subscribe(new OnBackpressureTimeoutSubscriber(s, maxSize, timeout, unit, scheduler.createWorker(), onEvict));
}
static final class OnBackpressureTimeoutSubscriber
extends AtomicInteger
implements Subscriber, Subscription, Runnable {
private static final long serialVersionUID = 2264324530873250941L;
final Subscriber super T> actual;
final AtomicLong requested;
final int maxSizeDouble;
final long timeout;
final TimeUnit unit;
final Worker worker;
final Consumer super T> onEvict;
Subscription s;
final ArrayDeque
© 2015 - 2025 Weber Informatics LLC | Privacy Policy