Skip to content

Commit 6218694

Browse files
committed
spring-projectsGH-8577: Deprecate ImapIdleCA.sendingTaskExecutor
Fixes spring-projects#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
1 parent 482a466 commit 6218694

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapIdleChannelAdapter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222
import java.util.concurrent.Executor;
2323
import java.util.concurrent.ExecutorService;
24-
import java.util.concurrent.Executors;
2524
import java.util.concurrent.ScheduledFuture;
2625

2726
import jakarta.mail.Folder;
@@ -33,6 +32,7 @@
3332
import org.springframework.beans.factory.BeanClassLoaderAware;
3433
import org.springframework.context.ApplicationEventPublisher;
3534
import org.springframework.context.ApplicationEventPublisherAware;
35+
import org.springframework.core.task.SyncTaskExecutor;
3636
import org.springframework.integration.endpoint.MessageProducerSupport;
3737
import org.springframework.integration.mail.event.MailIntegrationEvent;
3838
import org.springframework.integration.transaction.IntegrationResourceHolder;
@@ -78,7 +78,7 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport implements Be
7878

7979
private boolean shouldReconnectAutomatically = true;
8080

81-
private Executor sendingTaskExecutor = Executors.newFixedThreadPool(1);
81+
private Executor sendingTaskExecutor = new SyncTaskExecutor();
8282

8383
private boolean sendingTaskExecutorSet;
8484

@@ -107,7 +107,10 @@ public void setAdviceChain(List<Advice> adviceChain) {
107107
* Specify an {@link Executor} used to send messages received by the
108108
* adapter.
109109
* @param sendingTaskExecutor the sendingTaskExecutor to set
110+
* @deprecated since 6.0.5 in favor of async hands-off downstream in the flow,
111+
* e.g. {@link org.springframework.integration.channel.ExecutorChannel}.
110112
*/
113+
@Deprecated(since = "6.0.5", forRemoval = true)
111114
public void setSendingTaskExecutor(Executor sendingTaskExecutor) {
112115
Assert.notNull(sendingTaskExecutor, "'sendingTaskExecutor' must not be null");
113116
this.sendingTaskExecutor = sendingTaskExecutor;

spring-integration-mail/src/main/java/org/springframework/integration/mail/dsl/ImapIdleChannelAdapterSpec.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -352,8 +352,11 @@ public ImapIdleChannelAdapterSpec transactional() {
352352
* Specify a task executor to be used to send messages to the downstream flow.
353353
* @param sendingTaskExecutor the sendingTaskExecutor.
354354
* @return the spec.
355-
* @see ImapIdleChannelAdapter#setSendingTaskExecutor(Executor)
355+
* @deprecated since 6.1 in favor of async hands-off downstream in the flow,
356+
* e.g. {@link org.springframework.integration.channel.ExecutorChannel}.
356357
*/
358+
@Deprecated(since = "6.0.5", forRemoval = true)
359+
@SuppressWarnings("removal")
357360
public ImapIdleChannelAdapterSpec sendingTaskExecutor(Executor sendingTaskExecutor) {
358361
this.target.setSendingTaskExecutor(sendingTaskExecutor);
359362
return this;

spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail.xsd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,11 @@
167167
<xsd:attribute name="task-executor" type="xsd:string">
168168
<xsd:annotation>
169169
<xsd:documentation><![CDATA[
170-
Reference to a bean that implements
170+
[DEPRECATED] Reference to a bean that implements
171171
org.springframework.core.task.TaskExecutor which is used
172172
to send Messages received by this adapter.
173173
If not provided, the adapter uses a single-threaded executor.
174+
Deprecated since 6.0.5 in favor of async hand-off downstream in the flow.
174175
]]></xsd:documentation>
175176
<xsd:appinfo>
176177
<tool:annotation kind="ref">

spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns:task="http://www.springframework.org/schema/task"
54
xmlns:util="http://www.springframework.org/schema/util"
65
xmlns:context="http://www.springframework.org/schema/context"
76
xmlns:mail="http://www.springframework.org/schema/integration/mail"
87
xmlns:integration="http://www.springframework.org/schema/integration"
98
xsi:schemaLocation="http://www.springframework.org/schema/beans
109
https://www.springframework.org/schema/beans/spring-beans.xsd
11-
http://www.springframework.org/schema/task
12-
https://www.springframework.org/schema/task/spring-task.xsd
1310
http://www.springframework.org/schema/context
1411
https://www.springframework.org/schema/context/spring-context.xsd
1512
http://www.springframework.org/schema/util
@@ -78,8 +75,7 @@
7875
store-uri="imap:foo"
7976
channel="channel"
8077
auto-startup="false"
81-
should-delete-messages="true"
82-
task-executor="executor">
78+
should-delete-messages="true">
8379
<mail:transactional synchronization-factory="syncFactory" />
8480
</mail:imap-idle-channel-adapter>
8581

@@ -95,8 +91,6 @@
9591
<prop key="foo">bar</prop>
9692
</util:properties>
9793

98-
<task:executor id="executor" pool-size="5"/>
99-
10094
<mail:imap-idle-channel-adapter
10195
id="autoChannel"
10296
store-uri="imap:foo"

spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -194,7 +194,6 @@ public void transactionalAdapter() {
194194
assertThat(receiverAccessor.getPropertyValue("shouldDeleteMessages")).isEqualTo(Boolean.TRUE);
195195
assertThat(receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead")).isEqualTo(Boolean.TRUE);
196196
assertThat(adapterAccessor.getPropertyValue("errorChannel")).isNull();
197-
assertThat(adapterAccessor.getPropertyValue("sendingTaskExecutor")).isEqualTo(context.getBean("executor"));
198197
assertThat(adapterAccessor.getPropertyValue("adviceChain")).isNotNull();
199198
}
200199

src/reference/asciidoc/mail.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ In this case, the only header populated is the mentioned above `IntegrationMessa
143143
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.
144144
In this case there is nothing to produce downstream for possible logic around `IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE` header.
145145

146+
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.
147+
146148
[[mail-mapping]]
147149
=== Inbound Mail Message Mapping
148150

0 commit comments

Comments
 (0)