Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more intuitive java configurations for conditional flows [BATCH-2755] #849

Closed
spring-issuemaster opened this issue Sep 9, 2018 · 5 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Sep 9, 2018

Minhyeok Jeong opened BATCH-2755 and commented

Let's assume we have a job which has the flow scenario, as shown in the following image:

!flow.png!

Its configurations are as follows respectively:

  • XML Configuration
<job id="job">
    <step id="stepA" parent="s1">
        <next on="*" to="stepB" />
        <next on="FAILED" to="stepC" />
    </step>
    <step id="stepB" parent="s2" next="stepC" />
    <step id="stepC" parent="s3" next="stepD" />
    <step id="stepD" parent="s4" />
</job>
  • Java Configuration
@Bean
public Job job() {
    return this.jobBuilderFactory.get("job")
        .start(stepA())
        .on("FAILED").to(stepC())
        .from(stepA()).on("*").to(stepB())
        .next(stepC())
        .next(stepD())
        .end()
        .build();
}

Java configuration is quite complicated and hard to understand in comparison with XML configuration.

 

So I would like to suggest new Java configuration syntax, as shown in the following example:

@Bean public Job job() {
    return this.jobBuilderFactory.get("job")
        .start(stepA())
        .conditional()
            .on("*").to(stepB())
            .on("FAILED").to(stepC())
        .end()
        .next(stepC())
        .next(stepD())
        .end()
        .build();
}

 

To make it work, we would have to add new class and methods, e.g.:

ConditionalFlowBuilder JobBuilder.conditional();

public class ConditionalFlowBuilder {
    ConditionalFlowBuilder on(String pattern);
    ConditionalFlowBuilder to(...);
    JobBuilder end();
}

Affects: 4.1.0

Attachments:

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 29, 2018

Dimitrios Liapis commented

Mahmoud Ben Hassine Would that make sense? If so I could take a look

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 29, 2018

Michael Minella commented

What would you envision for a way for this to be backwards compatible?  Otherwise it would be too big of a breaking change to include in a point release.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 29, 2018

Dimitrios Liapis commented

Michael Minella thanks for the hint - I see your point.

Let me think about it and come back if I come up with something meaningful

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 4, 2018

Mahmoud Ben Hassine commented

@Minhyeok Jeong You are building a flow job but you are starting it with the start method and not the flow method. The example you provided can be implemented as follows:

@Bean
public Job job() {
	return this.jobBuilderFactory.get("job")
			   .flow(stepA()).on("FAILED").to(stepC())
			   .from(stepA()).on("*").to(stepB())
			   .from(stepB()).next(stepC())
			   .from(stepC()).next(stepD())
			   .end()
			.build();
}

This snippet reads exactly as the XML sample and is IMO intuitive and not complicated/hard to understand. Do you agree?

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 8, 2019

Mahmoud Ben Hassine commented

Closing this as explained in my previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.