diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quote/TickerStream.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quote/TickerStream.java index 84cb1850c2..da1787af53 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quote/TickerStream.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quote/TickerStream.java @@ -29,7 +29,7 @@ import org.springframework.integration.annotation.Poller; public class TickerStream { @ChannelAdapter("tickers") - @Poller(period = 300) + @Poller(interval = 300) public String nextTicker() { char[] chars = new char[3]; for (int i = 0; i < 3; i++) { diff --git a/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageConsumerTests.java b/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageConsumerTests.java index 9d70e23081..2d8a5221c3 100644 --- a/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageConsumerTests.java +++ b/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageConsumerTests.java @@ -28,7 +28,7 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.endpoint.ChannelPoller; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.PollingSchedule; +import org.springframework.integration.scheduling.IntervalTrigger; /** * @author Mark Fisher @@ -43,7 +43,7 @@ public class ByteStreamWritingMessageConsumerTests { @Before public void initialize() { this.channel = new QueueChannel(10); - this.poller = new ChannelPoller(channel, new PollingSchedule(0)); + this.poller = new ChannelPoller(channel, new IntervalTrigger(0)); } diff --git a/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/CharacterStreamWritingMessageConsumerTests.java b/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/CharacterStreamWritingMessageConsumerTests.java index 4544878bb2..91b9637d6c 100644 --- a/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/CharacterStreamWritingMessageConsumerTests.java +++ b/org.springframework.integration.stream/src/test/java/org/springframework/integration/stream/CharacterStreamWritingMessageConsumerTests.java @@ -27,7 +27,7 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.endpoint.ChannelPoller; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.PollingSchedule; +import org.springframework.integration.scheduling.IntervalTrigger; /** * @author Mark Fisher @@ -42,7 +42,7 @@ public class CharacterStreamWritingMessageConsumerTests { @Before public void initialize() { this.channel = new QueueChannel(10); - this.poller = new ChannelPoller(channel, new PollingSchedule(0)); + this.poller = new ChannelPoller(channel, new IntervalTrigger(0)); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/annotation/Poller.java b/org.springframework.integration/src/main/java/org/springframework/integration/annotation/Poller.java index df59a8e6be..8e88d9949e 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/annotation/Poller.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/annotation/Poller.java @@ -39,7 +39,7 @@ import org.springframework.integration.scheduling.PollingSchedule; @Documented public @interface Poller { - int period(); + int interval(); long initialDelay() default PollingSchedule.DEFAULT_INITIAL_DELAY; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractEndpointParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractEndpointParser.java index 5027d0ed05..a4e4c11f6e 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractEndpointParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractEndpointParser.java @@ -89,7 +89,7 @@ public abstract class AbstractEndpointParser extends AbstractSingleBeanDefinitio } Element pollerElement = DomUtils.getChildElementByTagName(element, POLLER_ELEMENT); if (pollerElement != null) { - IntegrationNamespaceUtils.configureSchedule(pollerElement, builder); + IntegrationNamespaceUtils.configureTrigger(pollerElement, builder); Element txElement = DomUtils.getChildElementByTagName(pollerElement, "transactional"); if (txElement != null) { IntegrationNamespaceUtils.configureTransactionAttributes(txElement, builder); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractOutboundChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractOutboundChannelAdapterParser.java index 97e279fc3e..6973d08b57 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractOutboundChannelAdapterParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractOutboundChannelAdapterParser.java @@ -46,7 +46,7 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann if (!StringUtils.hasText(channelName)) { throw new ConfigurationException("outbound channel adapter with a 'poller' requires a 'channel' to poll"); } - IntegrationNamespaceUtils.configureSchedule(pollerElement, adapterBuilder); + IntegrationNamespaceUtils.configureTrigger(pollerElement, adapterBuilder); Element txElement = DomUtils.getChildElementByTagName(pollerElement, "transactional"); if (txElement != null) { IntegrationNamespaceUtils.configureTransactionAttributes(txElement, adapterBuilder); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractPollingInboundChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractPollingInboundChannelAdapterParser.java index e859331171..d23411e4aa 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractPollingInboundChannelAdapterParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/AbstractPollingInboundChannelAdapterParser.java @@ -23,7 +23,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.ConfigurationException; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; -import org.springframework.integration.scheduling.PollingSchedule; +import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -45,7 +45,7 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac adapterBuilder.addPropertyReference("source", source); adapterBuilder.addPropertyReference("outputChannel", channelName); if (pollerElement != null) { - IntegrationNamespaceUtils.configureSchedule(pollerElement, adapterBuilder); + IntegrationNamespaceUtils.configureTrigger(pollerElement, adapterBuilder); IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, pollerElement, "max-messages-per-poll"); Element txElement = DomUtils.getChildElementByTagName(pollerElement, "transactional"); if (txElement != null) { @@ -53,14 +53,14 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac } } else { - adapterBuilder.addPropertyValue("schedule", new PollingSchedule(this.getDefaultPollInterval())); + adapterBuilder.addPropertyValue("trigger", new IntervalTrigger(this.getDefaultPollInterval())); } return adapterBuilder.getBeanDefinition(); } /** * Subclasses may override this to provide the default poll interval (when - * no 'schedule' is configured). Otherwise, the value will be 1 second. + * no 'trigger' is configured). Otherwise, the value will be 1 second. */ protected int getDefaultPollInterval() { return 1000; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceUtils.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceUtils.java index e505a1d1f5..c70ebec444 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceUtils.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceUtils.java @@ -25,9 +25,9 @@ import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.core.Conventions; import org.springframework.integration.ConfigurationException; -import org.springframework.integration.scheduling.CronSchedule; -import org.springframework.integration.scheduling.PollingSchedule; -import org.springframework.integration.scheduling.Schedule; +import org.springframework.integration.scheduling.CronTrigger; +import org.springframework.integration.scheduling.IntervalTrigger; +import org.springframework.integration.scheduling.Trigger; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.StringUtils; @@ -134,35 +134,33 @@ public abstract class IntegrationNamespaceUtils { } /** - * Parse a "poller" element to create a Schedule and add it to the property values of the target builder. + * Parse a "poller" element to create a Trigger and add it to the property values of the target builder. * * @param pollerElement the "poller" element to parse - * @param targetBuilder the builder that expects the "schedule" property + * @param targetBuilder the builder that expects the "trigger" property */ - public static void configureSchedule(Element pollerElement, BeanDefinitionBuilder targetBuilder) { - Schedule schedule = null; - if (!(StringUtils.hasText(pollerElement.getAttribute("period")) ^ StringUtils.hasText(pollerElement.getAttribute("cron")))) { - throw new ConfigurationException("A element must define either a period " - + "or a cron expression (but not both)"); + public static void configureTrigger(Element pollerElement, BeanDefinitionBuilder targetBuilder) { + Trigger trigger = null; + String interval = pollerElement.getAttribute("period"); + String cron = pollerElement.getAttribute("cron"); + if (!(StringUtils.hasText(interval) ^ StringUtils.hasText(cron))) { + throw new ConfigurationException( + "A element must define either a period or a cron expression (but not both)."); } - if (StringUtils.hasText(pollerElement.getAttribute("period"))) { - Long period = Long.valueOf(pollerElement.getAttribute("period")); - schedule = new PollingSchedule(period); + if (StringUtils.hasText(interval)) { + Long period = Long.valueOf(interval); + IntervalTrigger intervalTrigger = new IntervalTrigger(period); String initialDelay = pollerElement.getAttribute("initial-delay"); if (StringUtils.hasText(initialDelay)) { - ((PollingSchedule)schedule).setInitialDelay(Long.valueOf(initialDelay)); - } - if ("true".equals(pollerElement.getAttribute("fixed-rate").toLowerCase())) { - ((PollingSchedule)schedule).setFixedRate(true); - } - else { - ((PollingSchedule)schedule).setFixedRate(false); + intervalTrigger.setInitialDelay(Long.valueOf(initialDelay)); } + intervalTrigger.setFixedRate("true".equals(pollerElement.getAttribute("fixed-rate").toLowerCase())); + trigger = intervalTrigger; } if (StringUtils.hasText(pollerElement.getAttribute("cron"))) { - schedule = new CronSchedule(pollerElement.getAttribute("cron")); + trigger = new CronTrigger(pollerElement.getAttribute("cron")); } - targetBuilder.addPropertyValue("schedule", schedule); + targetBuilder.addPropertyValue("trigger", trigger); } /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java index 803d434c35..ebeb4bc823 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java @@ -27,9 +27,9 @@ import org.springframework.integration.channel.ChannelRegistry; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.endpoint.AbstractEndpoint; -import org.springframework.integration.endpoint.AbstractMessageHandlingEndpoint; import org.springframework.integration.endpoint.AbstractMessageConsumingEndpoint; -import org.springframework.integration.scheduling.PollingSchedule; +import org.springframework.integration.endpoint.AbstractMessageHandlingEndpoint; +import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -87,11 +87,11 @@ public abstract class AbstractMethodAnnotationPostProcessor source, MessageChannel channel, Schedule schedule) { - super(schedule); + public SourcePoller(PollableSource source, MessageChannel channel, Trigger trigger) { + super(trigger); Assert.notNull(source, "source must not be null"); Assert.notNull(channel, "channel must not be null"); this.source = source; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java index 45c2c6b7c2..4efc314f8e 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java @@ -22,8 +22,8 @@ import org.springframework.context.Lifecycle; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.MethodInvokingSource; import org.springframework.integration.message.PollableSource; -import org.springframework.integration.scheduling.Schedule; import org.springframework.integration.scheduling.TaskScheduler; +import org.springframework.integration.scheduling.Trigger; /** * A Channel Adapter implementation for connecting a @@ -36,7 +36,7 @@ public class SourcePollingChannelAdapter extends AbstractMessageProducingEndpoin private volatile PollableSource source; - private volatile Schedule schedule; + private volatile Trigger trigger; private volatile SourcePoller poller; @@ -53,8 +53,8 @@ public class SourcePollingChannelAdapter extends AbstractMessageProducingEndpoin this.source = source; } - public void setSchedule(Schedule schedule) { - this.schedule = schedule; + public void setTrigger(Trigger trigger) { + this.trigger = trigger; } public void setMaxMessagesPerPoll(int maxMessagesPerPoll) { @@ -73,7 +73,7 @@ public class SourcePollingChannelAdapter extends AbstractMessageProducingEndpoin if (this.running) { return; } - this.poller = new SourcePoller(source, this.getOutputChannel(), schedule); + this.poller = new SourcePoller(source, this.getOutputChannel(), trigger); if (maxMessagesPerPoll < 0 && source instanceof MethodInvokingSource) { // the default is 1 since a MethodInvokingSource might return a non-null value // every time it is invoked, thus producing an infinite number of messages per poll diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/IntervalTrigger.java b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/IntervalTrigger.java index 57655d122f..4c6c8dede1 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/IntervalTrigger.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/IntervalTrigger.java @@ -63,6 +63,13 @@ public class IntervalTrigger implements Trigger { this.initialDelay = initialDelay; } + /** + * Specify the delay for the initial execution using the given time unit. + */ + public void setInitialDelay(long initialDelay, TimeUnit unit) { + this.initialDelay = unit.toMillis(initialDelay); + } + /** * Specify whether the interval should be measured between the * scheduled start times rather than between actual completion times diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/bus/DefaultMessageBusTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/bus/DefaultMessageBusTests.java index 148f06c728..44f133d322 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/bus/DefaultMessageBusTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/bus/DefaultMessageBusTests.java @@ -41,7 +41,7 @@ import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.PollableSource; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.PollingSchedule; +import org.springframework.integration.scheduling.IntervalTrigger; /** * @author Mark Fisher @@ -206,7 +206,7 @@ public class DefaultMessageBusTests { CountDownLatch latch = new CountDownLatch(1); SourcePollingChannelAdapter channelAdapter = new SourcePollingChannelAdapter(); channelAdapter.setSource(new FailingSource(latch)); - channelAdapter.setSchedule(new PollingSchedule(1000)); + channelAdapter.setTrigger(new IntervalTrigger(1000)); channelAdapter.setOutputChannel(outputChannel); channelAdapter.setBeanName("testChannel"); context.getBeanFactory().registerSingleton("testChannel", channelAdapter); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorTests.java index abdf6ab05e..19272af46e 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorTests.java @@ -49,8 +49,8 @@ import org.springframework.integration.endpoint.ServiceActivatorEndpoint; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageConsumer; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.PollingSchedule; -import org.springframework.integration.scheduling.Schedule; +import org.springframework.integration.scheduling.IntervalTrigger; +import org.springframework.integration.scheduling.Trigger; import org.springframework.integration.util.MethodInvoker; /** @@ -329,13 +329,12 @@ public class MessagingAnnotationPostProcessorTests { processedEndpoint.afterPropertiesSet(); DirectFieldAccessor accessor = new DirectFieldAccessor(processedEndpoint); ChannelPoller poller = (ChannelPoller) accessor.getPropertyValue("poller"); - Schedule schedule = (Schedule) new DirectFieldAccessor(poller).getPropertyValue("schedule"); - assertEquals(PollingSchedule.class, schedule.getClass()); - PollingSchedule pollingSchedule = (PollingSchedule) schedule; - assertEquals(1234, pollingSchedule.getPeriod()); - assertEquals(5678, pollingSchedule.getInitialDelay()); - assertEquals(true, pollingSchedule.getFixedRate()); - assertEquals(TimeUnit.SECONDS, pollingSchedule.getTimeUnit()); + Trigger trigger = (Trigger) new DirectFieldAccessor(poller).getPropertyValue("trigger"); + assertEquals(IntervalTrigger.class, trigger.getClass()); + DirectFieldAccessor triggerAccessor = new DirectFieldAccessor(trigger); + assertEquals(new Long(123000), triggerAccessor.getPropertyValue("interval")); + assertEquals(new Long(456000), triggerAccessor.getPropertyValue("initialDelay")); + assertEquals(true, triggerAccessor.getPropertyValue("fixedRate")); } @Test @@ -448,7 +447,7 @@ public class MessagingAnnotationPostProcessorTests { private static class AnnotatedEndpointWithPolledAnnotation { @ServiceActivator(inputChannel="testChannel") - @Poller(period=1234, initialDelay=5678, fixedRate=true, timeUnit=TimeUnit.SECONDS) + @Poller(interval=123, initialDelay=456, fixedRate=true, timeUnit=TimeUnit.SECONDS) public String prependFoo(String s) { return "foo" + s; } @@ -470,7 +469,7 @@ public class MessagingAnnotationPostProcessorTests { private static class ChannelAdapterAnnotationTestBean { @ChannelAdapter("testChannel") - @Poller(period = 1000, initialDelay = 0, maxMessagesPerPoll = 1) + @Poller(interval=1000, initialDelay=0, maxMessagesPerPoll=1) public String test() { return "test"; } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ChannelPollerTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ChannelPollerTests.java index cd3455219f..a7565bd7cd 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ChannelPollerTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ChannelPollerTests.java @@ -30,7 +30,7 @@ import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageConsumer; import org.springframework.integration.message.MessageRejectedException; -import org.springframework.integration.scheduling.Schedule; +import org.springframework.integration.scheduling.Trigger; /** * @author Iwein Fuld @@ -39,16 +39,16 @@ import org.springframework.integration.scheduling.Schedule; public class ChannelPollerTests { private ChannelPoller poller; - private Schedule scheduleMock = createMock(Schedule.class); + private Trigger triggerMock = createMock(Trigger.class); private PollableChannel channelMock = createMock(PollableChannel.class); private MessageConsumer endpointMock = createMock(MessageConsumer.class); private Message messageMock = createMock(Message.class); - private Object[] globalMocks = new Object[] { scheduleMock, channelMock, endpointMock, messageMock }; + private Object[] globalMocks = new Object[] { triggerMock, channelMock, endpointMock, messageMock }; @Before public void init() { - poller = new ChannelPoller(channelMock, scheduleMock); + poller = new ChannelPoller(channelMock, triggerMock); poller.subscribe(endpointMock); poller.setReceiveTimeout(-1); reset(globalMocks); @@ -112,7 +112,7 @@ public class ChannelPollerTests { @Test public void blockingSourceTimedOut() { - poller = new ChannelPoller(channelMock, scheduleMock); + poller = new ChannelPoller(channelMock, triggerMock); poller.subscribe(endpointMock); // we don't need to await the timeout, returning null suffices expect(channelMock.receive(1)).andReturn(null); @@ -124,7 +124,7 @@ public class ChannelPollerTests { @Test public void blockingSourceNotTimedOut() { - poller = new ChannelPoller(channelMock, scheduleMock); + poller = new ChannelPoller(channelMock, triggerMock); poller.subscribe(endpointMock); expect(channelMock.receive(1)).andReturn(messageMock); endpointMock.onMessage(messageMock);