Skip to content

Commit

Permalink
Add default methods in Job and Step interfaces
Browse files Browse the repository at this point in the history
Default values are consistent with AbstractJob
and AbstractStep.

Issue #3924
  • Loading branch information
fmbenhassine committed May 9, 2022
1 parent 9f4424f commit 74e8caa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.batch.core;

import org.springframework.batch.core.job.DefaultJobParametersValidator;
import org.springframework.lang.Nullable;

/**
Expand All @@ -33,9 +34,11 @@ public interface Job {
/**
* Flag to indicate if this job can be restarted, at least in principle.
*
* @return true if this job can be restarted after a failure
* @return true if this job can be restarted after a failure. Defaults to {@code true}.
*/
boolean isRestartable();
default boolean isRestartable() {
return true;
}

/**
* Run the {@link JobExecution} and update the meta information, such as status
Expand All @@ -52,19 +55,23 @@ public interface Job {
* sequence, they can use this incrementer. The return value may be {@code null},
* when this job does not have a natural sequence.
*
* @return in incrementer to be used for creating new parameters
* @return an incrementer to be used for creating new parameters. Defaults to {@code null}.
*/
@Nullable
JobParametersIncrementer getJobParametersIncrementer();
default JobParametersIncrementer getJobParametersIncrementer() {
return null;
}

/**
* A validator for the job parameters of a {@link JobExecution}. Clients of
* a {@code Job} may need to validate the parameters for a launch or before or during
* the execution.
*
* @return a validator that can be used to check parameter values (never
* {@code null}).
* {@code null}). Defaults to {@link DefaultJobParametersValidator}.
*/
JobParametersValidator getJobParametersValidator();
default JobParametersValidator getJobParametersValidator() {
return new DefaultJobParametersValidator();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* explicitly represent the configuration of a step by a developer but also the ability to execute the step.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public interface Step {
Expand All @@ -36,13 +37,19 @@ public interface Step {

/**
* @return {@code true} if a step that is already marked as complete can be started again.
* Defaults to {@code false}.
*/
boolean isAllowStartIfComplete();
default boolean isAllowStartIfComplete() {
return false;
}

/**
* @return the number of times a job can be started with the same identifier.
* @return the number of times a step can be (re)started for the same job instance.
* Defaults to {@code Integer.MAX_VALUE}
*/
int getStartLimit();
default int getStartLimit() {
return Integer.MAX_VALUE;
}

/**
* Process the step and assign progress and status meta information to the {@link StepExecution} provided. The
Expand Down

0 comments on commit 74e8caa

Please sign in to comment.