From f5fe67ad671bfb1134bcb746e8c6c5cb91d3c711 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 30 Sep 2011 16:30:04 -0400 Subject: [PATCH] INT-2100 addressed PR comments --- .../mail/ImapIdleChannelAdapter.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 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 580dd4cbe6..f7150bdcf5 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 @@ -28,8 +28,8 @@ import javax.mail.internet.MimeMessage; import org.springframework.integration.endpoint.MessageProducerSupport; import org.springframework.integration.support.MessageBuilder; import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.Trigger; import org.springframework.scheduling.TriggerContext; -import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.util.Assert; /** @@ -59,7 +59,7 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport { private volatile long connectionPingInterval = 10000; - private final ExceptionAwarePeriodicTrigger receivingTaskTrigger = new ExceptionAwarePeriodicTrigger(0); + private final ExceptionAwarePeriodicTrigger receivingTaskTrigger = new ExceptionAwarePeriodicTrigger(); public ImapIdleChannelAdapter(ImapMailReceiver mailReceiver) { @@ -119,7 +119,7 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport { } catch (Exception e) { //run again after a delay logger.warn("Failed to execute IDLE task. Will attempt to resubmit in " + reconnectDelay + " milliseconds.", e); - receivingTaskTrigger.delay(); + receivingTaskTrigger.delayNextExecution(); } } } @@ -177,26 +177,23 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport { } } - private class ExceptionAwarePeriodicTrigger extends PeriodicTrigger { + private class ExceptionAwarePeriodicTrigger implements Trigger { - private volatile boolean delay; + private volatile boolean delayNextExecution; - public ExceptionAwarePeriodicTrigger(long period) { - super(period); - } public Date nextExecutionTime(TriggerContext triggerContext) { - if (delay){ - delay = false; + if (delayNextExecution){ + delayNextExecution = false; return new Date(System.currentTimeMillis() + reconnectDelay); } else { - return super.nextExecutionTime(triggerContext); + return new Date(System.currentTimeMillis()); } } - public void delay() { - this.delay = true; + public void delayNextExecution() { + this.delayNextExecution = true; } }