INT-1684 added the 'time-unit' attribute on the top-level <poller> element. It can be used with 'fixed-rate' or 'fixed-delay' values (but not 'cron' or 'trigger' references)

This commit is contained in:
Mark Fisher
2010-12-13 15:03:46 -05:00
parent ddd2805520
commit 55d0f965d4
2 changed files with 35 additions and 4 deletions

View File

@@ -109,31 +109,42 @@ public class PollerParser extends AbstractBeanDefinitionParser {
String fixedRateAttribute = pollerElement.getAttribute("fixed-rate");
String fixedDelayAttribute = pollerElement.getAttribute("fixed-delay");
String cronAttribute = pollerElement.getAttribute("cron");
String timeUnit = pollerElement.getAttribute("time-unit");
List<String> triggerBeanNames = new ArrayList<String>();
if (StringUtils.hasText(triggerAttribute)) {
if (StringUtils.hasText(timeUnit)) {
parserContext.getReaderContext().error("The 'time-unit' attribute cannot be used with a 'trigger' reference.", pollerElement);
}
triggerBeanNames.add(triggerAttribute);
}
else if (StringUtils.hasText(fixedRateAttribute)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(PERIODIC_TRIGGER_CLASSNAME);
builder.addConstructorArgValue(fixedRateAttribute);
if (StringUtils.hasText(timeUnit)) {
builder.addConstructorArgValue(timeUnit);
}
builder.addPropertyValue("fixedRate", Boolean.TRUE);
String triggerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
builder.getBeanDefinition(), parserContext.getRegistry());
triggerBeanNames.add(triggerBeanName);
}
else if (StringUtils.hasText(fixedDelayAttribute)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition(PERIODIC_TRIGGER_CLASSNAME);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(PERIODIC_TRIGGER_CLASSNAME);
builder.addConstructorArgValue(fixedDelayAttribute);
if (StringUtils.hasText(timeUnit)) {
builder.addConstructorArgValue(timeUnit);
}
builder.addPropertyValue("fixedRate", Boolean.FALSE);
String triggerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
builder.getBeanDefinition(), parserContext.getRegistry());
triggerBeanNames.add(triggerBeanName);
}
else if (StringUtils.hasText(cronAttribute)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition(CRON_TRIGGER_CLASSNAME);
if (StringUtils.hasText(timeUnit)) {
parserContext.getReaderContext().error("The 'time-unit' attribute cannot be used with a 'cron' trigger.", pollerElement);
}
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CRON_TRIGGER_CLASSNAME);
builder.addConstructorArgValue(cronAttribute);
String triggerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
builder.getBeanDefinition(), parserContext.getRegistry());

View File

@@ -1186,6 +1186,26 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:documentation>Fixed rate trigger (in milliseconds).</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="time-unit">
<xsd:annotation>
<xsd:documentation><![CDATA[
The java.util.concurrent.TimeUnit enum value. This can ONLY be used in combination
with the 'fixed-delay' or 'fixed-rate' attributes. If combined with either 'cron'
or a 'trigger' reference attribute, it will cause a failure. The minimal supported
granularity for a PeriodicTrigger is MILLISEONDS. Therefore, the only available options
are MILLISECONDS and SECONDS. If this value is not provided, then any 'fixed-delay' or
'fixed-rate' value will be interpreted as MILLISECONDS by default. Basically this enum
provides a convenience for SECONDS-based interval trigger values. For hourly, daily,
and monthly settings, consider using a 'cron' trigger instead.
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="MILLISECONDS" />
<xsd:enumeration value="SECONDS" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="cron" type="xsd:string">
<xsd:annotation>
<xsd:documentation>Cron trigger.</xsd:documentation>