From 62186945d63e41c6ff44cb7021a448e4ef26bf4b Mon Sep 17 00:00:00 2001 From: abilan Date: Tue, 28 Mar 2023 16:10:12 -0400 Subject: [PATCH 1/2] GH-8577: Deprecate ImapIdleCA.sendingTaskExecutor Fixes https://github.com/spring-projects/spring-integration/issues/8577 When we process mail messages in async manner, it is possible that we end up in a race condition situation where the next idle cycle closes the folder. It is possible to reopen the folder, but feels better to block the current idle cycle until we are done with the message and therefore keep folder opened. * Deprecate `ImapIdleChannelAdapter.sendingTaskExecutor` in favor of an `ExecutorChannel` as an output for this channel adapter or similar async hand-off downstream. * Make a default one as a `SyncTaskExecutor` to make a sense of this deprecation --- .../integration/mail/ImapIdleChannelAdapter.java | 9 ++++++--- .../integration/mail/dsl/ImapIdleChannelAdapterSpec.java | 7 +++++-- .../integration/mail/config/spring-integration-mail.xsd | 3 ++- .../config/ImapIdleChannelAdapterParserTests-context.xml | 8 +------- .../mail/config/ImapIdleChannelAdapterParserTests.java | 3 +-- src/reference/asciidoc/mail.adoc | 2 ++ 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java index b9ad5cc4f1e..a274d1c5eea 100755 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -21,7 +21,6 @@ import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.ScheduledFuture; import jakarta.mail.Folder; @@ -33,6 +32,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.core.task.SyncTaskExecutor; import org.springframework.integration.endpoint.MessageProducerSupport; import org.springframework.integration.mail.event.MailIntegrationEvent; import org.springframework.integration.transaction.IntegrationResourceHolder; @@ -78,7 +78,7 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport implements Be private boolean shouldReconnectAutomatically = true; - private Executor sendingTaskExecutor = Executors.newFixedThreadPool(1); + private Executor sendingTaskExecutor = new SyncTaskExecutor(); private boolean sendingTaskExecutorSet; @@ -107,7 +107,10 @@ public void setAdviceChain(List adviceChain) { * Specify an {@link Executor} used to send messages received by the * adapter. * @param sendingTaskExecutor the sendingTaskExecutor to set + * @deprecated since 6.0.5 in favor of async hands-off downstream in the flow, + * e.g. {@link org.springframework.integration.channel.ExecutorChannel}. */ + @Deprecated(since = "6.0.5", forRemoval = true) public void setSendingTaskExecutor(Executor sendingTaskExecutor) { Assert.notNull(sendingTaskExecutor, "'sendingTaskExecutor' must not be null"); this.sendingTaskExecutor = sendingTaskExecutor; diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/ImapIdleChannelAdapterSpec.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/ImapIdleChannelAdapterSpec.java index 5f256d35b3f..e9b14f93b4f 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/ImapIdleChannelAdapterSpec.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/ImapIdleChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 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. @@ -352,8 +352,11 @@ public ImapIdleChannelAdapterSpec transactional() { * Specify a task executor to be used to send messages to the downstream flow. * @param sendingTaskExecutor the sendingTaskExecutor. * @return the spec. - * @see ImapIdleChannelAdapter#setSendingTaskExecutor(Executor) + * @deprecated since 6.1 in favor of async hands-off downstream in the flow, + * e.g. {@link org.springframework.integration.channel.ExecutorChannel}. */ + @Deprecated(since = "6.0.5", forRemoval = true) + @SuppressWarnings("removal") public ImapIdleChannelAdapterSpec sendingTaskExecutor(Executor sendingTaskExecutor) { this.target.setSendingTaskExecutor(sendingTaskExecutor); return this; diff --git a/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail.xsd b/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail.xsd index 8ef3ea2ae60..009b0aabf93 100644 --- a/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail.xsd +++ b/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail.xsd @@ -167,10 +167,11 @@ diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml index b385e0ae8cf..98c1f45c93b 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml @@ -1,15 +1,12 @@ + should-delete-messages="true"> @@ -95,8 +91,6 @@ bar - - Date: Tue, 28 Mar 2023 16:17:04 -0400 Subject: [PATCH 2/2] Fix language in docs Co-authored-by: Gary Russell --- src/reference/asciidoc/mail.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reference/asciidoc/mail.adoc b/src/reference/asciidoc/mail.adoc index 5a083b8a7e7..350c3dea9e3 100644 --- a/src/reference/asciidoc/mail.adoc +++ b/src/reference/asciidoc/mail.adoc @@ -143,7 +143,7 @@ In this case, the only header populated is the mentioned above `IntegrationMessa Starting with version 5.5.11, the folder is closed automatically after `AbstractMailReceiver.receive()` if no messages received or all of them are filtered out independently of the `autoCloseFolder` flag. In this case there is nothing to produce downstream for possible logic around `IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE` header. -Starting with version 6.0.5, an `ImapIdleChannelAdapter.sendingTaskExecutor` option is deprecated in favor of an asynchronous message handling in downstream flow, e.g. via an `ExecutorChannel` as an output channel of this channel adapter. +Starting with version 6.0.5, the `ImapIdleChannelAdapter.sendingTaskExecutor` option is deprecated in favor of using asynchronous message handling in the downstream flow, e.g. via an `ExecutorChannel` as the output channel of this channel adapter. [[mail-mapping]] === Inbound Mail Message Mapping