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) 2016-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.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.reactivestreams.Publisher;
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.util.annotation.Nullable;
import reactor.util.concurrent.Queues;
import reactor.util.context.Context;
/**
* A Publisher that correlates two Publishers when they overlap in time and groups the
* results.
*
* There are no guarantees in what order the items get combined when multiple items from
* one or both source Publishers overlap.
*
* @param the left Publisher to correlate items from the source Publisher with
* @param the other Publisher to correlate items from the source Publisher with
* @param type that a function returns via a Publisher whose emissions indicate
* the duration of the values of the source Publisher
* @param type that a function that returns via a Publisher whose emissions
* indicate the duration of the values of the {@code right} Publisher
* @param type that a function that takes an item emitted by each Publisher and
* returns the value to be emitted by the resulting Publisher
* @see https://github.com/reactor/reactive-streams-commons
* @since 3.0
*/
final class FluxGroupJoin
extends InternalFluxOperator {
final Publisher other;
final Function> leftEnd;
final Function> rightEnd;
final BiFunction, ? extends R> resultSelector;
final Supplier> processorQueueSupplier;
FluxGroupJoin(Flux source,
Publisher other,
Function> leftEnd,
Function> rightEnd,
BiFunction, ? extends R> resultSelector,
Supplier> queueSupplier,
Supplier> processorQueueSupplier) {
super(source);
this.other = Objects.requireNonNull(other, "other");
this.leftEnd = Objects.requireNonNull(leftEnd, "leftEnd");
this.rightEnd = Objects.requireNonNull(rightEnd, "rightEnd");
this.processorQueueSupplier = Objects.requireNonNull(processorQueueSupplier, "processorQueueSupplier");
this.resultSelector = Objects.requireNonNull(resultSelector, "resultSelector");
}
@Override
public CoreSubscriber subscribeOrReturn(CoreSubscriber actual) {
GroupJoinSubscription parent =
new GroupJoinSubscription<>(actual,
leftEnd,
rightEnd,
resultSelector,
processorQueueSupplier);
actual.onSubscribe(parent);
LeftRightSubscriber left = new LeftRightSubscriber(parent, true);
parent.cancellations.add(left);
LeftRightSubscriber right = new LeftRightSubscriber(parent, false);
parent.cancellations.add(right);
source.subscribe(left);
other.subscribe(right);
return null;
}
@Override
public Object scanUnsafe(Attr key) {
if (key == Attr.RUN_STYLE) return Attr.RunStyle.SYNC;
return super.scanUnsafe(key);
}
interface JoinSupport extends InnerProducer {
void innerError(Throwable ex);
void innerComplete(LeftRightSubscriber sender);
void innerValue(boolean isLeft, Object o);
void innerClose(boolean isLeft, LeftRightEndSubscriber index);
void innerCloseError(Throwable ex);
}
static final class GroupJoinSubscription
implements JoinSupport {
final Queue