GH-243 Added wrapper for fluxed Function
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -153,30 +153,27 @@ public class FunctionRegistration<T> implements BeanNameAware {
|
||||
S target = (S) this.target;
|
||||
result = new FunctionRegistration<S>(target);
|
||||
result.type(this.type.getType());
|
||||
boolean flux = type.isWrapper();
|
||||
if (!flux) {
|
||||
if (target instanceof Function) {
|
||||
target = (S) new FluxFunction((Function<?, ?>) target);
|
||||
}
|
||||
else if (target instanceof Supplier) {
|
||||
target = (S) new FluxSupplier((Supplier<?>) target);
|
||||
}
|
||||
else if (target instanceof Consumer) {
|
||||
target = (S) new FluxConsumer((Consumer<?>) target);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (target instanceof Consumer) {
|
||||
target = (S) new FluxedConsumer((Consumer<?>) target);
|
||||
}
|
||||
}
|
||||
|
||||
if (Mono.class.isAssignableFrom(type.getOutputWrapper())) {
|
||||
if (!type.isWrapper()) {
|
||||
target = target instanceof Supplier
|
||||
? (S) new FluxSupplier((Supplier<?>) target)
|
||||
: target instanceof Function
|
||||
? (S) new FluxFunction((Function<?, ?>) target)
|
||||
: (S) new FluxConsumer((Consumer<?>) target);
|
||||
}
|
||||
else if (Mono.class.isAssignableFrom(type.getOutputWrapper())) {
|
||||
target = (S) new FluxToMonoFunction((Function) target);
|
||||
}
|
||||
else if (Mono.class.isAssignableFrom(type.getInputWrapper())) {
|
||||
target = (S) new MonoToFluxFunction((Function) target);
|
||||
}
|
||||
else if (target instanceof Consumer) {
|
||||
target = (S) new FluxedConsumer((Consumer<?>) target);
|
||||
}
|
||||
else if (target instanceof Function) {
|
||||
// target = (S) new FluxedFunction((Function<?, ?>) target);
|
||||
}
|
||||
|
||||
result = result.target(target).names(this.names)
|
||||
.type(result.type.wrap(Flux.class)).properties(this.properties);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Marker wrapper for target Function<Flux, Mono>.
|
||||
* Marker wrapper for target {@code Function<Flux<?>, Mono<?>>}.
|
||||
*
|
||||
* @param <I> type of {@link Flux} input of the target function
|
||||
* @param <O> type of {@link Mono} output of the target function
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2019-2019 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cloud.function.core;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* {@link Function} implementation that wraps a target Function so that the target's
|
||||
* simple input and output types will be wrapped as {@link Flux} instances.
|
||||
*
|
||||
* @param <T> input type of target function
|
||||
* @param <R> output type of target function
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public class FluxedFunction<I, O>
|
||||
extends WrappedFunction<I, O, Flux<I>, Flux<O>, Function<Flux<I>, Flux<O>>> {
|
||||
|
||||
public FluxedFunction(Function<Flux<I>, Flux<O>> target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<O> apply(Flux<I> input) {
|
||||
return input.transform(this.getTarget());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user