diff --git a/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java b/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java index c734d6cc0b..7ca842b3ca 100644 --- a/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java +++ b/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java @@ -30,9 +30,9 @@ import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.AbstractPollingEndpoint; -import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.util.Assert; /** @@ -132,7 +132,7 @@ public abstract class TestUtils { if (endpoint instanceof AbstractPollingEndpoint) { DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint); if (accessor.getPropertyValue("trigger") == null) { - ((AbstractPollingEndpoint) endpoint).setTrigger(new IntervalTrigger(10)); + ((AbstractPollingEndpoint) endpoint).setTrigger(new PeriodicTrigger(10)); } } registerBean(endpointName, endpoint, this); diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java index e62ded0e28..9b94027626 100644 --- a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java @@ -27,11 +27,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.endpoint.PollingConsumer; -import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.integration.ws.MarshallingWebServiceOutboundGateway; import org.springframework.integration.ws.SimpleWebServiceOutboundGateway; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; +import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.ws.WebServiceMessageFactory; import org.springframework.ws.client.core.FaultMessageResolver; import org.springframework.ws.client.core.SourceExtractor; @@ -199,12 +199,12 @@ public class WebServiceOutboundGatewayParserTests { AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithPoller"); assertEquals(PollingConsumer.class, endpoint.getClass()); Object obj = new DirectFieldAccessor(endpoint).getPropertyValue("trigger"); - assertEquals(IntervalTrigger.class, obj.getClass()); - IntervalTrigger trigger = (IntervalTrigger) obj; + assertEquals(PeriodicTrigger.class, obj.getClass()); + PeriodicTrigger trigger = (PeriodicTrigger) obj; DirectFieldAccessor accessor = new DirectFieldAccessor(trigger); accessor = new DirectFieldAccessor(trigger); - assertEquals("IntervalTrigger had wrong interval", - 5000, ((Long)accessor.getPropertyValue("interval")).longValue()); + assertEquals("PeriodicTrigger had wrong period", + 5000, ((Long)accessor.getPropertyValue("period")).longValue()); } @Test diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java index bee667cd0c..95b4d78414 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -116,7 +116,7 @@ public class PollerParser extends AbstractBeanDefinitionParser { } TimeUnit timeUnit = TimeUnit.valueOf(element.getAttribute("time-unit")); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".scheduling.IntervalTrigger"); + "org.springframework.scheduling.support.PeriodicTrigger"); builder.addConstructorArgValue(interval); builder.addConstructorArgValue(timeUnit); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "initial-delay"); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java index 73f4ddfbe0..b64ac55507 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -31,7 +31,7 @@ import org.springframework.integration.handler.ReplyMessageHolder; import org.springframework.integration.message.ErrorMessage; import org.springframework.integration.message.MessageHandler; import org.springframework.integration.message.MessageDeliveryException; -import org.springframework.integration.scheduling.IntervalTrigger; +import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.util.Assert; /** @@ -203,7 +203,7 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint implemen else if (this.replyChannel instanceof PollableChannel) { PollingConsumer endpoint = new PollingConsumer( (PollableChannel) this.replyChannel, handler); - endpoint.setTrigger(new IntervalTrigger(10)); + endpoint.setTrigger(new PeriodicTrigger(10)); endpoint.setBeanFactory(this.getBeanFactory()); endpoint.afterPropertiesSet(); correlator = endpoint; 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 deleted file mode 100644 index 09f2ef8836..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/IntervalTrigger.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2002-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.scheduling; - -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import org.springframework.scheduling.Trigger; -import org.springframework.scheduling.TriggerContext; -import org.springframework.util.Assert; - -/** - * A trigger for periodic execution. The interval may be applied as either - * fixed-rate or fixed-delay, and an initial delay value may also be - * configured. The default initial delay is 0, and the default behavior is - * fixed-delay: each subsequent delay is measured from the last completion - * time. To enable execution between the scheduled start time of each - * execution, set 'fixedRate' to true. - * - * @author Mark Fisher - */ -public class IntervalTrigger implements Trigger { - - private final long interval; - - private final TimeUnit timeUnit; - - private volatile long initialDelay = 0; - - private volatile boolean fixedRate = false; - - - /** - * Create a trigger with the given interval in milliseconds. - */ - public IntervalTrigger(long interval) { - this(interval, null); - } - - /** - * Create a trigger with the given interval and time unit. - */ - public IntervalTrigger(long interval, TimeUnit timeUnit) { - Assert.isTrue(interval >= 0, "interval must not be negative"); - this.timeUnit = (timeUnit != null) ? timeUnit : TimeUnit.MILLISECONDS; - this.interval = this.timeUnit.toMillis(interval); - } - - - /** - * Specify the delay for the initial execution. - */ - public void setInitialDelay(long initialDelay) { - this.initialDelay = this.timeUnit.toMillis(initialDelay); - } - - /** - * Specify whether the interval should be measured between the - * scheduled start times rather than between actual completion times - * (the latter, "fixed delay" behavior, is the default). - */ - public void setFixedRate(boolean fixedRate) { - this.fixedRate = fixedRate; - } - - /** - * Returns the next time a task should run. - */ - public Date nextExecutionTime(TriggerContext triggerContext) { - if (triggerContext.lastScheduledExecutionTime() == null) { - return new Date(System.currentTimeMillis() + this.initialDelay); - } - else if (this.fixedRate) { - return new Date(triggerContext.lastScheduledExecutionTime().getTime() + this.interval); - } - return new Date(triggerContext.lastCompletionTime().getTime() + this.interval); - } - -} diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java index 7c3aeff7e9..813508f880 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java @@ -42,9 +42,9 @@ import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.MessageSource; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.integration.util.TestUtils; import org.springframework.integration.util.TestUtils.TestApplicationContext; +import org.springframework.scheduling.support.PeriodicTrigger; /** * @author Mark Fisher @@ -185,7 +185,7 @@ public class ApplicationContextMessageBusTests { CountDownLatch latch = new CountDownLatch(1); SourcePollingChannelAdapter channelAdapter = new SourcePollingChannelAdapter(); channelAdapter.setSource(new FailingSource(latch)); - channelAdapter.setTrigger(new IntervalTrigger(1000)); + channelAdapter.setTrigger(new PeriodicTrigger(1000)); channelAdapter.setOutputChannel(outputChannel); context.registerEndpoint("testChannel", channelAdapter); context.refresh(); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml index 4cc7a2b5f2..a27ed488dc 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml @@ -17,7 +17,7 @@ - + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/MessageChannelTemplateTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/MessageChannelTemplateTests.java index dd14399f0f..36110a2292 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/MessageChannelTemplateTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/MessageChannelTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -37,9 +37,9 @@ import org.springframework.integration.handler.AbstractReplyProducingMessageHand import org.springframework.integration.handler.ReplyMessageHolder; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.integration.util.TestUtils; import org.springframework.integration.util.TestUtils.TestApplicationContext; +import org.springframework.scheduling.support.PeriodicTrigger; /** * @author Mark Fisher @@ -62,7 +62,7 @@ public class MessageChannelTemplateTests { } }; PollingConsumer endpoint = new PollingConsumer(requestChannel, handler); - endpoint.setTrigger(new IntervalTrigger(10)); + endpoint.setTrigger(new PeriodicTrigger(10)); context.registerEndpoint("testEndpoint", endpoint); context.refresh(); } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java index e4e505a196..7ef88b797a 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -33,10 +33,10 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.Message; import org.springframework.integration.message.MessageSource; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.integration.util.TestUtils; import org.springframework.integration.util.TestUtils.TestApplicationContext; +import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.util.ClassUtils; /** @@ -62,7 +62,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests { return invocation.proceed(); } }); - pollerMetadata.setTrigger(new IntervalTrigger(5000)); + pollerMetadata.setTrigger(new PeriodicTrigger(5000)); pollerMetadata.setMaxMessagesPerPoll(1); pollerMetadata.setAdviceChain(adviceChain); factoryBean.setPollerMetadata(pollerMetadata); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java b/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java index b353d5ed29..831c9b9a5c 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/PollingEndpointStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -16,7 +16,7 @@ package org.springframework.integration.endpoint; -import org.springframework.integration.scheduling.IntervalTrigger; +import org.springframework.scheduling.support.PeriodicTrigger; /** * @author Jonas Partner @@ -24,7 +24,7 @@ import org.springframework.integration.scheduling.IntervalTrigger; public class PollingEndpointStub extends AbstractPollingEndpoint { public PollingEndpointStub() { - this.setTrigger(new IntervalTrigger(500)); + this.setTrigger(new PeriodicTrigger(500)); } @Override diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/message/MethodInvokingMessageHandlerTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/message/MethodInvokingMessageHandlerTests.java index acd76f3b2d..d22dd8dddd 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/message/MethodInvokingMessageHandlerTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/message/MethodInvokingMessageHandlerTests.java @@ -31,9 +31,9 @@ import org.springframework.integration.core.Message; import org.springframework.integration.core.MessagingException; import org.springframework.integration.endpoint.PollingConsumer; import org.springframework.integration.handler.MethodInvokingMessageHandler; -import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.integration.util.TestUtils; import org.springframework.integration.util.TestUtils.TestApplicationContext; +import org.springframework.scheduling.support.PeriodicTrigger; /** * @author Mark Fisher @@ -82,7 +82,7 @@ public class MethodInvokingMessageHandlerTests { assertNull(queue.poll()); MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo"); PollingConsumer endpoint = new PollingConsumer(channel, handler); - endpoint.setTrigger(new IntervalTrigger(10)); + endpoint.setTrigger(new PeriodicTrigger(10)); context.registerEndpoint("testEndpoint", endpoint); context.refresh(); String result = queue.poll(2000, TimeUnit.MILLISECONDS); @@ -100,6 +100,7 @@ public class MethodInvokingMessageHandlerTests { this.queue = queue; } + @SuppressWarnings("unused") public void foo(String s) { try { this.queue.put(s); @@ -111,6 +112,7 @@ public class MethodInvokingMessageHandlerTests { } + @SuppressWarnings("unused") private static class TestSink { private String result; diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/util/TestUtils.java b/org.springframework.integration/src/test/java/org/springframework/integration/util/TestUtils.java index 96433000fe..d79e12b849 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/util/TestUtils.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/util/TestUtils.java @@ -32,9 +32,9 @@ import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.AbstractPollingEndpoint; -import org.springframework.integration.scheduling.IntervalTrigger; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.support.ErrorHandler; +import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.util.Assert; /** @@ -137,7 +137,7 @@ public abstract class TestUtils { if (endpoint instanceof AbstractPollingEndpoint) { DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint); if (accessor.getPropertyValue("trigger") == null) { - ((AbstractPollingEndpoint) endpoint).setTrigger(new IntervalTrigger(10)); + ((AbstractPollingEndpoint) endpoint).setTrigger(new PeriodicTrigger(10)); } } registerBean(endpointName, endpoint, this);