Split MessageSource types into 2 sub-interfaces: PollableSource and SubscribableSource. The MessageChannel hierarchy has also been revised accordingly. DirectChannel and PublishSubscribeChannel are now SubscribableSources, while the other queue-based channels are PollableSources. The PollableChannel interface extends BlockingSource which in turn is an extension of PollableSource that adds timeout-aware methods.
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -24,24 +23,21 @@ import java.util.Map;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageDeliveryAware;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Base class for implementing a Source that creates messages from files in a
|
||||
* directory, either local or remote.
|
||||
* Base class for implementing a PollableSource that creates messages
|
||||
* from files in a directory, either local or remote.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author iwein
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public abstract class AbstractDirectorySource<T> implements MessageSource<T>, MessageDeliveryAware {
|
||||
public abstract class AbstractDirectorySource<T> implements PollableSource<T>, MessageDeliveryAware {
|
||||
|
||||
public final static String FILE_INFO_PROPERTY = "file.info";
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -31,7 +32,6 @@ import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageDeliveryAware;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileSource extends AbstractDirectorySource<File> implements MessageSource<File>, MessageDeliveryAware {
|
||||
public class FileSource extends AbstractDirectorySource<File> implements MessageDeliveryAware {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import javax.jms.Destination;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ import org.springframework.jms.core.JmsTemplate;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsSource extends AbstractJmsTemplateBasedAdapter implements MessageSource<Object> {
|
||||
public class JmsSource extends AbstractJmsTemplateBasedAdapter implements PollableSource<Object> {
|
||||
|
||||
public JmsSource(JmsTemplate jmsTemplate) {
|
||||
super(jmsTemplate);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.adapter.mail.monitor.DefaultLocalMailMessageStore;
|
||||
@@ -34,20 +35,19 @@ import org.springframework.integration.adapter.mail.monitor.LocalMailMessageStor
|
||||
import org.springframework.integration.adapter.mail.monitor.MailTransportUtils;
|
||||
import org.springframework.integration.adapter.mail.monitor.MonitoringStrategy;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link MessageSource} implementation which delegates to a
|
||||
* {@link MonitoringStrategy} to poll a mailbox Each poll of the mailbox may
|
||||
* {@link MonitoringStrategy} to poll a mailbox. Each poll of the mailbox may
|
||||
* return more than one message which will then be stored locally using the
|
||||
* provided {@link LocalMailMessageStore}
|
||||
* @author Jonas Partner
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PollingMailSource implements MessageSource, DisposableBean, Lifecycle {
|
||||
public class PollingMailSource implements PollableSource, DisposableBean, Lifecycle {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ import java.io.InputStream;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
|
||||
/**
|
||||
* A pollable source for receiving bytes from an {@link InputStream}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamSource implements MessageSource<byte[]> {
|
||||
public class ByteStreamSource implements PollableSource<byte[]> {
|
||||
|
||||
private BufferedInputStream stream;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamSource implements MessageSource<String> {
|
||||
public class CharacterStreamSource implements PollableSource<String> {
|
||||
|
||||
private final BufferedReader reader;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.ContextStartedEvent;
|
||||
import org.springframework.context.event.ContextStoppedEvent;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ApplicationEventSourceTests {
|
||||
|
||||
@Test
|
||||
public void testAnyApplicationEventSentByDefault() {
|
||||
MessageChannel channel = new QueueChannel();
|
||||
QueueChannel channel = new QueueChannel();
|
||||
ApplicationEventSource adapter = new ApplicationEventSource(channel);
|
||||
Message<?> message1 = channel.receive(0);
|
||||
assertNull(message1);
|
||||
@@ -58,7 +58,7 @@ public class ApplicationEventSourceTests {
|
||||
|
||||
@Test
|
||||
public void testOnlyConfiguredEventTypesAreSent() {
|
||||
MessageChannel channel = new QueueChannel();
|
||||
QueueChannel channel = new QueueChannel();
|
||||
ApplicationEventSource adapter = new ApplicationEventSource(channel);
|
||||
List<Class<? extends ApplicationEvent>> eventTypes = new ArrayList<Class<? extends ApplicationEvent>>();
|
||||
eventTypes.add(TestApplicationEvent1.class);
|
||||
@@ -77,7 +77,7 @@ public class ApplicationEventSourceTests {
|
||||
@Test
|
||||
public void testApplicationContextEvents() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationEventSourceTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channel");
|
||||
PollableChannel channel = (PollableChannel) context.getBean("channel");
|
||||
Message<?> refreshedEventMessage = channel.receive(0);
|
||||
assertNotNull(refreshedEventMessage);
|
||||
assertEquals(ContextRefreshedEvent.class, refreshedEventMessage.getPayload().getClass());
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
@@ -46,7 +45,7 @@ public class HttpInvokerGatewayTests {
|
||||
|
||||
@Test
|
||||
public void testRequestOnly() throws Exception {
|
||||
MessageChannel channel = new QueueChannel();
|
||||
QueueChannel channel = new QueueChannel();
|
||||
HttpInvokerGateway gateway = new HttpInvokerGateway(channel);
|
||||
gateway.setExpectReply(false);
|
||||
gateway.afterPropertiesSet();
|
||||
@@ -61,7 +60,7 @@ public class HttpInvokerGatewayTests {
|
||||
|
||||
@Test
|
||||
public void testRequestReply() throws Exception {
|
||||
final MessageChannel channel = new QueueChannel();
|
||||
final QueueChannel channel = new QueueChannel();
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
public void run() {
|
||||
Message<?> message = channel.receive();
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.jms.JmsGateway;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.jms.connection.JmsTransactionManager;
|
||||
@@ -42,7 +41,7 @@ public class JmsGatewayParserTests {
|
||||
public void testGatewayWithConnectionFactoryAndDestination() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithConnectionFactoryAndDestination.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
@@ -56,7 +55,7 @@ public class JmsGatewayParserTests {
|
||||
public void testGatewayWithConnectionFactoryAndDestinationName() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithConnectionFactoryAndDestinationName.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
@@ -70,7 +69,7 @@ public class JmsGatewayParserTests {
|
||||
public void testGatewayWithMessageConverter() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithMessageConverter.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
@@ -133,7 +132,7 @@ public class JmsGatewayParserTests {
|
||||
public void testGatewayWithDefaultConnectionFactory() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithDefaultConnectionFactory.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.jms.JmsSource;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ public class JmsSourceParserTests {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceEndpoint.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channel");
|
||||
PollableChannel channel = (PollableChannel) context.getBean("channel");
|
||||
Message<?> message = channel.receive(3000);
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
|
||||
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertNull;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.SourceEndpoint;
|
||||
import org.springframework.integration.endpoint.TriggerMessage;
|
||||
@@ -38,7 +38,7 @@ public class ByteStreamSourceTests {
|
||||
public void testEndOfStream() {
|
||||
byte[] bytes = new byte[] {1,2,3};
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
MessageChannel channel = new QueueChannel();
|
||||
QueueChannel channel = new QueueChannel();
|
||||
ByteStreamSource source = new ByteStreamSource(stream);
|
||||
SourceEndpoint endpoint = new SourceEndpoint(source);
|
||||
endpoint.setTarget(channel);
|
||||
@@ -61,7 +61,7 @@ public class ByteStreamSourceTests {
|
||||
public void testByteArrayIsTruncated() {
|
||||
byte[] bytes = new byte[] {0,1,2,3,4,5};
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
MessageChannel channel = new QueueChannel();
|
||||
QueueChannel channel = new QueueChannel();
|
||||
ByteStreamSource source = new ByteStreamSource(stream);
|
||||
source.setBytesPerMessage(4);
|
||||
PollingSchedule schedule = new PollingSchedule(1000);
|
||||
@@ -83,7 +83,7 @@ public class ByteStreamSourceTests {
|
||||
public void testByteArrayIsNotTruncated() {
|
||||
byte[] bytes = new byte[] {0,1,2,3,4,5};
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
MessageChannel channel = new QueueChannel();
|
||||
QueueChannel channel = new QueueChannel();
|
||||
ByteStreamSource source = new ByteStreamSource(stream);
|
||||
source.setBytesPerMessage(4);
|
||||
source.setShouldTruncate(false);
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.io.IOException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
|
||||
import org.springframework.integration.dispatcher.PollingDispatcher;
|
||||
@@ -37,7 +36,7 @@ import org.springframework.integration.scheduling.PollingSchedule;
|
||||
*/
|
||||
public class ByteStreamTargetTests {
|
||||
|
||||
private MessageChannel channel;
|
||||
private QueueChannel channel;
|
||||
|
||||
private PollingDispatcher dispatcher;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertNull;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.SourceEndpoint;
|
||||
import org.springframework.integration.endpoint.TriggerMessage;
|
||||
@@ -37,7 +37,7 @@ public class CharacterStreamSourceTests {
|
||||
@Test
|
||||
public void testEndOfStream() {
|
||||
StringReader reader = new StringReader("test");
|
||||
MessageChannel channel = new QueueChannel();
|
||||
QueueChannel channel = new QueueChannel();
|
||||
CharacterStreamSource source = new CharacterStreamSource(reader);
|
||||
PollingSchedule schedule = new PollingSchedule(1000);
|
||||
schedule.setInitialDelay(10000);
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.io.StringWriter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
|
||||
import org.springframework.integration.dispatcher.PollingDispatcher;
|
||||
@@ -36,7 +35,7 @@ import org.springframework.integration.scheduling.PollingSchedule;
|
||||
*/
|
||||
public class CharacterStreamTargetTests {
|
||||
|
||||
private MessageChannel channel;
|
||||
private QueueChannel channel;
|
||||
|
||||
private PollingDispatcher dispatcher;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user