Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2017-2021 VMware Inc. or its affiliates, All Rights Reserved.
*
* 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
*
* https://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 reactor.core.publisher;
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.Objects;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.function.Consumer;
import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber;
import reactor.core.scheduler.Scheduler;
import reactor.util.Logger;
import reactor.util.Loggers;
import reactor.util.annotation.Nullable;
import reactor.util.context.Context;
import static reactor.core.Scannable.Attr.RUN_STYLE;
import static reactor.core.Scannable.Attr.RunStyle.ASYNC;
/**
* Buffers values if the subscriber doesn't request fast enough, bounding the buffer to a
* chosen size and applying a TTL (time-to-live) to the elements. If the buffer overflows,
* drop the oldest element.
*
* @author Stephane Maldini
* @author Simon Baslé
* @author David Karnok
*/
//see https://github.com/akarnokd/RxJava2Extensions/blob/master/src/main/java/hu/akarnokd/rxjava2/operators/FlowableOnBackpressureTimeout.java
final class FluxOnBackpressureBufferTimeout extends InternalFluxOperator {
private static final Logger LOGGER =
Loggers.getLogger(FluxOnBackpressureBufferTimeout.class);
final Duration ttl;
final Scheduler ttlScheduler;
final int bufferSize;
final Consumer super O> onBufferEviction;
FluxOnBackpressureBufferTimeout(Flux extends O> source,
Duration ttl,
Scheduler ttlScheduler,
int bufferSize,
Consumer super O> onBufferEviction) {
super(source);
this.ttl = ttl;
this.ttlScheduler = ttlScheduler;
this.bufferSize = bufferSize;
this.onBufferEviction = onBufferEviction;
}
@Override
public CoreSubscriber super O> subscribeOrReturn(CoreSubscriber super O> actual) {
return new BackpressureBufferTimeoutSubscriber<>(actual,
ttl,
ttlScheduler,
bufferSize,
onBufferEviction);
}
@Override
public int getPrefetch() {
return Integer.MAX_VALUE;
}
@Override
public Object scanUnsafe(Attr key) {
if (key == Attr.RUN_ON) return ttlScheduler;
if (key == RUN_STYLE) return ASYNC;
return super.scanUnsafe(key);
}
static final class BackpressureBufferTimeoutSubscriber extends ArrayDeque