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.util.Objects;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.stream.Stream;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber;
import reactor.core.Disposable;
import reactor.core.Disposables;
import reactor.core.Exceptions;
import reactor.core.Scannable;
import reactor.core.scheduler.Scheduler;
import reactor.util.concurrent.Queues;
/**
* @author David Karnok
*/
final class FluxWindowTimeout extends InternalFluxOperator> {
final int maxSize;
final long timespan;
final TimeUnit unit;
final Scheduler timer;
FluxWindowTimeout(Flux source, int maxSize, long timespan, TimeUnit unit, Scheduler timer) {
super(source);
if (timespan <= 0) {
throw new IllegalArgumentException("Timeout period must be strictly positive");
}
if (maxSize <= 0) {
throw new IllegalArgumentException("maxSize must be strictly positive");
}
this.timer = Objects.requireNonNull(timer, "Timer");
this.timespan = timespan;
this.unit = Objects.requireNonNull(unit, "unit");
this.maxSize = maxSize;
}
@Override
public CoreSubscriber super T> subscribeOrReturn(CoreSubscriber super Flux> actual) {
return new WindowTimeoutSubscriber<>(actual, maxSize,
timespan, unit,
timer);
}
@Override
public Object scanUnsafe(Attr key) {
if (key == Attr.RUN_ON) return timer;
if (key == Attr.RUN_STYLE) return Attr.RunStyle.ASYNC;
return super.scanUnsafe(key);
}
static final class WindowTimeoutSubscriber implements InnerOperator> {
final CoreSubscriber super Flux> actual;
final long timespan;
final TimeUnit unit;
final Scheduler scheduler;
final int maxSize;
final Scheduler.Worker worker;
final Queue