INT-1747 added support for Executor to RessubmittingTask

This commit is contained in:
Oleg Zhurakousky
2011-01-19 13:33:04 -05:00
parent 2993f95c52
commit 7aa464c086
2 changed files with 22 additions and 3 deletions

View File

@@ -27,6 +27,7 @@ import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.integration.endpoint.MessageProducerSupport;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.scheduling.TaskScheduler;
@@ -62,8 +63,6 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
Assert.notNull(mailReceiver, "mailReceiver must not be null");
this.mailReceiver = mailReceiver;
}
/**
* Specify whether the IDLE task should reconnect automatically after
* catching a {@link FolderClosedException} while waiting for messages.
@@ -86,7 +85,6 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
logger.warn("error occurred in idle task", e);
}
}
/*
* Lifecycle implementation
*/
@@ -95,6 +93,8 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport {
protected void doStart() {
TaskScheduler scheduler = this.getTaskScheduler();
Assert.notNull(scheduler, "'taskScheduler' must not be null" );
ResubmittingTask task = new ResubmittingTask(this.idleTask, scheduler, reconnectDelay);
task.setTaskExecutor(taskExecutor);
scheduledFuture = scheduler.schedule(new ResubmittingTask(this.idleTask, scheduler, reconnectDelay), new Date());
}

View File

@@ -17,6 +17,7 @@ package org.springframework.integration.mail;
import java.security.ProviderException;
import java.util.Date;
import java.util.concurrent.Executor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -34,14 +35,32 @@ class ResubmittingTask implements Runnable {
private final Runnable targetTask;
private final TaskScheduler scheduler;
private final long delay;
private Executor taskExecutor;
public ResubmittingTask(Runnable targetTask, TaskScheduler scheduler, long delay) {
this.targetTask = targetTask;
this.scheduler = scheduler;
this.delay = delay;
}
public void setTaskExecutor(Executor taskExecutor) {
this.taskExecutor = taskExecutor;
}
public void run() {
if (taskExecutor != null){
taskExecutor.execute(new Runnable() {
public void run() {
ResubmittingTask.this.invokeTask();
}
});
}
else {
this.invokeTask();
}
}
private void invokeTask(){
try {
targetTask.run();
logger.debug("Task completed successfully. Re-scheduling it again right away");