When a PollableSourceAdapter has a SynchronousChannel, it now registers its source with that channel (and does not start any tasks with the scheduler). This is a temporary implementation of this feature likely to be handled differently after continued source refactoring.
This commit is contained in:
@@ -23,6 +23,7 @@ import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.handler.HandlerMethodInvoker;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.util.MethodValidator;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
@@ -23,8 +23,10 @@ import java.util.concurrent.Executors;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.dispatcher.SynchronousChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.scheduling.MessagingTask;
|
||||
import org.springframework.integration.scheduling.MessagingTaskScheduler;
|
||||
import org.springframework.integration.scheduling.MessagingTaskSchedulerAware;
|
||||
@@ -50,10 +52,10 @@ public class PollingSourceAdapter<T> extends AbstractSourceAdapter<T> implements
|
||||
|
||||
private volatile int maxMessagesPerTask = 1;
|
||||
|
||||
private volatile boolean starting;
|
||||
|
||||
private volatile boolean running;
|
||||
|
||||
private final Object lifecycleMonitor = new Object();
|
||||
|
||||
|
||||
/**
|
||||
* Create a new adapter for the given source.
|
||||
@@ -106,28 +108,38 @@ public class PollingSourceAdapter<T> extends AbstractSourceAdapter<T> implements
|
||||
if (this.source == null) {
|
||||
throw new ConfigurationException("source must not be null");
|
||||
}
|
||||
if (this.getChannel() instanceof SynchronousChannel) {
|
||||
((SynchronousChannel) this.getChannel()).setSource(this.source);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (this.isRunning() || this.starting) {
|
||||
return;
|
||||
}
|
||||
this.starting = true;
|
||||
if (!this.isInitialized()) {
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
if (this.scheduler == null) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("no task scheduler has been provided, will create one");
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
if (this.isRunning()) {
|
||||
return;
|
||||
}
|
||||
this.scheduler = new SimpleMessagingTaskScheduler(Executors.newSingleThreadScheduledExecutor());
|
||||
if (!this.isInitialized()) {
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
if (this.getChannel() instanceof SynchronousChannel) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("source adapter configured on synchronous channel, not scheduling");
|
||||
}
|
||||
this.running = true;
|
||||
return;
|
||||
}
|
||||
if (this.scheduler == null) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("no task scheduler has been provided, will create one");
|
||||
}
|
||||
this.scheduler = new SimpleMessagingTaskScheduler(Executors.newSingleThreadScheduledExecutor());
|
||||
}
|
||||
this.running = true;
|
||||
}
|
||||
if (!this.scheduler.isRunning()) {
|
||||
this.scheduler.start();
|
||||
}
|
||||
this.scheduler.schedule(new PollingSourceAdapterTask());
|
||||
this.running = true;
|
||||
this.starting = false;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
||||
@@ -22,11 +22,11 @@ import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.adapter.PollableSource;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.DispatcherPolicy;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ public class SynchronousChannel extends AbstractMessageChannel {
|
||||
private static final ThreadLocalMessageHolder messageHolder = new ThreadLocalMessageHolder();
|
||||
|
||||
|
||||
private final PollableSource<?> source;
|
||||
private volatile PollableSource<?> source;
|
||||
|
||||
private final MessageDistributor distributor;
|
||||
|
||||
@@ -66,6 +66,10 @@ public class SynchronousChannel extends AbstractMessageChannel {
|
||||
}
|
||||
|
||||
|
||||
public void setSource(PollableSource<?> source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public void addHandler(MessageHandler handler) {
|
||||
this.distributor.addHandler(handler);
|
||||
this.handlerCount.incrementAndGet();
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
package org.springframework.integration.message;
|
||||
|
||||
/**
|
||||
* Interface for any external message source that can be polled.
|
||||
@@ -27,6 +27,7 @@ import org.junit.Test;
|
||||
import org.springframework.integration.channel.SimpleChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.PollableSource;
|
||||
import org.springframework.integration.adapter.PollingSourceAdapter;
|
||||
import org.springframework.integration.adapter.SourceAdapter;
|
||||
import org.springframework.integration.channel.DispatcherPolicy;
|
||||
@@ -41,6 +40,7 @@ import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.adapter.PollableSource;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user