INT-1758 refactored AbsractPollingEndpoint to remove deopendency on PollerMetadata, fixed tests
This commit is contained in:
@@ -158,7 +158,11 @@ public class ConsumerEndpointFactoryBean
|
||||
Assert.notNull(this.pollerMetadata, "No poller has been defined for endpoint '" + this.beanName
|
||||
+ "', and no default poller is available within the context.");
|
||||
}
|
||||
pollingConsumer.setPollerMetadata(this.pollerMetadata);
|
||||
pollingConsumer.setTaskExecutor(this.pollerMetadata.getTaskExecutor());
|
||||
pollingConsumer.setTrigger(this.pollerMetadata.getTrigger());
|
||||
pollingConsumer.setAdviceChain(this.pollerMetadata.getAdviceChain());
|
||||
pollingConsumer.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll());
|
||||
|
||||
pollingConsumer.setReceiveTimeout(this.pollerMetadata.getReceiveTimeout());
|
||||
pollingConsumer.setBeanClassLoader(beanClassLoader);
|
||||
pollingConsumer.setBeanFactory(beanFactory);
|
||||
|
||||
@@ -129,7 +129,10 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean<Sourc
|
||||
// a non-null and non-interruptable value every time it is invoked
|
||||
this.pollerMetadata.setMaxMessagesPerPoll(1);
|
||||
}
|
||||
spca.setPollerMetadata(this.pollerMetadata);
|
||||
spca.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll());
|
||||
spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor());
|
||||
spca.setAdviceChain(this.pollerMetadata.getAdviceChain());
|
||||
spca.setTrigger(this.pollerMetadata.getTrigger());
|
||||
spca.setErrorHandler(this.pollerMetadata.getErrorHandler());
|
||||
spca.setBeanClassLoader(this.beanClassLoader);
|
||||
spca.setAutoStartup(this.autoStartup);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
@@ -29,9 +30,10 @@ import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.scheduling.PollerMetadata;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.support.PeriodicTrigger;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -47,7 +49,9 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
|
||||
private volatile ErrorHandler errorHandler;
|
||||
|
||||
private volatile PollerMetadata pollerMetadata = new PollerMetadata();
|
||||
private volatile Trigger trigger = new PeriodicTrigger(10);
|
||||
|
||||
private volatile List<Advice> adviceChain;
|
||||
|
||||
private volatile ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
|
||||
|
||||
@@ -56,17 +60,30 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
private volatile Runnable poller;
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
|
||||
private volatile long maxMessagesPerPoll = -1;
|
||||
|
||||
private final Object initializationMonitor = new Object();
|
||||
|
||||
|
||||
public AbstractPollingEndpoint() {
|
||||
this.setPhase(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public void setTaskExecutor(Executor taskExecutor) {
|
||||
this.taskExecutor = (taskExecutor != null ? taskExecutor : new SyncTaskExecutor());
|
||||
}
|
||||
|
||||
public void setTrigger(Trigger trigger) {
|
||||
this.trigger = (trigger != null ? trigger : new PeriodicTrigger(10));
|
||||
}
|
||||
|
||||
public void setPollerMetadata(PollerMetadata pollerMetadata) {
|
||||
this.pollerMetadata = pollerMetadata;
|
||||
public void setAdviceChain(List<Advice> adviceChain) {
|
||||
this.adviceChain = adviceChain;
|
||||
}
|
||||
|
||||
public void setMaxMessagesPerPoll(long maxMessagesPerPoll) {
|
||||
this.maxMessagesPerPoll = maxMessagesPerPoll;
|
||||
}
|
||||
|
||||
public void setErrorHandler(ErrorHandler errorHandler) {
|
||||
@@ -83,8 +100,8 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
Assert.notNull(this.pollerMetadata.getTrigger(), "Trigger is required");
|
||||
Executor providedExecutor = this.pollerMetadata.getTaskExecutor();
|
||||
Assert.notNull(this.trigger, "Trigger is required");
|
||||
Executor providedExecutor = this.taskExecutor;
|
||||
if (providedExecutor != null) {
|
||||
this.taskExecutor = providedExecutor;
|
||||
}
|
||||
@@ -117,7 +134,7 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
}
|
||||
};
|
||||
|
||||
List<Advice> adviceChain = this.pollerMetadata.getAdviceChain();
|
||||
List<Advice> adviceChain = this.adviceChain;
|
||||
if (!CollectionUtils.isEmpty(adviceChain)) {
|
||||
ProxyFactory proxyFactory = new ProxyFactory(pollingTask);
|
||||
if (!CollectionUtils.isEmpty(adviceChain)) {
|
||||
@@ -140,7 +157,7 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
}
|
||||
Assert.state(this.getTaskScheduler() != null,
|
||||
"unable to start polling, no taskScheduler available");
|
||||
this.runningTask = this.getTaskScheduler().schedule(this.poller, this.pollerMetadata.getTrigger());
|
||||
this.runningTask = this.getTaskScheduler().schedule(this.poller, this.trigger);
|
||||
}
|
||||
|
||||
@Override // guarded by super#lifecycleLock
|
||||
@@ -161,7 +178,7 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
*/
|
||||
private class Poller implements Runnable {
|
||||
|
||||
private final long maxMessagesPerPoll = pollerMetadata.getMaxMessagesPerPoll();
|
||||
//private final long maxMessagesPerPoll = pollerMetadata.getMaxMessagesPerPoll();
|
||||
|
||||
private final Callable<Boolean> pollingTask;
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.integration.history.TrackableComponent;
|
||||
import org.springframework.integration.mapping.InboundMessageMapper;
|
||||
import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.scheduling.PollerMetadata;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -292,7 +291,6 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint implement
|
||||
else if (this.replyChannel instanceof PollableChannel) {
|
||||
PollingConsumer endpoint = new PollingConsumer(
|
||||
(PollableChannel) this.replyChannel, handler);
|
||||
endpoint.setPollerMetadata(new PollerMetadata());
|
||||
endpoint.setBeanFactory(this.getBeanFactory());
|
||||
endpoint.setReceiveTimeout(this.replyTimeout);
|
||||
endpoint.afterPropertiesSet();
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.support.PeriodicTrigger;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ public class PollerMetadata {
|
||||
|
||||
public static final int MAX_MESSAGES_UNBOUNDED = -1;
|
||||
|
||||
private volatile Trigger trigger = new PeriodicTrigger(10);
|
||||
private volatile Trigger trigger;
|
||||
|
||||
private volatile long maxMessagesPerPoll = MAX_MESSAGES_UNBOUNDED;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user