Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

java-ee - 具有许多可选步骤的JEE批处理作业规范(JEE Batch Job Specification with many optional Steps)

Is there a way to achieve the following logic with JSR 352 Batch API?

(有没有办法使用JSR 352 Batch API实现以下逻辑?)

I have a series of Steps that each need to be executed based on a different condition known when starting the job.

(我有一系列步骤,每个步骤都需要根据开始工作时已知的不同条件执行。)

ConditionsEntity is provided by an external system.

(ConditionsEntity由外部系统提供。)

public List<Steps> createStepSequence(ConditionsEntity conditions) {
  if (conditions.isStep1Enabled()) {
    steps.add(step1)
  }
  if (conditions.isStep2Enabled()) {
    steps.add(step2)
  }
  if (conditions.isStep3Enabled()) {
    steps.add(step3)
  }
  //many more ifs

return steps;
}

My first attempt fails because of: com.ibm.jbatch.container.exception.BatchContainerRuntimeException: A decision cannot precede another decision.

(我的第一次尝试失败,原因是:com.ibm.jbatch.container.exception.BatchContainerRuntimeException:一个决定不能先于另一个决定。)

I'm adding the FAILING Code here

(我在这里添加失败代码)

<?xml version="1.0" encoding="UTF-8"?>
<job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd" version="1.0">
    <properties>
        <property name="isExecuteStep2" value="false"/>
        <property name="isExecuteStep3" value="false"/>
    </properties>
    <step id="step1" next="decider1">
        <batchlet ref="myBatchlet1"/>
    </step>
    <decision id="decider1" ref="SkipNextStepDecider">
        <properties>
            <property name="isExecuteNextStep" value="#{jobProperties['isExecuteStep2']}"/>
        </properties>
        <next on="EXECUTE" to="step2"/>
        <next on="SKIP" to="decider2"/>
    </decision>
    <step id="step2">
        <batchlet ref="myBatchlet2"/>
    </step>
    <decision id="decider2" ref="SkipNextStepDecider">
        <properties>
            <property name="isExecuteNextStep" value="#{jobProperties['isExecuteStep3']}"/>
        </properties>
        <next on="EXECUTE" to="step3"/>
        <end on="SKIP"/>
    </decision>
    <step id="step3">
        <batchlet ref="myBatchlet3"/>
    </step>
</job>


@Named
public class SkipNextStepDecider implements Decider {

    @Inject
    @BatchProperty
    private String isExecuteNextStep;

    @Override
    public String decide(StepExecution[] ses) throws Exception {
        if (isExecuteNextStep.equalsIgnoreCase("true")) {
            return "EXECUTE";
        } else {
            return "SKIP";
        }
    }
}
  ask by taranaki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It looks like the failure was caused by the fact that one decision had another decison as its next execution point at runtime.

(看起来失败是由于一个决定在运行时将另一个决定作为下一个执行点而造成的。)

As per the JSR 352 spec Section 8.5, it should be a supported use case:

(根据JSR 352规范8.5节,它应该是受支持的用例:)

A job may contain any number of decision elements.

(作业可以包含任何数量的决策元素。)

A decision element is the target of the "next" attribute from a job-level step, flow, split, or another decision.

(决策元素是作业级步骤,流程,拆分或其他决策中“下一个”属性的目标。)

As a workaround, you can try having a pass-through batchlet-step that contains the same condition and logic.

(作为一种解决方法,您可以尝试使用传递批处理步骤,该步骤包含相同的条件和逻辑。)

For example,

(例如,)

<step id="pass-through-step">
   <batchlet ref="PassThroughBatchlet"/>
   <next on="EXECUTE" to="step2"/>
   <next on="SKIP" to="decider2"/>
</step>

Or if some of your conditional logic can be achived with a batchlet-step containing transition elements, you can do away with those decisions.

(或者,如果可以通过包含过渡元素的批处理步骤来实现某些条件逻辑,则可以取消这些决策。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...