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

Change StepBuilerHelper#enhance parameter type to AbstractStep #4220

Closed
wants to merge 1 commit into from

Conversation

acktsap
Copy link
Contributor

@acktsap acktsap commented Oct 25, 2022

This commit moves StepBuilerHelper#enhance method to AbstractStep. It removes unnecessary casting to AbstractStep.

Currently, changing argument type to AbstractStep is enough. But until 4.3.x, there were another casting code (It’s been removed by 7c8fb17). But there may be similar cases in future.

By moving enhance method to AbstractStep, we can use like followings for those cases.

// in TaskletStep
@Override
public void enhance(StepProperties properties) {
    super.enhance(properties);
    this.transactionManager = properties.getTransactionManager();
}

This also can be applied to JobBuilderHelper.

I also extracted StepProperties to prevent dependency cycle (org.springframework.batch.core.step.builder <-> org.springframework.batch.core.step)

@fmbenhassine
Copy link
Contributor

Thank you for the PR. Could you please rebase it in on the latest main? Please note that we added an ObservationRegistry and MeterRegistry properties in CommonStepProperties, please make sure to include them in your rebase.

Any reason you renamed CommonStepProperties to StepProperties? I think we should keep the name CommonStepProperties to be consistent with the naming of CommonJobProperties for jobs.

This also can be applied to JobBuilderHelper.

Please open a separate PR for this enhancement. Thank you upfront.

@fmbenhassine fmbenhassine added the status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter label Nov 8, 2022
@acktsap
Copy link
Contributor Author

acktsap commented Nov 12, 2022

Rebased and add ObservationRegistry, MeterRegistry. Renamed to CommonStepProperties back.
I'll make a pr for JobBuilderHelper soon.

@fmbenhassine fmbenhassine removed the status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter label Nov 17, 2022
@fmbenhassine
Copy link
Contributor

Thank you for the update. I did not review this PR in details until you rebased it.

Looking at the change, you moved the enhance method from the builder to the step:

--builder.enhance(step);
++step.enhance(commonStepProperties);

That method is actually configuring/enhancing the step with some properties, and I believe this is the role of the builder, not the step itself. The step can provide setters for its properties, but not a public method enhance (currently, that method is protected in the builder). The addition of a new public method AbstractStep#enhance(CommonStepProperties) means that, as a user, I would need to instantiate CommonStepProperties and call myStep.enhance(properties) for things to work. This is not the case with the current way of configuring steps through the builder.

In my opinion, the way to remove the cast to AbstractStep in StepBuilderHelper#enhance is by changing the parameter type to AbstractStep, because all builders inheriting from StepBuilderHelper currently create AbstractStep types anyway, and that method does nothing for other step types anyway:

protected void enhance(Step target) {
   if (target instanceOf AbstractStep) {
      // configure AbstractStep
   } 

   // Nothing is done for other step types, so this method has no added value for other step types anyway

}

So I guess the way to remove the cast can be achieved like:

--protected void enhance(Step target) {
++protected void enhance(AbstractStep target) {

---   if (target instanceOf AbstractStep) {

---   }

}

I tried this change on the main branch and things seem to work as expected. What do you think?

@fmbenhassine fmbenhassine added the status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter label Nov 17, 2022
@acktsap
Copy link
Contributor Author

acktsap commented Nov 17, 2022

That method is actually configuring/enhancing the step with some properties, and I believe this is the role of the builder, not the step itself. The step can provide setters for its properties, but not a public method enhance (currently, that method is protected in the builder)

Make sense. I thought changing parameter type to AbstractStep at first. Then can i make the change (just change the parameter type) in this pr and #4231?

@fmbenhassine
Copy link
Contributor

Then can i make the change (just change the parameter type) in this pr and #4231?

Yes please. It should be good to merge if all tests pass. Thank you upfront!

@acktsap
Copy link
Contributor Author

acktsap commented Nov 17, 2022

Done

@acktsap acktsap changed the title Move enhance method to AbstractStep Change StepBuilerHelper#enhance parameter type to AbstractStep Nov 17, 2022
@fmbenhassine fmbenhassine removed the status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter label Nov 22, 2022
@fmbenhassine
Copy link
Contributor

Rebased and merged as 3385a19. Thank you for your contribution!

@fmbenhassine fmbenhassine added this to the 5.0.0 milestone Nov 22, 2022
@acktsap acktsap deleted the add-enhance-to-step branch November 22, 2022 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants