BATCH-1136: Add setListeners(StepExecutionListener[]) to TaskletStep so that the parser will be able to set <listeners/> consistently on steps using the "listeners" property.

This commit is contained in:
dhgarrette
2009-03-12 17:48:54 +00:00
parent 9729ca23fd
commit 30c6584e08
6 changed files with 26 additions and 19 deletions

View File

@@ -64,7 +64,7 @@ public abstract class AbstractStepParser {
bd.getPropertyValues().addPropertyValue("tasklet", taskletBeanRef);
}
setUpBeanDefinition(stepElement, bd, parserContext, jobRepositoryRef, "stepExecutionListeners");
setUpBeanDefinition(stepElement, bd, parserContext, jobRepositoryRef);
return bd;
@@ -78,13 +78,13 @@ public abstract class AbstractStepParser {
ParserContext parserContext, String jobRepositoryRef) {
AbstractBeanDefinition bd = taskletElementParser.parseTaskletElement(element, parserContext);
setUpBeanDefinition(stepElement, bd, parserContext, jobRepositoryRef, "listeners");
setUpBeanDefinition(stepElement, bd, parserContext, jobRepositoryRef);
return bd;
}
protected void setUpBeanDefinition(Element stepElement, AbstractBeanDefinition bd, ParserContext parserContext,
String jobRepositoryRef, String listenersPropertyNames) {
String jobRepositoryRef) {
checkStepAttributes(stepElement, bd);
RuntimeBeanReference jobRepositoryBeanRef = new RuntimeBeanReference(jobRepositoryRef);
@@ -94,7 +94,7 @@ public abstract class AbstractStepParser {
RuntimeBeanReference transactionManagerBeanRef = new RuntimeBeanReference(transactionManagerRef);
bd.getPropertyValues().addPropertyValue("transactionManager", transactionManagerBeanRef);
handleListenersElement(stepElement, bd, parserContext, listenersPropertyNames);
handleListenersElement(stepElement, bd, parserContext);
bd.setRole(BeanDefinition.ROLE_SUPPORT);
@@ -117,8 +117,7 @@ public abstract class AbstractStepParser {
}
@SuppressWarnings("unchecked")
private void handleListenersElement(Element element, BeanDefinition bd, ParserContext parserContext,
String propertyName) {
private void handleListenersElement(Element element, BeanDefinition bd, ParserContext parserContext) {
Element listenersElement = DomUtils.getChildElementByTagName(element, "listeners");
if (listenersElement != null) {
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(listenersElement.getTagName(),
@@ -132,7 +131,7 @@ public abstract class AbstractStepParser {
listenerBeans.add(stepListenerParser.parse(listenerElement, parserContext));
}
}
bd.getPropertyValues().addPropertyValue(propertyName, listenerBeans);
bd.getPropertyValues().addPropertyValue("listeners", listenerBeans);
parserContext.popAndRegisterContainingComponent();
}
}

View File

@@ -58,7 +58,7 @@ public class StandaloneStepParser extends AbstractStepParser {
}
else {
bd = new GenericBeanDefinition();
setUpBeanDefinition(element, bd, parserContext, jobRepositoryRef, "listeners");
setUpBeanDefinition(element, bd, parserContext, jobRepositoryRef);
}
bd.setAbstract(Boolean.valueOf(element.getAttribute("abstract")));

View File

@@ -32,6 +32,7 @@ import org.springframework.batch.core.scope.context.StepContextRepeatCallback;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.core.step.StepInterruptionPolicy;
import org.springframework.batch.core.step.ThreadStepInterruptionPolicy;
import org.springframework.batch.core.step.item.SimpleStepFactoryBean;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
@@ -216,6 +217,20 @@ public class TaskletStep extends AbstractStep {
this.interruptionPolicy = interruptionPolicy;
}
/**
* Variation on
* {@link AbstractStep#setStepExecutionListeners(StepExecutionListener[])}.
* This method exists because the parser requires a "listeners" property
* setter to match the one on {@link SimpleStepFactoryBean}.
*
* @param listeners
* @see AbstractStep#setStepExecutionListeners(StepExecutionListener[])
* @see SimpleStepFactoryBean#setListeners(org.springframework.batch.core.StepListener[])
*/
public void setListeners(StepExecutionListener[] listeners) {
this.setStepExecutionListeners(listeners);
}
/**
* Process the step and update its context so that progress can be monitored
* by the caller. The step is broken down into chunks, each one executing in

View File

@@ -18,7 +18,7 @@
<step-listener id="toplevel" class="org.springframework.batch.core.configuration.xml.DummyAnnotationStepExecutionListener"/>
<beans:bean id="baseStep" abstract="true">
<beans:property name="stepExecutionListeners">
<beans:property name="listeners">
<beans:list>
<step-listener class="org.springframework.batch.core.listener.CompositeStepExecutionListener"/>
</beans:list>

View File

@@ -18,7 +18,7 @@
<step-listener id="toplevel" class="org.springframework.batch.core.listener.StepExecutionListenerSupport"/>
<beans:bean id="baseStep" abstract="true">
<beans:property name="stepExecutionListeners">
<beans:property name="listeners">
<beans:list>
<step-listener class="org.springframework.batch.core.listener.CompositeStepExecutionListener"/>
</beans:list>

View File

@@ -11,7 +11,7 @@
<tasklet reader="reader" writer="writer" commit-interval="5"/>
</step>
<step id="s2" ref="standalone2" next="s3"/>
<step id="s3" parent="baseTaskletStep" tasklet="dummyTasklet" next="s4"/>
<step id="s3" parent="baseStep" tasklet="dummyTasklet" next="s4"/>
<step id="s4" ref="standalone4"/>
</job>
@@ -19,7 +19,7 @@
<tasklet reader="reader" writer="writer" commit-interval="5"/>
</step>
<step id="standalone4" tasklet="dummyTasklet" parent="baseTaskletStep">
<step id="standalone4" tasklet="dummyTasklet" parent="baseStep">
<tasklet reader="reader" writer="writer" commit-interval="5"/>
</step>
@@ -28,12 +28,5 @@
<listener class="org.springframework.batch.core.listener.StepExecutionListenerSupport"/>
</listeners>
</step>
<!-- TODO: Use baseStep instead once BATCH-1136 is implemented -->
<beans:bean id="baseTaskletStep" abstract="true">
<beans:property name="stepExecutionListeners">
<beans:bean class="org.springframework.batch.core.listener.StepExecutionListenerSupport"/>
</beans:property>
</beans:bean>
</beans:beans>