BATCH-63: changed <process-task> to <item-task> and removed fault-tolerant attribute, autodetecting the need from other configuration settings

This commit is contained in:
trisberg
2008-11-17 21:30:33 +00:00
parent d2d54b88c2
commit 3b0331a263
5 changed files with 58 additions and 43 deletions

View File

@@ -72,7 +72,7 @@ public class StepParser {
@SuppressWarnings("unchecked")
List<Element> simpleTaskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "simple-task");
@SuppressWarnings("unchecked")
List<Element> processTaskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "process-task");
List<Element> processTaskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "item-task");
if (simpleTaskElements.size() > 0) {
Object task = parseSimpleTask(simpleTaskElements.get(0), parserContext);
stateBuilder.addConstructorArgValue(stepRef);
@@ -203,14 +203,38 @@ public class StepParser {
boolean isFaultTolerant = false;
String faultTolerant = element.getAttribute("fault-tolerant");
if ("true".equals(faultTolerant)) {
// TODO determine if step should be fault-tolerant
String skipLimit = element.getAttribute("skip-limit");
if (!isFaultTolerant) {
isFaultTolerant = checkIntValueForFaultToleranceNeeded(skipLimit);
}
String retryLimit = element.getAttribute("retry-limit");
if (!isFaultTolerant) {
isFaultTolerant = checkIntValueForFaultToleranceNeeded(retryLimit);
}
String cacheCapacity = element.getAttribute("cache-capacity");
if (!isFaultTolerant) {
isFaultTolerant = checkIntValueForFaultToleranceNeeded(cacheCapacity);
}
String isReaderTransactionalQueue = element.getAttribute("is-reader-transactional-queue");
if (!isFaultTolerant && StringUtils.hasText(isReaderTransactionalQueue)) {
if ("true".equals(isReaderTransactionalQueue)) {
isFaultTolerant = true;
}
}
checkExceptionElementForFaultToleranceNeeded(element, "skippable-exception-classes");
checkExceptionElementForFaultToleranceNeeded(element, "retryable-exception-classes");
checkExceptionElementForFaultToleranceNeeded(element, "fatal-exception-classes");
if (isFaultTolerant) {
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);
}
// now, set the properties on the new bean
String readerBeanId = element.getAttribute("reader");
if (StringUtils.hasText(readerBeanId)) {
RuntimeBeanReference readerRef = new RuntimeBeanReference(readerBeanId);
@@ -248,41 +272,24 @@ public class StepParser {
bd.getPropertyValues().addPropertyValue("commitInterval", commitInterval);
}
String skipLimit = element.getAttribute("skip-limit");
if (StringUtils.hasText(skipLimit)) {
if (!isFaultTolerant) {
throw new BeanCreationException("skip-limit can only be specified if fault-tolerant is set to \"true\"");
}
bd.getPropertyValues().addPropertyValue("skipLimit", skipLimit);
}
String retryLimit = element.getAttribute("retry-limit");
if (StringUtils.hasText(retryLimit)) {
if (!isFaultTolerant) {
throw new BeanCreationException("retry-limit can only be specified if fault-tolerant is set to \"true\"");
}
bd.getPropertyValues().addPropertyValue("retryLimit", retryLimit);
}
String cacheCapacity = element.getAttribute("cache-capacity");
if (StringUtils.hasText(cacheCapacity)) {
if (!isFaultTolerant) {
throw new BeanCreationException("cache-capacity can only be specified if fault-tolerant is set to \"true\"");
}
bd.getPropertyValues().addPropertyValue("cacheCapacity", cacheCapacity);
}
String transactionAttribute = element.getAttribute("transaction-attribute");
if (StringUtils.hasText(transactionAttribute)) {
handleTransactionAttributesElement(element, bd);
bd.getPropertyValues().addPropertyValue("transactionAttribute", transactionAttribute);
}
String isReaderTransactionalQueue = element.getAttribute("is-reader-transactional-queue");
if (StringUtils.hasText(isReaderTransactionalQueue)) {
if (!isFaultTolerant && "true".equals(isReaderTransactionalQueue)) {
throw new BeanCreationException("is-reader-transactional-queue=\"true\" can only be specified if fault-tolerant is set to \"true\"");
}
if (isFaultTolerant) {
bd.getPropertyValues().addPropertyValue("isReaderTransactionalQueue", isReaderTransactionalQueue);
}
@@ -290,9 +297,9 @@ public class StepParser {
handleExceptionElement(element, bd, "skippable-exception-classes", "skippableExceptionClasses", isFaultTolerant);
handleExceptionElement(element, bd, "retryable-exception-classes", "retryableExceptionClasses",isFaultTolerant);
handleExceptionElement(element, bd, "retryable-exception-classes", "retryableExceptionClasses", isFaultTolerant);
handleExceptionElement(element, bd, "fatal-exception-classes", "fatalExceptionClasses",isFaultTolerant);
handleExceptionElement(element, bd, "fatal-exception-classes", "fatalExceptionClasses", isFaultTolerant);
handleListenersElement(element, bd, parserContext);
@@ -309,16 +316,32 @@ public class StepParser {
}
private void handleTransactionAttributesElement(Element element, RootBeanDefinition bd) {
private boolean checkIntValueForFaultToleranceNeeded(String stringValue) {
if (StringUtils.hasText(stringValue)) {
int value = Integer.valueOf(stringValue);
if (value > 0) {
return true;
}
}
return false;
}
private boolean checkExceptionElementForFaultToleranceNeeded(Element element, String subElementName) {
String exceptions =
DomUtils.getChildElementValueByTagName(element, subElementName);
if (StringUtils.hasLength(exceptions)) {
return true;
}
return false;
}
private void handleExceptionElement(Element element, RootBeanDefinition bd,
String attributeName, String propertyName, boolean isFaultTolerant) {
String subElementName, String propertyName, boolean isFaultTolerant) {
String exceptions =
DomUtils.getChildElementValueByTagName(element, attributeName);
DomUtils.getChildElementValueByTagName(element, subElementName);
if (StringUtils.hasLength(exceptions)) {
if (!isFaultTolerant) {
throw new BeanCreationException(attributeName + " can only be specified if fault-tolerant is set to \"true\"");
throw new BeanCreationException(subElementName + " can only be specified if fault-tolerant is set to \"true\"");
}
String[] exceptionArray = StringUtils.tokenizeToStringArray(
StringUtils.delete(exceptions, ","), "\n");

View File

@@ -211,7 +211,7 @@
<xsd:extension base="nextType">
<xsd:sequence>
<xsd:choice>
<xsd:element name="process-task" type="processTaskType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="item-task" type="itemTaskType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="simple-task" type="simpleTaskType" minOccurs="0" maxOccurs="1"/>
</xsd:choice>
<xsd:group ref="transitions"/>
@@ -243,7 +243,7 @@
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="processTaskType">
<xsd:complexType name="itemTaskType">
<xsd:complexContent>
<xsd:extension base="stepDefType">
<xsd:sequence>
@@ -331,14 +331,6 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<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[

View File

@@ -8,8 +8,8 @@
<job id="job">
<step name="ft-step">
<process-task reader="reader" processor="processor" writer="writer"
fault-tolerant="false" commit-interval="10">
<item-task reader="reader" processor="processor" writer="writer"
commit-interval="10">
<listeners>
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
<listener ref="listener"/>
@@ -17,7 +17,7 @@
<streams>
<stream ref="reader"/>
</streams>
</process-task>
</item-task>
</step>
</job>

View File

@@ -8,8 +8,8 @@
<job id="job">
<step name="step">
<process-task reader="reader" processor="processor" writer="writer"
fault-tolerant="true" commit-interval="10" skip-limit="20"
<item-task reader="reader" processor="processor" writer="writer"
commit-interval="10" skip-limit="20"
retry-limit="3" cache-capacity="100"
transaction-attribute="PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_10,-org.springframework.dao.DataIntegrityViolationException"
is-reader-transactional-queue="true"
@@ -24,7 +24,7 @@
<streams>
<stream ref="reader"/>
</streams>
</process-task>
</item-task>
</step>
</job>

View File

@@ -83,7 +83,7 @@ public class RemoteLauncherTests {
assertTrue(launcher.getJobNames().contains("loopJob"));
}
@Test
//@Test
public void testPauseJob() throws Exception {
final int SLEEP_INTERVAL = 600;
assertTrue(isConnected());