diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionRegistration.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionRegistration.java index 8907c6ee9..484f36011 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionRegistration.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionRegistration.java @@ -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 implements BeanNameAware { S target = (S) this.target; result = new FunctionRegistration(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); } diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FluxToMonoFunction.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FluxToMonoFunction.java index 07c23790f..cfff5d9fa 100644 --- a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FluxToMonoFunction.java +++ b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FluxToMonoFunction.java @@ -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, Mono>}. * * @param type of {@link Flux} input of the target function * @param type of {@link Mono} output of the target function diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FluxedFunction.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FluxedFunction.java new file mode 100644 index 000000000..a1aeae979 --- /dev/null +++ b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FluxedFunction.java @@ -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 input type of target function + * @param output type of target function + * @author Oleg Zhurakousky + * @since 2.0.1 + */ +public class FluxedFunction + extends WrappedFunction, Flux, Function, Flux>> { + + public FluxedFunction(Function, Flux> target) { + super(target); + } + + @Override + public Flux apply(Flux input) { + return input.transform(this.getTarget()); + } + +}