27
27
import org .apache .commons .logging .LogFactory ;
28
28
29
29
import org .springframework .batch .core .BatchStatus ;
30
- import org .springframework .batch .core .Job ;
31
- import org .springframework .batch .core .JobExecution ;
32
- import org .springframework .batch .core .JobExecutionException ;
33
- import org .springframework .batch .core .JobParameter ;
34
- import org .springframework .batch .core .JobParameters ;
35
- import org .springframework .batch .core .JobParametersBuilder ;
36
- import org .springframework .batch .core .JobParametersInvalidException ;
37
30
import org .springframework .batch .core .configuration .JobRegistry ;
38
31
import org .springframework .batch .core .converter .DefaultJobParametersConverter ;
39
32
import org .springframework .batch .core .converter .JobParametersConverter ;
40
- import org .springframework .batch .core .explore .JobExplorer ;
41
- import org .springframework .batch .core .launch .JobLauncher ;
33
+ import org .springframework .batch .core .job .Job ;
34
+ import org .springframework .batch .core .job .JobExecution ;
35
+ import org .springframework .batch .core .job .JobExecutionException ;
36
+ import org .springframework .batch .core .job .parameters .JobParameter ;
37
+ import org .springframework .batch .core .job .parameters .JobParameters ;
38
+ import org .springframework .batch .core .job .parameters .JobParametersBuilder ;
39
+ import org .springframework .batch .core .job .parameters .JobParametersInvalidException ;
40
+ import org .springframework .batch .core .launch .JobOperator ;
41
+ import org .springframework .batch .core .launch .NoSuchJobException ;
42
42
import org .springframework .batch .core .repository .JobExecutionAlreadyRunningException ;
43
43
import org .springframework .batch .core .repository .JobInstanceAlreadyCompleteException ;
44
44
import org .springframework .batch .core .repository .JobRepository ;
55
55
import org .springframework .util .StringUtils ;
56
56
57
57
/**
58
- * {@link ApplicationRunner} to {@link JobLauncher launch} Spring Batch jobs. If a single
58
+ * {@link ApplicationRunner} to {@link JobOperator launch} Spring Batch jobs. If a single
59
59
* job is found in the context, it will be executed by default. If multiple jobs are
60
60
* found, launch a specific job by providing a jobName.
61
61
*
@@ -78,9 +78,7 @@ public class JobLauncherApplicationRunner
78
78
79
79
private JobParametersConverter converter = new DefaultJobParametersConverter ();
80
80
81
- private final JobLauncher jobLauncher ;
82
-
83
- private final JobExplorer jobExplorer ;
81
+ private final JobOperator jobOperator ;
84
82
85
83
private final JobRepository jobRepository ;
86
84
@@ -96,17 +94,14 @@ public class JobLauncherApplicationRunner
96
94
97
95
/**
98
96
* Create a new {@link JobLauncherApplicationRunner}.
99
- * @param jobLauncher to launch jobs
100
- * @param jobExplorer to check the job repository for previous executions
97
+ * @param jobOperator to launch jobs
101
98
* @param jobRepository to check if a job instance exists with the given parameters
102
99
* when running a job
103
100
*/
104
- public JobLauncherApplicationRunner (JobLauncher jobLauncher , JobExplorer jobExplorer , JobRepository jobRepository ) {
105
- Assert .notNull (jobLauncher , "'jobLauncher' must not be null" );
106
- Assert .notNull (jobExplorer , "'jobExplorer' must not be null" );
101
+ public JobLauncherApplicationRunner (JobOperator jobOperator , JobRepository jobRepository ) {
102
+ Assert .notNull (jobOperator , "'jobOperator' must not be null" );
107
103
Assert .notNull (jobRepository , "'jobRepository' must not be null" );
108
- this .jobLauncher = jobLauncher ;
109
- this .jobExplorer = jobExplorer ;
104
+ this .jobOperator = jobOperator ;
110
105
this .jobRepository = jobRepository ;
111
106
}
112
107
@@ -204,28 +199,31 @@ private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecut
204
199
}
205
200
}
206
201
207
- protected void execute (Job job , JobParameters jobParameters ) throws JobExecutionAlreadyRunningException ,
208
- JobRestartException , JobInstanceAlreadyCompleteException , JobParametersInvalidException {
202
+ protected void execute (Job job , JobParameters jobParameters )
203
+ throws JobExecutionAlreadyRunningException , NoSuchJobException , JobRestartException ,
204
+ JobInstanceAlreadyCompleteException , JobParametersInvalidException {
209
205
JobParameters parameters = getNextJobParameters (job , jobParameters );
210
- JobExecution execution = this .jobLauncher . run (job , parameters );
206
+ JobExecution execution = this .jobOperator . start (job , parameters );
211
207
if (this .publisher != null ) {
212
208
this .publisher .publishEvent (new JobExecutionEvent (execution ));
213
209
}
214
210
}
215
211
212
+ @ SuppressWarnings ("deprecated" )
216
213
private JobParameters getNextJobParameters (Job job , JobParameters jobParameters ) {
217
- if (this .jobRepository != null && this .jobRepository .isJobInstanceExists (job .getName (), jobParameters )) {
214
+ if (this .jobRepository != null && this .jobRepository .getJobInstance (job .getName (), jobParameters ) != null ) {
218
215
return getNextJobParametersForExisting (job , jobParameters );
219
216
}
220
217
if (job .getJobParametersIncrementer () == null ) {
221
218
return jobParameters ;
222
219
}
223
- JobParameters nextParameters = new JobParametersBuilder (jobParameters , this .jobExplorer )
220
+ JobParameters nextParameters = new JobParametersBuilder (jobParameters , this .jobRepository )
224
221
.getNextJobParameters (job )
225
222
.toJobParameters ();
226
223
return merge (nextParameters , jobParameters );
227
224
}
228
225
226
+ @ SuppressWarnings ("deprecated" )
229
227
private JobParameters getNextJobParametersForExisting (Job job , JobParameters jobParameters ) {
230
228
JobExecution lastExecution = this .jobRepository .getLastJobExecution (job .getName (), jobParameters );
231
229
if (isStoppedOrFailed (lastExecution ) && job .isRestartable ()) {
0 commit comments