Add default methods in Job and Step interfaces

Default values are consistent with AbstractJob
and AbstractStep.

Issue #3924
This commit is contained in:
Mahmoud Ben Hassine
2022-05-09 10:29:57 +02:00
parent 9f4424f4fa
commit 74e8caa368
2 changed files with 23 additions and 9 deletions

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.batch.core;
import org.springframework.batch.core.job.DefaultJobParametersValidator;
import org.springframework.lang.Nullable;
/**
@@ -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
@@ -52,10 +55,12 @@ 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
@@ -63,8 +68,10 @@ public interface Job {
* 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();
}
}

View File

@@ -20,6 +20,7 @@ package org.springframework.batch.core;
* 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 {
@@ -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