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
@@ -199,23 +194,24 @@ private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecut
199
194
}
200
195
}
201
196
202
- protected void execute (Job job , JobParameters jobParameters ) throws JobExecutionAlreadyRunningException ,
203
- JobRestartException , JobInstanceAlreadyCompleteException , JobParametersInvalidException {
197
+ protected void execute (Job job , JobParameters jobParameters )
198
+ throws JobExecutionAlreadyRunningException , NoSuchJobException , JobRestartException ,
199
+ JobInstanceAlreadyCompleteException , JobParametersInvalidException {
204
200
JobParameters parameters = getNextJobParameters (job , jobParameters );
205
- JobExecution execution = this .jobLauncher . run (job , parameters );
201
+ JobExecution execution = this .jobOperator . start (job , parameters );
206
202
if (this .publisher != null ) {
207
203
this .publisher .publishEvent (new JobExecutionEvent (execution ));
208
204
}
209
205
}
210
206
211
207
private JobParameters getNextJobParameters (Job job , JobParameters jobParameters ) {
212
- if (this .jobRepository != null && this .jobRepository .isJobInstanceExists (job .getName (), jobParameters )) {
208
+ if (this .jobRepository != null && this .jobRepository .getJobInstance (job .getName (), jobParameters ) != null ) {
213
209
return getNextJobParametersForExisting (job , jobParameters );
214
210
}
215
211
if (job .getJobParametersIncrementer () == null ) {
216
212
return jobParameters ;
217
213
}
218
- JobParameters nextParameters = new JobParametersBuilder (jobParameters , this .jobExplorer )
214
+ JobParameters nextParameters = new JobParametersBuilder (jobParameters , this .jobRepository )
219
215
.getNextJobParameters (job )
220
216
.toJobParameters ();
221
217
return merge (nextParameters , jobParameters );
0 commit comments