From 370be4853dd464b35fa881a68af8d6781e7d91be Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 26 Aug 2016 14:52:23 -0400 Subject: [PATCH] Apply Some Java 8 Code Changes * Make most functional interfaces as `@FunctionalInterface` * Convert some abstract classes to `@FunctionalInterface` with `default` methods * Apply Lambda style implementation in some places * Remove `Function` in favor of similar in Java 8 * Remove redundant code from `DefaultAmqpHeaderMapper` since we are already on Spring AMQP-2.0 * Add several ctors to the `ExpressionEvaluatingMessageListProcessor` * Populate explicit `Boolean.class` `expectedType` from the `ExpressionEvaluatingReleaseStrategy` --- .../amqp/support/DefaultAmqpHeaderMapper.java | 32 +---- .../aggregator/CorrelationStrategy.java | 3 +- ...ressionEvaluatingMessageListProcessor.java | 54 ++++++- .../ExpressionEvaluatingReleaseStrategy.java | 6 +- .../aggregator/MessageGroupProcessor.java | 1 + .../aggregator/MessageListProcessor.java | 1 + .../aggregator/ReleaseStrategy.java | 3 +- ...eadStatePropagationChannelInterceptor.java | 2 +- .../IntegrationConfigurationInitializer.java | 1 + .../integration/core/GenericSelector.java | 3 +- .../integration/core/MessageSelector.java | 3 +- .../integration/core/MessageSource.java | 3 +- .../dispatcher/LoadBalancingStrategy.java | 1 + .../MessageHandlingTaskDecorator.java | 1 + .../expression/ExpressionSource.java | 3 +- .../gateway/RequestReplyExchanger.java | 1 + .../integration/handler/MessageProcessor.java | 3 +- .../handler/MessageTriggerAction.java | 3 +- .../mapping/InboundMessageMapper.java | 3 +- .../mapping/OutboundMessageMapper.java | 3 +- .../routingslip/RoutingSlipRouteStrategy.java | 3 +- .../splitter/AbstractMessageSplitter.java | 14 +- .../integration/support/MessageDecorator.java | 1 + .../support/locks/LockRegistry.java | 1 + .../management/ConfigurableMetricsAware.java | 1 + .../transformer/GenericTransformer.java | 1 + .../integration/transformer/Transformer.java | 1 + .../integration/util/CollectionFilter.java | 3 +- .../integration/util/Function.java | 42 ------ .../integration/util/FunctionIterator.java | 1 + .../integration/file/FileNameGenerator.java | 3 +- .../file/filters/FileListFilter.java | 3 +- .../file/remote/ClientCallback.java | 1 + .../remote/ClientCallbackWithoutResult.java | 8 +- .../file/remote/InputStreamCallback.java | 2 +- .../file/remote/RemoteFileTemplate.java | 135 +++++++----------- .../file/remote/SessionCallback.java | 1 + .../remote/SessionCallbackWithoutResult.java | 9 +- .../FileTransferringMessageHandler.java | 2 +- .../file/remote/session/SessionFactory.java | 1 + .../remote/session/SessionFactoryLocator.java | 1 + .../ftp/session/FtpRemoteFileTemplate.java | 10 +- .../config/GroovyControlBusFactoryBean.java | 22 ++- .../ip/tcp/connection/TcpListener.java | 1 + .../jdbc/MessagePreparedStatementSetter.java | 3 +- .../jdbc/SqlParameterSourceFactory.java | 1 + .../integration/jmx/MBeanAttributeFilter.java | 1 + .../integration/jmx/MBeanObjectConverter.java | 1 + .../integration/mail/SearchTermStrategy.java | 1 + .../redis/outbound/ArgumentsStrategy.java | 3 +- .../integration/scripting/ScriptExecutor.java | 6 +- .../scripting/ScriptVariableGenerator.java | 1 + .../jsr223/AbstractScriptExecutor.java | 5 - .../sftp/gateway/SftpOutboundGateway.java | 7 +- .../sftp/outbound/SftpMessageHandler.java | 17 +-- .../sftp/session/SftpRemoteFileTemplate.java | 12 +- .../integration/syslog/MessageConverter.java | 1 + .../xml/splitter/XPathMessageSplitter.java | 22 ++- 58 files changed, 208 insertions(+), 270 deletions(-) delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/util/Function.java diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java index 263cf647c0..806c4e3af8 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java @@ -16,13 +16,11 @@ package org.springframework.integration.amqp.support; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; import org.springframework.amqp.core.MessageDeliveryMode; import org.springframework.amqp.core.MessageProperties; @@ -31,9 +29,6 @@ import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.integration.mapping.AbstractHeaderMapper; import org.springframework.integration.mapping.support.JsonHeaders; import org.springframework.util.MimeType; -import org.springframework.util.ReflectionUtils; -import org.springframework.util.ReflectionUtils.FieldCallback; -import org.springframework.util.ReflectionUtils.FieldFilter; import org.springframework.util.StringUtils; /** @@ -59,8 +54,6 @@ import org.springframework.util.StringUtils; */ public class DefaultAmqpHeaderMapper extends AbstractHeaderMapper implements AmqpHeaderMapper { - static final boolean CONSUMER_METADATA_PRESENT; - private static final List STANDARD_HEADER_NAMES = new ArrayList(); static { @@ -90,27 +83,6 @@ public class DefaultAmqpHeaderMapper extends AbstractHeaderMapper toHeadersFromRequest(MessageProperties source) { Map headersFromRequest = super.toHeadersFromRequest(source); - if (CONSUMER_METADATA_PRESENT) { - addConsumerMetadata(source, headersFromRequest); - } + addConsumerMetadata(source, headersFromRequest); return headersFromRequest; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/CorrelationStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/CorrelationStrategy.java index b124738f47..90f622b8ad 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/CorrelationStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/CorrelationStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -25,6 +25,7 @@ import org.springframework.messaging.Message; * @author Marius Bogoevici * @author Iwein Fuld */ +@FunctionalInterface public interface CorrelationStrategy { /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageListProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageListProcessor.java index 6e970a58d3..3a8be3aacc 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageListProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageListProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -22,29 +22,41 @@ import org.springframework.expression.Expression; import org.springframework.expression.ParseException; import org.springframework.integration.util.AbstractExpressionEvaluator; import org.springframework.messaging.Message; +import org.springframework.util.Assert; /** * A base class for aggregators that evaluates a SpEL expression with the message list as the root object within the * evaluation context. * * @author Dave Syer + * @author Artem Bilan * @since 2.0 */ -public class ExpressionEvaluatingMessageListProcessor extends AbstractExpressionEvaluator implements MessageListProcessor { +public class ExpressionEvaluatingMessageListProcessor extends AbstractExpressionEvaluator + implements MessageListProcessor { private final Expression expression; private volatile Class expectedType = null; /** - * Set the result type expected from evaluation of the expression. - * - * @param expectedType The expected type. + * Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided + * SpEL expression and expected result type. + * @param expression a SpEL expression to evaluate in {@link #process(Collection)}. + * @param expectedType an expected result type. + * @since 5.0 */ - public void setExpectedType(Class expectedType) { + public ExpressionEvaluatingMessageListProcessor(String expression, Class expectedType) { + this(expression); this.expectedType = expectedType; } + /** + * Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided + * SpEL expression and expected result type. + * @param expression a SpEL expression to evaluate in {@link #process(Collection)}. + * @since 5.0 + */ public ExpressionEvaluatingMessageListProcessor(String expression) { try { this.expression = EXPRESSION_PARSER.parseExpression(expression); @@ -54,6 +66,36 @@ public class ExpressionEvaluatingMessageListProcessor extends AbstractExpression } } + /** + * Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided + * expression and expected result type. + * @param expression an expression to evaluate in {@link #process(Collection)}. + * @param expectedType an expected result type. + * @since 5.0 + */ + public ExpressionEvaluatingMessageListProcessor(Expression expression, Class expectedType) { + this(expression); + this.expectedType = expectedType; + } + + /** + * Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided expression. + * @param expression an expression to evaluate in {@link #process(Collection)}. + * @since 5.0 + */ + public ExpressionEvaluatingMessageListProcessor(Expression expression) { + Assert.notNull(expression, "'expression' must not be null."); + this.expression = expression; + } + + /** + * Set the result type expected from evaluation of the expression. + * @param expectedType The expected type. + */ + public void setExpectedType(Class expectedType) { + this.expectedType = expectedType; + } + /** * Processes the Message by evaluating the expression with that Message as the root object. The expression * evaluation result Object will be returned. diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategy.java index d0e0dc414b..d28bce3f5b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2016 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. @@ -27,7 +27,7 @@ public class ExpressionEvaluatingReleaseStrategy extends ExpressionEvaluatingMes ReleaseStrategy { public ExpressionEvaluatingReleaseStrategy(String expression) { - super(expression); + super(expression, Boolean.class); } /** @@ -35,7 +35,7 @@ public class ExpressionEvaluatingReleaseStrategy extends ExpressionEvaluatingMes * be boolean). */ public boolean canRelease(MessageGroup messages) { - return ((Boolean) process(messages.getMessages())).booleanValue(); + return (Boolean) process(messages.getMessages()); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupProcessor.java index 15bac7e115..1316205fbf 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageGroupProcessor.java @@ -24,6 +24,7 @@ import org.springframework.integration.store.MessageGroup; * @author Iwein Fuld * @see org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler */ +@FunctionalInterface public interface MessageGroupProcessor { /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageListProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageListProcessor.java index e11cb59e9a..3eff678e29 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageListProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageListProcessor.java @@ -24,6 +24,7 @@ import org.springframework.messaging.Message; * @author Dave Syer * */ +@FunctionalInterface public interface MessageListProcessor { Object process(Collection> messages); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ReleaseStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ReleaseStrategy.java index ba928f82ce..d213c68806 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ReleaseStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ReleaseStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2016 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. @@ -27,6 +27,7 @@ import org.springframework.integration.store.MessageGroup; * @author Mark Fisher * @author Dave Syer */ +@FunctionalInterface public interface ReleaseStrategy { boolean canRelease(MessageGroup group); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java index 7d5d5212fe..ebfa6e1780 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java @@ -116,7 +116,7 @@ public abstract class ThreadStatePropagationChannelInterceptor @Override public Message decorateMessage(Message message) { - return new MessageWithThreadState(message, this.state); + return new MessageWithThreadState<>(message, this.state); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java index 40ba7f73ce..823dd84ffc 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; * @author Artem Bilan * @since 4.0 */ +@FunctionalInterface public interface IntegrationConfigurationInitializer { void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/GenericSelector.java b/spring-integration-core/src/main/java/org/springframework/integration/core/GenericSelector.java index 1db7ecfc9e..12f7f9cf99 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/GenericSelector.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/GenericSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2016 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,6 +24,7 @@ package org.springframework.integration.core; * @author Artem Bilan * @since 4.0 */ +@FunctionalInterface public interface GenericSelector { boolean accept(S source); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSelector.java b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSelector.java index 292873f795..dc696165ee 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSelector.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2016 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. @@ -23,6 +23,7 @@ import org.springframework.messaging.Message; * * @author Mark Fisher */ +@FunctionalInterface public interface MessageSelector extends GenericSelector> { boolean accept(Message message); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSource.java b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSource.java index 2a7f9adb6b..04d85d4ec9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -23,6 +23,7 @@ import org.springframework.messaging.Message; * * @author Mark Fisher */ +@FunctionalInterface public interface MessageSource { /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/LoadBalancingStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/LoadBalancingStrategy.java index b161b76ee0..d8a35292c0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/LoadBalancingStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/LoadBalancingStrategy.java @@ -29,6 +29,7 @@ import org.springframework.messaging.MessageHandler; * @author Oleg Zhurakousky * @since 1.0.3 */ +@FunctionalInterface public interface LoadBalancingStrategy { Iterator getHandlerIterator(Message message, Collection handlers); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/MessageHandlingTaskDecorator.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/MessageHandlingTaskDecorator.java index 34d57bc4ed..0c8e7105f3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/MessageHandlingTaskDecorator.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/MessageHandlingTaskDecorator.java @@ -27,6 +27,7 @@ import org.springframework.messaging.support.MessageHandlingRunnable; * @see UnicastingDispatcher * @see BroadcastingDispatcher */ +@FunctionalInterface public interface MessageHandlingTaskDecorator { Runnable decorate(MessageHandlingRunnable task); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java index 5130644796..d4afa8f9e9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2016 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. @@ -26,6 +26,7 @@ import org.springframework.expression.Expression; * @author Mark Fisher * @since 2.0 */ +@FunctionalInterface public interface ExpressionSource { Expression getExpression(String key, Locale locale); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/RequestReplyExchanger.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/RequestReplyExchanger.java index bd46c73898..4de5a37796 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/RequestReplyExchanger.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/RequestReplyExchanger.java @@ -26,6 +26,7 @@ import org.springframework.messaging.Message; * @author Mark Fisher * @since 2.0 */ +@FunctionalInterface public interface RequestReplyExchanger { Message exchange(Message request); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageProcessor.java index b16172d417..a4121e99b6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -39,6 +39,7 @@ import org.springframework.messaging.Message; * @author Mark Fisher * @since 2.0 */ +@FunctionalInterface public interface MessageProcessor { /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageTriggerAction.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageTriggerAction.java index eb1ef715c0..70c58218e7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageTriggerAction.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageTriggerAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 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. @@ -26,6 +26,7 @@ import org.springframework.messaging.Message; * @since 4.2 * */ +@FunctionalInterface public interface MessageTriggerAction { /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java index c8aa735a3c..95b1058a73 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2016 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. @@ -23,6 +23,7 @@ import org.springframework.messaging.Message; * * @author Mark Fisher */ +@FunctionalInterface public interface InboundMessageMapper { Message toMessage(T object) throws Exception; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java index 1fc40b613d..b46e44ca3d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2016 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. @@ -23,6 +23,7 @@ import org.springframework.messaging.Message; * * @author Mark Fisher */ +@FunctionalInterface public interface OutboundMessageMapper { T fromMessage(Message message) throws Exception; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/routingslip/RoutingSlipRouteStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/routingslip/RoutingSlipRouteStrategy.java index 24ddda5b49..5632412c10 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/routingslip/RoutingSlipRouteStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/routingslip/RoutingSlipRouteStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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. @@ -27,6 +27,7 @@ import org.springframework.messaging.Message; * @since 4.1 * @see org.springframework.integration.handler.AbstractMessageProducingHandler */ +@FunctionalInterface public interface RoutingSlipRouteStrategy { /** 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 33bc48de5c..c27e0c0ac1 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 @@ -26,7 +26,6 @@ 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; @@ -89,7 +88,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess Map messageHeaders = message.getHeaders(); if (willAddHeaders(message)) { - messageHeaders = new HashMap(messageHeaders); + messageHeaders = new HashMap<>(messageHeaders); addHeaders(message, messageHeaders); } final Map headers = messageHeaders; @@ -97,15 +96,8 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess final AtomicInteger sequenceNumber = new AtomicInteger(1); return new FunctionIterator>(iterator, - new Function>() { - - @Override - public AbstractIntegrationMessageBuilder apply(Object object) { - return createBuilder(object, headers, correlationId, sequenceNumber.getAndIncrement(), - sequenceSize); - } - - }); + object -> + createBuilder(object, headers, correlationId, sequenceNumber.getAndIncrement(), sequenceSize)); } private AbstractIntegrationMessageBuilder createBuilder(Object item, Map headers, diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageDecorator.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageDecorator.java index 6306839f60..85bdc7cfb9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageDecorator.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageDecorator.java @@ -27,6 +27,7 @@ import org.springframework.messaging.Message; * @author Artem Bilan * @since 4.2.9 */ +@FunctionalInterface public interface MessageDecorator { Message decorateMessage(Message message); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/locks/LockRegistry.java b/spring-integration-core/src/main/java/org/springframework/integration/support/locks/LockRegistry.java index 3c20ab9efa..c8e4af9475 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/locks/LockRegistry.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/locks/LockRegistry.java @@ -25,6 +25,7 @@ import java.util.concurrent.locks.Lock; * @author Gary Russell * @since 2.1.1 */ +@FunctionalInterface public interface LockRegistry { /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetricsAware.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetricsAware.java index add4ec9c23..e59d8a0ec0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetricsAware.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetricsAware.java @@ -23,6 +23,7 @@ package org.springframework.integration.support.management; * @since 4.2 * */ +@FunctionalInterface public interface ConfigurableMetricsAware { void configureMetrics(M metrics); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/GenericTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/GenericTransformer.java index 11626a43e7..5c9d839f4a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/GenericTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/GenericTransformer.java @@ -25,6 +25,7 @@ package org.springframework.integration.transformer; * @author Artem Bilan * @since 4.0 */ +@FunctionalInterface public interface GenericTransformer { T transform(S source); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/Transformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/Transformer.java index 2b3d7af709..d073fa11e8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/Transformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/Transformer.java @@ -23,6 +23,7 @@ import org.springframework.messaging.Message; * * @author Mark Fisher */ +@FunctionalInterface public interface Transformer extends GenericTransformer, Message> { Message transform(Message message); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/CollectionFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/util/CollectionFilter.java index 9b5797130e..0ba5c954d3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/CollectionFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/CollectionFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2016 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. @@ -25,6 +25,7 @@ import java.util.Collection; * @author Mark Fisher * @since 2.1 */ +@FunctionalInterface public interface CollectionFilter { Collection filter(Collection unfilteredElements); 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 deleted file mode 100644 index e64439b9d8..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/Function.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015-2016 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 54213fb9b3..1123f276f2 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 @@ -17,6 +17,7 @@ package org.springframework.integration.util; import java.util.Iterator; +import java.util.function.Function; /** * An {@link Iterator} implementation to convert each item from the target diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileNameGenerator.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileNameGenerator.java index 9ff63784cb..3698c9cc43 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileNameGenerator.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileNameGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2016 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. @@ -23,6 +23,7 @@ import org.springframework.messaging.Message; * * @author Mark Fisher */ +@FunctionalInterface public interface FileNameGenerator { String generateFileName(Message message); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java index d52dd601b2..875d496c52 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -27,6 +27,7 @@ import java.util.List; * * @since 1.0.0 */ +@FunctionalInterface public interface FileListFilter { /** diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallback.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallback.java index a25a40059a..4ee8901899 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallback.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallback.java @@ -29,6 +29,7 @@ import org.springframework.integration.file.remote.session.Session; * @since 4.1 * */ +@FunctionalInterface public interface ClientCallback { /** diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallbackWithoutResult.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallbackWithoutResult.java index 288fb2f329..3a6cc959f1 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallbackWithoutResult.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/ClientCallbackWithoutResult.java @@ -22,15 +22,17 @@ package org.springframework.integration.file.remote; * access to lower level methods where no result is returned. * * @author Gary Russell + * @author Artem Bilan * * @param The type of the underlying client object. * @since 4.1 * */ -public abstract class ClientCallbackWithoutResult implements ClientCallback { +@FunctionalInterface +public interface ClientCallbackWithoutResult extends ClientCallback { @Override - public Object doWithClient(C client) { + default Object doWithClient(C client) { doWithClientWithoutResult(client); return null; } @@ -43,6 +45,6 @@ public abstract class ClientCallbackWithoutResult implements ClientCallback implements RemoteFileOperations, Initializ */ public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) { Assert.notNull(remoteDirectoryExpression, "remoteDirectoryExpression must not be null"); - this.directoryExpressionProcessor = new ExpressionEvaluatingMessageProcessor(remoteDirectoryExpression, String.class); + this.directoryExpressionProcessor = + new ExpressionEvaluatingMessageProcessor<>(remoteDirectoryExpression, String.class); } /** @@ -150,7 +152,8 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ */ public void setTemporaryRemoteDirectoryExpression(Expression temporaryRemoteDirectoryExpression) { Assert.notNull(temporaryRemoteDirectoryExpression, "temporaryRemoteDirectoryExpression must not be null"); - this.temporaryDirectoryExpressionProcessor = new ExpressionEvaluatingMessageProcessor(temporaryRemoteDirectoryExpression, String.class); + this.temporaryDirectoryExpressionProcessor = + new ExpressionEvaluatingMessageProcessor<>(temporaryRemoteDirectoryExpression, String.class); } /** @@ -161,7 +164,7 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ */ public void setFileNameExpression(Expression fileNameExpression) { Assert.notNull(fileNameExpression, "fileNameExpression must not be null"); - this.fileNameProcessor = new ExpressionEvaluatingMessageProcessor(fileNameExpression, String.class); + this.fileNameProcessor = new ExpressionEvaluatingMessageProcessor<>(fileNameExpression, String.class); } /** @@ -243,10 +246,12 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ } } if (this.autoCreateDirectory) { - Assert.hasText(this.remoteFileSeparator, "'remoteFileSeparator' must not be empty when 'autoCreateDirectory' is set to 'true'"); + Assert.hasText(this.remoteFileSeparator, + "'remoteFileSeparator' must not be empty when 'autoCreateDirectory' is set to 'true'"); } if (this.hasExplicitlySetSuffix && !this.useTemporaryFileName) { - this.logger.warn("Since 'use-temporary-file-name' is set to 'false' the value of 'temporary-file-suffix' has no effect"); + this.logger.warn("Since 'use-temporary-file-name' is set to 'false' " + + "the value of 'temporary-file-suffix' has no effect"); } } @@ -280,46 +285,42 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ final StreamHolder inputStreamHolder = this.payloadToInputStream(message); if (inputStreamHolder != null) { try { - return this.execute(new SessionCallback() { - - @Override - public String doInSession(Session session) throws IOException { - String fileName = inputStreamHolder.getName(); - try { - String remoteDirectory = RemoteFileTemplate.this.directoryExpressionProcessor + return this.execute(session -> { + String fileName = inputStreamHolder.getName(); + try { + String remoteDirectory = RemoteFileTemplate.this.directoryExpressionProcessor + .processMessage(message); + remoteDirectory = RemoteFileTemplate.this.normalizeDirectoryPath(remoteDirectory); + if (StringUtils.hasText(subDirectory)) { + if (subDirectory.startsWith(RemoteFileTemplate.this.remoteFileSeparator)) { + remoteDirectory += subDirectory.substring(1); + } + else { + remoteDirectory += RemoteFileTemplate.this.normalizeDirectoryPath(subDirectory); + } + } + String temporaryRemoteDirectory = remoteDirectory; + if (RemoteFileTemplate.this.temporaryDirectoryExpressionProcessor != null) { + temporaryRemoteDirectory = RemoteFileTemplate.this.temporaryDirectoryExpressionProcessor .processMessage(message); - remoteDirectory = RemoteFileTemplate.this.normalizeDirectoryPath(remoteDirectory); - if (StringUtils.hasText(subDirectory)) { - if (subDirectory.startsWith(RemoteFileTemplate.this.remoteFileSeparator)) { - remoteDirectory += subDirectory.substring(1); - } - else { - remoteDirectory += RemoteFileTemplate.this.normalizeDirectoryPath(subDirectory); - } - } - String temporaryRemoteDirectory = remoteDirectory; - if (RemoteFileTemplate.this.temporaryDirectoryExpressionProcessor != null) { - temporaryRemoteDirectory = RemoteFileTemplate.this.temporaryDirectoryExpressionProcessor - .processMessage(message); - } - fileName = RemoteFileTemplate.this.fileNameGenerator.generateFileName(message); - RemoteFileTemplate.this.sendFileToRemoteDirectory(inputStreamHolder.getStream(), - temporaryRemoteDirectory, remoteDirectory, fileName, session, mode); - return remoteDirectory + fileName; - } - catch (FileNotFoundException e) { - throw new MessageDeliveryException(message, "File [" + inputStreamHolder.getName() - + "] not found in local working directory; it was moved or deleted unexpectedly.", e); - } - catch (IOException e) { - throw new MessageDeliveryException(message, "Failed to transfer file [" - + inputStreamHolder.getName() + " -> " + fileName - + "] from local directory to remote directory.", e); - } - catch (Exception e) { - throw new MessageDeliveryException(message, "Error handling message for file [" - + inputStreamHolder.getName() + " -> " + fileName + "]", e); } + fileName = RemoteFileTemplate.this.fileNameGenerator.generateFileName(message); + RemoteFileTemplate.this.sendFileToRemoteDirectory(inputStreamHolder.getStream(), + temporaryRemoteDirectory, remoteDirectory, fileName, session, mode); + return remoteDirectory + fileName; + } + catch (FileNotFoundException e) { + throw new MessageDeliveryException(message, "File [" + inputStreamHolder.getName() + + "] not found in local working directory; it was moved or deleted unexpectedly.", e); + } + catch (IOException e) { + throw new MessageDeliveryException(message, "Failed to transfer file [" + + inputStreamHolder.getName() + " -> " + fileName + + "] from local directory to remote directory.", e); + } + catch (Exception e) { + throw new MessageDeliveryException(message, "Error handling message for file [" + + inputStreamHolder.getName() + " -> " + fileName + "]", e); } }); } @@ -342,24 +343,12 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ @Override public boolean exists(final String path) { - return this.execute(new SessionCallback() { - - @Override - public Boolean doInSession(Session session) throws IOException { - return session.exists(path); - } - }); + return execute(session -> session.exists(path)); } @Override public boolean remove(final String path) { - return this.execute(new SessionCallback() { - - @Override - public Boolean doInSession(Session session) throws IOException { - return session.remove(path); - } - }); + return execute(session -> session.remove(path)); } @Override @@ -367,10 +356,7 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ Assert.hasText(fromPath, "Old filename cannot be null or empty"); Assert.hasText(toPath, "New filename cannot be null or empty"); - this.execute(new SessionCallbackWithoutResult() { - - @Override - public void doInSessionWithoutResult(Session session) throws IOException { + this.execute((SessionCallbackWithoutResult) session -> { int lastSeparator = toPath.lastIndexOf(RemoteFileTemplate.this.remoteFileSeparator); if (lastSeparator > 0) { String remoteFileDirectory = toPath.substring(0, lastSeparator + 1); @@ -378,7 +364,6 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ RemoteFileTemplate.this.remoteFileSeparator, RemoteFileTemplate.this.logger); } session.rename(fromPath, toPath); - } }); } @@ -395,29 +380,18 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ @Override public boolean get(final String remotePath, final InputStreamCallback callback) { Assert.notNull(remotePath, "'remotePath' cannot be null"); - return this.execute(new SessionCallback() { - - @Override - public Boolean doInSession(Session session) throws IOException { - InputStream inputStream = session.readRaw(remotePath); - callback.doWithInputStream(inputStream); - inputStream.close(); - return session.finalizeRaw(); - } + return this.execute(session -> { + InputStream inputStream = session.readRaw(remotePath); + callback.doWithInputStream(inputStream); + inputStream.close(); + return session.finalizeRaw(); }); } @Override - public F[] list(final String path) { - return this.execute(new SessionCallback() { - - @Override - public F[] doInSession(Session session) throws IOException { - return session.list(path); - } - - }); + public F[] list(String path) { + return execute(session -> session.list(path)); } @Override @@ -425,7 +399,6 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ return this.sessionFactory.getSession(); } - @SuppressWarnings("rawtypes") @Override public T execute(SessionCallback callback) { Session session = null; diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallback.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallback.java index 187284dcfe..036a144f3e 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallback.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallback.java @@ -28,6 +28,7 @@ import org.springframework.integration.file.remote.session.Session; * @since 3.0 * */ +@FunctionalInterface public interface SessionCallback { /** diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallbackWithoutResult.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallbackWithoutResult.java index d80da5b332..96861c57a3 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallbackWithoutResult.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/SessionCallbackWithoutResult.java @@ -25,13 +25,15 @@ import org.springframework.integration.file.remote.session.Session; * no result is returned. * * @author Gary Russell + * @author Artem Bilan * @since 3.0 * */ -public abstract class SessionCallbackWithoutResult implements SessionCallback { +@FunctionalInterface +public interface SessionCallbackWithoutResult extends SessionCallback { @Override - public Object doInSession(Session session) throws IOException { + default Object doInSession(Session session) throws IOException { doInSessionWithoutResult(session); return null; } @@ -40,10 +42,9 @@ public abstract class SessionCallbackWithoutResult implements SessionCallback * Called within the context of a session. * Perform some operation(s) on the session. The caller will take * care of closing the session after this method exits. - * * @param session The session. * @throws IOException Any IOException. */ - protected abstract void doInSessionWithoutResult(Session session) throws IOException; + void doInSessionWithoutResult(Session session) throws IOException; } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java index 85766d1a19..edda4f7aa2 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java @@ -62,7 +62,7 @@ public class FileTransferringMessageHandler extends AbstractMessageHandler { /** - * @param autoCreateDirectory true to automatically create the direcotory. + * @param autoCreateDirectory true to automatically create the directory. * @see RemoteFileTemplate#setAutoCreateDirectory(boolean) */ public void setAutoCreateDirectory(boolean autoCreateDirectory) { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactory.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactory.java index 7703d196f2..19192c899f 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactory.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactory.java @@ -22,6 +22,7 @@ package org.springframework.integration.file.remote.session; * @author Mark Fisher * @since 2.0 */ +@FunctionalInterface public interface SessionFactory { Session getSession(); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactoryLocator.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactoryLocator.java index c64b9ded22..0b73420870 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactoryLocator.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/SessionFactoryLocator.java @@ -24,6 +24,7 @@ package org.springframework.integration.file.remote.session; * @since 4.2 * */ +@FunctionalInterface public interface SessionFactoryLocator { /** diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpRemoteFileTemplate.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpRemoteFileTemplate.java index 5351345bd1..16f7af235b 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpRemoteFileTemplate.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpRemoteFileTemplate.java @@ -23,8 +23,6 @@ import org.apache.commons.net.ftp.FTPFile; import org.springframework.integration.file.remote.ClientCallback; import org.springframework.integration.file.remote.RemoteFileTemplate; -import org.springframework.integration.file.remote.SessionCallback; -import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; @@ -67,13 +65,7 @@ public class FtpRemoteFileTemplate extends RemoteFileTemplate { } protected T doExecuteWithClient(final ClientCallback callback) { - return execute(new SessionCallback() { - - @Override - public T doInSession(Session session) throws IOException { - return callback.doWithClient((FTPClient) session.getClientInstance()); - } - }); + return execute(session -> callback.doWithClient((FTPClient) session.getClientInstance())); } /** diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java index 678d89e03a..b3c6ea37ef 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/GroovyControlBusFactoryBean.java @@ -29,10 +29,8 @@ import org.springframework.core.annotation.AnnotationUtils; import org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean; import org.springframework.integration.groovy.GroovyCommandMessageProcessor; import org.springframework.integration.handler.ServiceActivatingHandler; -import org.springframework.integration.scripting.ScriptVariableGenerator; import org.springframework.integration.support.management.IntegrationManagedResource; import org.springframework.jmx.export.annotation.ManagedResource; -import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.scripting.groovy.GroovyObjectCustomizer; import org.springframework.util.CustomizableThreadCreator; @@ -51,7 +49,8 @@ import groovy.lang.MissingPropertyException; * @author Gary Russell * @since 2.0 */ -public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFactoryBean implements BeanClassLoaderAware { +public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFactoryBean + implements BeanClassLoaderAware { private volatile Long sendTimeout; @@ -75,15 +74,11 @@ public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFac @Override protected MessageHandler createHandler() { Binding binding = new ManagedBeansBinding(this.getBeanFactory()); - GroovyCommandMessageProcessor processor = new GroovyCommandMessageProcessor(binding, new ScriptVariableGenerator() { - - @Override - public Map generateScriptVariables(Message message) { - Map variables = new HashMap(); - variables.put("headers", message.getHeaders()); - return variables; - } - + GroovyCommandMessageProcessor processor = new GroovyCommandMessageProcessor(binding, + message -> { + Map variables = new HashMap<>(); + variables.put("headers", message.getHeaders()); + return variables; }); if (this.customizer != null) { processor.setCustomizer(this.customizer); @@ -147,7 +142,8 @@ public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFac (AnnotationUtils.findAnnotation(bean.getClass(), IntegrationManagedResource.class) != null)) { return bean; } - throw new BeanCreationNotAllowedException(name, "Only beans with @ManagedResource or beans which implement " + + throw new BeanCreationNotAllowedException(name, + "Only beans with @ManagedResource or beans which implement " + "org.springframework.context.Lifecycle or org.springframework.util.CustomizableThreadCreator " + "are allowed to use as ControlBus components."); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpListener.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpListener.java index 25c46bde17..4a8415b866 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpListener.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpListener.java @@ -26,6 +26,7 @@ import org.springframework.messaging.Message; * @since 2.0 * */ +@FunctionalInterface public interface TcpListener { /** diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/MessagePreparedStatementSetter.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/MessagePreparedStatementSetter.java index 999d31c1fc..cb3135458e 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/MessagePreparedStatementSetter.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/MessagePreparedStatementSetter.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 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. @@ -34,6 +34,7 @@ import org.springframework.messaging.Message; * @since 4.2 * @see PreparedStatementSetter */ +@FunctionalInterface public interface MessagePreparedStatementSetter { void setValues(PreparedStatement ps, Message requestMessage) throws SQLException; diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/SqlParameterSourceFactory.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/SqlParameterSourceFactory.java index e1e4049f0d..49daaf9577 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/SqlParameterSourceFactory.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/SqlParameterSourceFactory.java @@ -25,6 +25,7 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; * @author Jonas Partner * @since 2.0 */ +@FunctionalInterface public interface SqlParameterSourceFactory { /** diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanAttributeFilter.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanAttributeFilter.java index 6e5a506465..01a048c431 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanAttributeFilter.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanAttributeFilter.java @@ -23,6 +23,7 @@ import javax.management.ObjectName; * @since 3.0 * */ +@FunctionalInterface public interface MBeanAttributeFilter { /** diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanObjectConverter.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanObjectConverter.java index 2a6356d291..4d88ca3239 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanObjectConverter.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/MBeanObjectConverter.java @@ -25,6 +25,7 @@ import javax.management.ObjectInstance; * @since 3.0 * */ +@FunctionalInterface public interface MBeanObjectConverter { /** diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java index 99914d5738..6601fd3dac 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/SearchTermStrategy.java @@ -29,6 +29,7 @@ import javax.mail.search.SearchTerm; * @since 2.2 * */ +@FunctionalInterface public interface SearchTermStrategy { /** diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ArgumentsStrategy.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ArgumentsStrategy.java index f91e097282..4836665c64 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ArgumentsStrategy.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ArgumentsStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 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. @@ -22,6 +22,7 @@ import org.springframework.messaging.Message; * @author Artem Bilan * @since 4.0 */ +@FunctionalInterface public interface ArgumentsStrategy { Object[] resolve(String command, Message message); diff --git a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutor.java b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutor.java index 9509f2e644..b110bc05f0 100644 --- a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutor.java +++ b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutor.java @@ -22,15 +22,19 @@ import org.springframework.scripting.ScriptSource; /** * @author David Turanski + * @author Artem Bilan * @since 2.1 */ +@FunctionalInterface public interface ScriptExecutor { /** * @param scriptSource The script source. * @return The result of the execution. */ - Object executeScript(ScriptSource scriptSource); + default Object executeScript(ScriptSource scriptSource) { + return executeScript(scriptSource, null); + } /** * @param scriptSource The script source. diff --git a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptVariableGenerator.java b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptVariableGenerator.java index 8c108c08e7..3eeec26531 100644 --- a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptVariableGenerator.java +++ b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptVariableGenerator.java @@ -27,6 +27,7 @@ import org.springframework.messaging.Message; * @author Oleg Zhurakousky * @since 2.0.2 */ +@FunctionalInterface public interface ScriptVariableGenerator { Map generateScriptVariables(Message message); diff --git a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java index 470765f545..1b7974081e 100644 --- a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java +++ b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java @@ -60,11 +60,6 @@ public abstract class AbstractScriptExecutor implements ScriptExecutor { } } - @Override - public Object executeScript(ScriptSource scriptSource) { - return this.executeScript(scriptSource, null); - } - @Override public Object executeScript(ScriptSource scriptSource, Map variables) { Object result; diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java index f39473dfb5..ae826754f0 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java @@ -141,18 +141,13 @@ public class SftpOutboundGateway extends AbstractRemoteFileOutboundGateway remoteFileTemplate, final String path, final int chmod) { - remoteFileTemplate.executeWithClient(new ClientCallbackWithoutResult() { - - @Override - protected void doWithClientWithoutResult(ChannelSftp client) { + remoteFileTemplate.executeWithClient((ClientCallbackWithoutResult) client -> { try { client.chmod(chmod, path); } catch (SftpException e) { throw new GeneralSftpException("Failed to execute chmod", e); } - } - }); } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/outbound/SftpMessageHandler.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/outbound/SftpMessageHandler.java index 0936bbbad2..0f0898aa61 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/outbound/SftpMessageHandler.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/outbound/SftpMessageHandler.java @@ -73,18 +73,13 @@ public class SftpMessageHandler extends FileTransferringMessageHandler @Override protected void doChmod(RemoteFileTemplate remoteFileTemplate, final String path, final int chmod) { - remoteFileTemplate.executeWithClient(new ClientCallbackWithoutResult() { - - @Override - protected void doWithClientWithoutResult(ChannelSftp client) { - try { - client.chmod(chmod, path); - } - catch (SftpException e) { - throw new GeneralSftpException("Failed to execute chmod", e); - } + remoteFileTemplate.executeWithClient((ClientCallbackWithoutResult) client -> { + try { + client.chmod(chmod, path); + } + catch (SftpException e) { + throw new GeneralSftpException("Failed to execute chmod", e); } - }); } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpRemoteFileTemplate.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpRemoteFileTemplate.java index 399d2878be..eb0ca24d6f 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpRemoteFileTemplate.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpRemoteFileTemplate.java @@ -16,12 +16,8 @@ package org.springframework.integration.sftp.session; -import java.io.IOException; - import org.springframework.integration.file.remote.ClientCallback; import org.springframework.integration.file.remote.RemoteFileTemplate; -import org.springframework.integration.file.remote.SessionCallback; -import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.remote.session.SessionFactory; import com.jcraft.jsch.ChannelSftp; @@ -48,13 +44,7 @@ public class SftpRemoteFileTemplate extends RemoteFileTemplate { } protected T doExecuteWithClient(final ClientCallback callback) { - return execute(new SessionCallback() { - - @Override - public T doInSession(Session session) throws IOException { - return callback.doWithClient((ChannelSftp) session.getClientInstance()); - } - }); + return execute(session -> callback.doWithClient((ChannelSftp) session.getClientInstance())); } } diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java index 7369a4e64f..b777a02e96 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/MessageConverter.java @@ -26,6 +26,7 @@ import org.springframework.messaging.Message; * @since 3.0 * */ +@FunctionalInterface public interface MessageConverter { Message fromSyslog(Message syslog) throws Exception; diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java index e3922aa160..8d44fd109c 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java @@ -41,7 +41,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.springframework.integration.splitter.AbstractMessageSplitter; -import org.springframework.integration.util.Function; import org.springframework.integration.util.FunctionIterator; import org.springframework.integration.xml.DefaultXmlPayloadConverter; import org.springframework.integration.xml.XmlPayloadConverter; @@ -210,20 +209,15 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { return splitStrings; } else { - return new FunctionIterator((Iterator) nodes, new Function() { - - @Override - public String apply(Node node) { - StringResult result = new StringResult(); - try { - transformer.transform(new DOMSource(node), result); - } - catch (TransformerException e) { - throw new IllegalStateException("failed to create DocumentBuilder", e); - } - return result.toString(); + return new FunctionIterator<>((Iterator) nodes, node -> { + StringResult result = new StringResult(); + try { + transformer.transform(new DOMSource(node), result); } - + catch (TransformerException e) { + throw new IllegalStateException("failed to create DocumentBuilder", e); + } + return result.toString(); }); } }