From 75ff56962af2ca558cb109a70c64456d5cd70ecc Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 25 Feb 2015 16:32:40 +0200 Subject: [PATCH] INT-3655: Remove Reactor `Function` Usage JIRA: https://jira.spring.io/browse/INT-3655 In addition, change `GatewayProxyFactoryBean` to the logic to ensure that the Reactor is really `optional` INT-3655: Doc Polishing --- build.gradle | 2 +- .../gateway/GatewayProxyFactoryBean.java | 21 ++++++---- .../splitter/AbstractMessageSplitter.java | 5 +-- .../integration/util/Function.java | 42 +++++++++++++++++++ .../integration/util/FunctionIterator.java | 4 +- src/reference/docbook/whats-new.xml | 14 +++++++ 6 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/util/Function.java diff --git a/build.gradle b/build.gradle index 70c76b1c9d..ea81e8daf8 100644 --- a/build.gradle +++ b/build.gradle @@ -110,7 +110,7 @@ subprojects { subproject -> pahoMqttClientVersion = '0.4.0' postgresVersion = '9.1-901-1.jdbc4' reactorVersion = '2.0.0.RC1' - reactorSpringVersion = '2.0.0.M2' + reactorSpringVersion = '2.0.0.RC1' romeToolsVersion = '1.5.0' saajApiVersion = '1.3.5' saajImplVersion = '1.3.23' diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index 1008284bf3..94430049ce 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -86,6 +86,9 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint private static final SpelExpressionParser PARSER = new SpelExpressionParser(); + private static final boolean reactorPresent = ClassUtils.isPresent("reactor.Environment", + GatewayProxyFactoryBean.class.getClassLoader()); + private volatile Class serviceInterface; private volatile MessageChannel defaultRequestChannel; @@ -116,7 +119,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint private volatile Class asyncSubmitListenableType; - private volatile Environment reactorEnvironment; + private volatile Object reactorEnvironment; private volatile boolean initialized; @@ -255,7 +258,10 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint * @param reactorEnvironment the Reactor Environment. * @since 4.1 */ - public void setReactorEnvironment(Environment reactorEnvironment) { + public void setReactorEnvironment(Object reactorEnvironment) { + if (!Environment.class.getName().equals(reactorEnvironment.getClass().getName())) { + throw new IllegalArgumentException("The 'reactorEnvironment' must be instance of 'reactor.Environment'"); + } this.reactorEnvironment = reactorEnvironment; } @@ -354,11 +360,11 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint } } } - if (Promise.class.isAssignableFrom(returnType)) { + if (reactorPresent && Promise.class.isAssignableFrom(returnType)) { if (this.reactorEnvironment == null) { throw new IllegalStateException("'reactorEnvironment' is required in case of 'Promise' return type."); } - return Promises.task(this.reactorEnvironment, + return Promises.task((Environment) this.reactorEnvironment, Functions.supplier(new AsyncInvocationTask(invocation))); } return this.doInvoke(invocation); @@ -584,7 +590,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint if (Future.class.isAssignableFrom(expectedReturnType)) { return (T) source; } - if (Promise.class.isAssignableFrom(expectedReturnType)) { + if (reactorPresent && Promise.class.isAssignableFrom(expectedReturnType)) { return (T) source; } if (this.getConversionService() != null) { @@ -596,7 +602,8 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint } private static boolean hasReturnParameterizedWithMessage(Method method) { - if (Future.class.isAssignableFrom(method.getReturnType()) || Promise.class.isAssignableFrom(method.getReturnType())) { + if (Future.class.isAssignableFrom(method.getReturnType()) + || (reactorPresent && Promise.class.isAssignableFrom(method.getReturnType()))) { Type returnType = method.getGenericReturnType(); if (returnType instanceof ParameterizedType) { Type[] typeArgs = ((ParameterizedType) returnType).getActualTypeArguments(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java index 2811be686b..26ffce2694 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -24,12 +24,11 @@ import java.util.concurrent.atomic.AtomicInteger; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; +import org.springframework.integration.util.Function; import org.springframework.integration.util.FunctionIterator; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; -import reactor.fn.Function; - /** * Base class for Message-splitting handlers. * diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/Function.java b/spring-integration-core/src/main/java/org/springframework/integration/util/Function.java new file mode 100644 index 0000000000..970ada0871 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/Function.java @@ -0,0 +1,42 @@ +/* + * Copyright 2015 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.integration.util; + +/** + * Implementations of this class perform work on the given parameter + * and return a result of an optionally different type. + * + *

This is a copy of Java 8 {@code Function} interface. + * + * @param The type of the input to the apply operation + * @param The type of the result of the apply operation + * + * @author Jon Brisbin + * @author Stephane Maldini + * @since 4.0 + */ +public interface Function { + + /** + * Execute the logic of the action, accepting the given parameter. + * @param t The parameter to pass to the action. + * @return result + */ + R apply(T t); + +} + diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/FunctionIterator.java b/spring-integration-core/src/main/java/org/springframework/integration/util/FunctionIterator.java index 45909ba147..b315220e78 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/FunctionIterator.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/FunctionIterator.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 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. @@ -19,8 +19,6 @@ package org.springframework.integration.util; import java.util.Iterator; import java.util.NoSuchElementException; -import reactor.fn.Function; - /** * An {@link Iterator} implementation to convert each item from the target * {@link #iterator} to a new object applying the {@link #function} on {@link #next()}. diff --git a/src/reference/docbook/whats-new.xml b/src/reference/docbook/whats-new.xml index 98cb872dfc..9e7137d489 100644 --- a/src/reference/docbook/whats-new.xml +++ b/src/reference/docbook/whats-new.xml @@ -94,5 +94,19 @@ to 1. The annotation now defaults this attribute to 1. +

+ API Changes + + o.s.integtation.util.FunctionIterator now requires a + o.s.integration.util.Function instead of a + reactor.function.Function. This was done to remove + an unnecessary hard dependency on Reactor. Any uses of this iterator will need to + change the import. + + + Of course, Reactor is still supported for functionality such as the Promise + gateway; the dependency was removed for those users who don't need it. + +