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-2023 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.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber;
import reactor.core.Exceptions;
import reactor.util.annotation.Nullable;
/**
* Concatenates a fixed array of Publishers' values.
*
* @param the value type
* @see Reactive-Streams-Commons
*/
final class FluxConcatArray extends Flux implements SourceProducer {
static final Object WORKING = new Object();
static final Object DONE = new Object();
final Publisher extends T>[] array;
final boolean delayError;
@SafeVarargs
FluxConcatArray(boolean delayError, Publisher extends T>... array) {
this.array = Objects.requireNonNull(array, "array");
this.delayError = delayError;
}
@Override
public void subscribe(CoreSubscriber super T> actual) {
Publisher extends T>[] a = array;
if (a.length == 0) {
Operators.complete(actual);
return;
}
if (a.length == 1) {
Publisher extends T> p = a[0];
if (p == null) {
Operators.error(actual, new NullPointerException("The single source Publisher is null"));
} else {
p = Operators.toFluxOrMono(p);
p.subscribe(actual);
}
return;
}
if (delayError) {
ConcatArrayDelayErrorSubscriber parent = new
ConcatArrayDelayErrorSubscriber<>(actual, a);
parent.onComplete();
return;
}
ConcatArraySubscriber parent = new ConcatArraySubscriber<>(actual, a);
parent.onComplete();
}
@Override
public Object scanUnsafe(Attr key) {
if (key == Attr.DELAY_ERROR) return delayError;
if (key == Attr.RUN_STYLE) return Attr.RunStyle.SYNC;
return SourceProducer.super.scanUnsafe(key);
}
/**
* Returns a new instance which has the additional source to be merged together with
* the current array of sources.
*
* This operation doesn't change the current FluxMerge instance.
*
* @param source the new source to merge with the others
* @return the new FluxConcatArray instance
*/
FluxConcatArray concatAdditionalSourceLast(Publisher extends T> source) {
int n = array.length;
@SuppressWarnings("unchecked")
Publisher extends T>[] newArray = new Publisher[n + 1];
System.arraycopy(array, 0, newArray, 0, n);
newArray[n] = source;
return new FluxConcatArray<>(delayError, newArray);
}
/**
* Returns a new instance which has the additional source to be merged together with
* the current array of sources.
*
* This operation doesn't change the current FluxMerge instance.
*
* @param source the new source to merge with the others
* @return the new FluxConcatArray instance
*/
@SuppressWarnings("unchecked")
FluxConcatArray concatAdditionalIgnoredLast(Publisher extends V>
source) {
int n = array.length;
Publisher extends V>[] newArray = new Publisher[n + 1];
//noinspection SuspiciousSystemArraycopy
System.arraycopy(array, 0, newArray, 0, n);
newArray[n - 1] = Mono.ignoreElements(newArray[n - 1]);
newArray[n] = source;
return new FluxConcatArray<>(delayError, newArray);
}
/**
* Returns a new instance which has the additional first source to be concatenated together with
* the current array of sources.
*
* This operation doesn't change the current FluxConcatArray instance.
*
* @param source the new source to merge with the others
* @return the new FluxConcatArray instance
*/
FluxConcatArray concatAdditionalSourceFirst(Publisher extends T> source) {
int n = array.length;
@SuppressWarnings("unchecked")
Publisher extends T>[] newArray = new Publisher[n + 1];
System.arraycopy(array, 0, newArray, 1, n);
newArray[0] = source;
return new FluxConcatArray<>(delayError, newArray);
}
interface SubscriptionAware {
Subscription upstream();
}
static final class ConcatArraySubscriber extends ThreadLocal