removed IntervalTrigger, now replaced by PeriodicTrigger in the Spring 3.0 core

This commit is contained in:
Mark Fisher
2009-08-05 02:51:18 +00:00
parent 002a6497c6
commit e881c124d7
12 changed files with 30 additions and 121 deletions

View File

@@ -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");

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -17,7 +17,7 @@
<constructor-arg ref="sourceChannel"/>
<constructor-arg ref="serviceActivator"/>
<property name="trigger">
<bean class="org.springframework.integration.scheduling.IntervalTrigger">
<bean class="org.springframework.scheduling.support.PeriodicTrigger">
<constructor-arg value="100"/>
</bean>
</property>

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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;

View File

@@ -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);