From 9ffc2db9f59ac76bb5ef996361152d3bb399920c Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 29 Mar 2023 09:49:59 -0400 Subject: [PATCH] GH-8577: Deprecate ImapIdleCA.sendingTaskExecutor (#8589) * 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 * Fix language in docs Co-authored-by: Gary Russell --------- Co-authored-by: Gary Russell --- .../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 b9ad5cc4f1..a274d1c5ee 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.time.Instant; 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.aop.framework.ProxyFactory; 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 class ImapIdleChannelAdapter extends MessageProducerSupport implements Be * 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 5f256d35b3..e9b14f93b4 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 class ImapIdleChannelAdapterSpec * 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 8ef3ea2ae6..009b0aabf9 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 b385e0ae8c..98c1f45c93 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 - -