INT-845 added StartupMode enum since polling consumers must not start as eagerly as event-driven consumers subscribe to their input channels
This commit is contained in:
@@ -41,6 +41,8 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
|
||||
private final IdleTask idleTask = new IdleTask();
|
||||
|
||||
private volatile boolean autoStartup = true;
|
||||
|
||||
private volatile boolean shouldReconnectAutomatically = true;
|
||||
|
||||
private volatile TaskExecutor taskExecutor;
|
||||
@@ -63,6 +65,10 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
this.shouldReconnectAutomatically = shouldReconnectAutomatically;
|
||||
}
|
||||
|
||||
public void setAutoStartup(boolean autoStartup) {
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
|
||||
public void setTaskExecutor(TaskExecutor taskExecutor) {
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
@@ -73,6 +79,16 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() {
|
||||
if (this.autoStartup) {
|
||||
this.setStartupMode(StartupMode.ON_CONTEXT_REFRESH);
|
||||
}
|
||||
else {
|
||||
this.setStartupMode(StartupMode.MANUAL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Lifecycle implementation
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint.StartupMode;
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.integration.mail.MailReceivingMessageSource;
|
||||
import org.springframework.integration.mail.Pop3MailReceiver;
|
||||
@@ -52,7 +53,7 @@ public class PollingMailSourceParserTests {
|
||||
Object adapter = context.getBean("imapAdapter");
|
||||
assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
|
||||
assertEquals(StartupMode.MANUAL, adapterAccessor.getPropertyValue("startupMode"));
|
||||
Object channel = context.getBean("channel");
|
||||
assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Object source = adapterAccessor.getPropertyValue("source");
|
||||
@@ -71,7 +72,7 @@ public class PollingMailSourceParserTests {
|
||||
Object adapter = context.getBean("pop3Adapter");
|
||||
assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
|
||||
assertEquals(StartupMode.MANUAL, adapterAccessor.getPropertyValue("startupMode"));
|
||||
Object channel = context.getBean("channel");
|
||||
assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Object source = adapterAccessor.getPropertyValue("source");
|
||||
|
||||
Reference in New Issue
Block a user