BATCH-63:added commit-interval and fault tolerant attributes to; added restartable to job
This commit is contained in:
@@ -55,6 +55,11 @@ public class JobParser extends AbstractBeanDefinitionParser {
|
||||
}
|
||||
builder.addPropertyReference("jobRepository", repositoryAttribute);
|
||||
|
||||
String restartableAttribute = element.getAttribute("restartable");
|
||||
if (StringUtils.hasText(restartableAttribute)) {
|
||||
builder.addPropertyValue("restartable", restartableAttribute);
|
||||
}
|
||||
|
||||
FlowParser flowParser = new FlowParser();
|
||||
AbstractBeanDefinition flowDef = flowParser.parse(element, parserContext, jobName);
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* Internal parser for the <step/> elements inside a job. A step element
|
||||
@@ -198,10 +200,13 @@ public class StepParser {
|
||||
protected RootBeanDefinition parseChunkOriented(Element element, ParserContext parserContext) {
|
||||
|
||||
RootBeanDefinition bd;
|
||||
|
||||
boolean isFaultTolerant = false;
|
||||
|
||||
String faultTolerant = element.getAttribute("fault-tolerant");
|
||||
if ("true".equals(faultTolerant)) {
|
||||
bd = new RootBeanDefinition("org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean", null, null);
|
||||
isFaultTolerant = true;
|
||||
}
|
||||
else {
|
||||
bd = new RootBeanDefinition("org.springframework.batch.core.step.item.SimpleStepFactoryBean", null, null);
|
||||
@@ -233,6 +238,25 @@ public class StepParser {
|
||||
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
|
||||
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
|
||||
|
||||
String commitInterval = element.getAttribute("commit-interval");
|
||||
if (StringUtils.hasText(commitInterval)) {
|
||||
bd.getPropertyValues().addPropertyValue("commitInterval", commitInterval);
|
||||
}
|
||||
|
||||
if (isFaultTolerant) {
|
||||
String skipLimit = element.getAttribute("skip-limit");
|
||||
if (StringUtils.hasText(skipLimit)) {
|
||||
bd.getPropertyValues().addPropertyValue("skipLimit", skipLimit);
|
||||
}
|
||||
}
|
||||
|
||||
if (isFaultTolerant) {
|
||||
String retryLimit = element.getAttribute("retry-limit");
|
||||
if (StringUtils.hasText(retryLimit)) {
|
||||
bd.getPropertyValues().addPropertyValue("retryLimit", retryLimit);
|
||||
}
|
||||
}
|
||||
|
||||
handleExceptionElement(element, bd, "skippable-exception-classes", "skippableExceptionClasses");
|
||||
|
||||
handleExceptionElement(element, bd, "retryable-exception-classes", "retryableExceptionClasses");
|
||||
@@ -276,7 +300,16 @@ public class StepParser {
|
||||
String className = listenerElement.getAttribute("class");
|
||||
if ((StringUtils.hasText(id) || StringUtils.hasText(className))
|
||||
&& StringUtils.hasText(listenerRef)) {
|
||||
throw new BeanCreationException("Both 'id' or 'ref' plus 'class' specified; use 'class' with an optional 'id' or just 'ref' for <" + listenerElement.getTagName() + "> element with" + (StringUtils.hasText(id) ? " id=\"" + id + "\"" : "" ) + (StringUtils.hasText(className) ? " class=\"" + className + "\"" : "") + (StringUtils.hasText(listenerRef) ? " ref=\"" + listenerRef + "\"" : ""));
|
||||
NamedNodeMap attributeNodes = listenerElement.getAttributes();
|
||||
StringBuilder attributes = new StringBuilder();
|
||||
for (int i = 0; i < attributeNodes.getLength(); i++) {
|
||||
if (i > 0) {
|
||||
attributes.append(" ");
|
||||
}
|
||||
attributes.append(attributeNodes.item(i));
|
||||
}
|
||||
throw new BeanCreationException("Both 'id' or 'ref' plus 'class' specified; use 'class' with an optional 'id' or just 'ref' for <" +
|
||||
listenerElement.getTagName() + "> element with attributes: " + attributes);
|
||||
}
|
||||
if (StringUtils.hasText(listenerRef)) {
|
||||
listenerRefs.add(listenerRef);
|
||||
|
||||
@@ -37,6 +37,13 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="restartable" type="xsd:boolean" default="false" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Whether the job should be retartable or not in case of failure.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
@@ -194,6 +201,13 @@
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:attributeGroup ref="jobRepository"/>
|
||||
<xsd:attributeGroup ref="transactionManager"/>
|
||||
<xsd:attribute name="commit-interval" type="xsd:integer" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The number of items that will be processed before commit is called for the transaction.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
@@ -269,7 +283,14 @@
|
||||
</xsd:simpleType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="fault-tolerant" type="xsd:boolean" default="false" use="optional"/>
|
||||
<xsd:attribute name="fault-tolerant" type="xsd:boolean" default="false" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Whether the step should provide fault tolerance with skip limit and skippable
|
||||
exception handling.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="reader" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
@@ -291,6 +312,20 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="skip-limit" type="xsd:integer" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The maximum number of items that will be allowed to be skipped.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="retry-limit" type="xsd:integer" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The maximum number of times the processing of an item will be retried.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -47,7 +47,7 @@ public class StepWithChunkOrientedJobParserTests {
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TestReader reader;
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
<job id="job">
|
||||
<step name="step1">
|
||||
<chunk-oriented reader="reader" processor="processor" writer="writer">
|
||||
<chunk-oriented reader="reader" processor="processor" writer="writer"
|
||||
fault-tolerant="true" commit-interval="10" skip-limit="20" retry-limit="3">
|
||||
<listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
|
||||
<listener ref="listener"/>
|
||||
|
||||
Reference in New Issue
Block a user