The TaskScheduler for the MessageBus is now created in MessageBusParser if no explicit reference has been provided via the "task-executor" attribute of the <message-bus/> element. The configuration of an asynchronous ApplicationEventMulticaster has also been pushed to the parser rather than being contained within the MessageBus implementation.

This commit is contained in:
Mark Fisher
2008-10-09 13:45:07 +00:00
parent 977596272c
commit 49361dba5c
15 changed files with 161 additions and 146 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.integration.mail;
import java.util.Date;
import javax.mail.Message;
import org.apache.commons.logging.Log;
@@ -23,10 +25,10 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.Lifecycle;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.endpoint.AbstractMessageProducingEndpoint;
import org.springframework.integration.mail.monitor.AsyncMonitoringStrategy;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.scheduling.Trigger;
import org.springframework.util.Assert;
/**
@@ -46,8 +48,6 @@ public class ListeningMailSource extends AbstractMessageProducingEndpoint implem
private volatile boolean monitorRunning = false;
private volatile TaskExecutor taskExecutor;
public ListeningMailSource(FolderConnection folderConnection) {
Assert.notNull(folderConnection, "FolderConnection must not be null");
@@ -55,10 +55,6 @@ public class ListeningMailSource extends AbstractMessageProducingEndpoint implem
}
public void setTaskExecutor(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
}
// Lifecycle implementation
public boolean isRunning() {
@@ -82,11 +78,14 @@ public class ListeningMailSource extends AbstractMessageProducingEndpoint implem
protected void startMonitor() {
synchronized (this.monitorRunnable) {
if (!this.monitorRunning) {
if (this.taskExecutor == null) {
this.taskExecutor = this.getTaskScheduler();
}
Assert.state(this.taskExecutor != null, "TaskExecutor is required");
this.taskExecutor.execute(this.monitorRunnable);
Assert.state(this.getTaskScheduler() != null, "TaskScheduler is required");
this.getTaskScheduler().schedule(this.monitorRunnable,
new Trigger() {
public Date getNextRunTime(Date lastScheduledRunTime, Date lastCompleteTime) {
return new Date();
}
}
);
}
this.monitorRunning = true;
}
@@ -119,7 +118,12 @@ public class ListeningMailSource extends AbstractMessageProducingEndpoint implem
public synchronized void interrupt() {
this.thread.interrupt();
if (this.thread != null) {
this.thread.interrupt();
}
else if (logger.isInfoEnabled()) {
logger.info("monitor is not running, cannot interrupt");
}
}
public void run() {

View File

@@ -24,41 +24,35 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import javax.mail.internet.MimeMessage;
import org.easymock.classextension.EasyMock;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.message.Message;
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
import org.springframework.integration.scheduling.TaskScheduler;
import org.springframework.integration.util.TestUtils;
/**
* @author Jonas Partner
*/
public class SubscribableMailSourceTests {
private TaskExecutor executor;
@Before
public void setUp() {
executor = new ConcurrentTaskExecutor();
}
@Test
public void testReceive() throws Exception {
javax.mail.Message message = EasyMock.createMock(MimeMessage.class);
StubFolderConnection folderConnection = new StubFolderConnection(message);
QueueChannel channel = new QueueChannel();
TaskScheduler scheduler = TestUtils.createTaskScheduler(5);
scheduler.start();
ListeningMailSource mailSource = new ListeningMailSource(folderConnection);
mailSource.setTaskExecutor(executor);
mailSource.setTaskScheduler(scheduler);
mailSource.setOutputChannel(channel);
mailSource.start();
Message<?> result = channel.receive(1000);
mailSource.stop();
assertNotNull(result);
assertEquals("Wrong payload", message, result.getPayload());
mailSource.stop();
scheduler.stop();
}