Java Reference
In-Depth Information
"No bootstrap parameters found from incrementer for job="
+ jobIdentifier);
}
} else {
jobParameters = incrementer.getNext(lastInstances.get(0)
.getJobParameters());
}
return jobParameters;
}
public void setJobLauncher(JobLauncher jobLauncher) {
this.jobLauncher = jobLauncher;
}
public void setJobLocator(JobLocator jobLocator) {
this.jobLocator = jobLocator;
}
public void setJobParameters(Map<String, String> jobParameters) {
this.jobParameters = jobParameters;
}
public void setJobExplorer(JobExplorer jobExplorer) {
this.jobExplorer = jobExplorer;
}
}
As you look over this code, notice that there are many clashes in class names between Quartz and
Spring Batch. To understand what is going on, let's start by looking at the execution environment's
structure. You have a single class that extends Spring's QuartzJobBean . This implementation of Quartz's
org.quartz.Job interface is a helpful class that allows you to implement only the pieces of logic that
pertain to your work, leaving the manipulation of the scheduler and so on to Spring. In this case, you
override the executeInternal method from which to execute the job.
Within the executeInternal method, you begin by obtaining the JobDataMap , which is a Map of
parameters you pass in to the Quartz job via your Spring configuration (you look at the configuration
after this class is covered). This Map contains all the dependencies that are injected into the
SpringBatchQuartzJobLauncher class as well as any additional parameters you may want to reference. In
this case, you want to reference one other parameter: the name of the job.
With the name of the job obtained, you use the JobLocator to retrieve the Spring Batch job from the
JobRegistry . Before you can execute the job you need to convert the parameters passed via Spring as a
Map of <String, String> into a Spring Batch JobParameters collection. Once that is complete, you can
execute the job using the JobLauncher .
Notice that the actual execution of the job in this class doesn't take much in the way of code. The
vast majority of this class is dedicated to the conversion and incrementing of the job's parameters. The
other two methods, translateParams and getNextJobParameters are used to translate the parameters you
receive from Spring into JobParameters and call the configured parameter incrementer.
translateParams begins by creating an instance of Spring Batch's
org.springframework.batch.core.JobParametersBuilder . This class is used to take key value pairs and
 
Search WWH ::




Custom Search