Class JobBuilder
- java.lang.Object
-
- org.quartz.JobBuilder
-
public class JobBuilder extends java.lang.ObjectJobBuilderis used to instantiateJobDetails.The builder will always try to keep itself in a valid state, with reasonable defaults set for calling build() at any point. For instance if you do not invoke withIdentity(..) a job name will be generated for you.
Quartz provides a builder-style API for constructing scheduling-related entities via a Domain-Specific Language (DSL). The DSL can best be utilized through the usage of static imports of the methods on the classes
TriggerBuilder,JobBuilder,DateBuilder,JobKey,TriggerKeyand the variousScheduleBuilderimplementations.Client code can then use the DSL to write code such as this:
JobDetail job = newJob(MyJob.class) .withIdentity("myJob") .build(); Trigger trigger = newTrigger() .withIdentity(triggerKey("myTrigger", "myTriggerGroup")) .withSchedule(simpleSchedule() .withIntervalInHours(1) .repeatForever()) .startAt(futureDate(10, MINUTES)) .build(); scheduler.scheduleJob(job, trigger);- See Also:
TriggerBuilder,DateBuilder,JobDetail
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJobBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JobDetailbuild()Produce theJobDetailinstance defined by thisJobBuilder.static JobBuildernewJob()Create a JobBuilder with which to define aJobDetail.static JobBuildernewJob(java.lang.Class<? extends Job> jobClass)Create a JobBuilder with which to define aJobDetail, and set the class name of theJobto be executed.JobBuilderofType(java.lang.Class<? extends Job> jobClazz)Set the class which will be instantiated and executed when a Trigger fires that is associated with this JobDetail.JobBuilderrequestRecovery()Instructs theSchedulerwhether or not theJobshould be re-executed if a 'recovery' or 'fail-over' situation is encountered.JobBuilderrequestRecovery(boolean jobShouldRecover)Instructs theSchedulerwhether or not theJobshould be re-executed if a 'recovery' or 'fail-over' situation is encountered.JobBuildersetJobData(JobDataMap newJobDataMap)JobBuilderstoreDurably()Whether or not theJobshould remain stored after it is orphaned (nopoint to it).TriggersJobBuilderstoreDurably(boolean jobDurability)Whether or not theJobshould remain stored after it is orphaned (nopoint to it).TriggersJobBuilderusingJobData(java.lang.String dataKey, java.lang.Boolean value)Add the given key-value pair to the JobDetail'sJobDataMap.JobBuilderusingJobData(java.lang.String dataKey, java.lang.Double value)Add the given key-value pair to the JobDetail'sJobDataMap.JobBuilderusingJobData(java.lang.String dataKey, java.lang.Float value)Add the given key-value pair to the JobDetail'sJobDataMap.JobBuilderusingJobData(java.lang.String dataKey, java.lang.Integer value)Add the given key-value pair to the JobDetail'sJobDataMap.JobBuilderusingJobData(java.lang.String dataKey, java.lang.Long value)Add the given key-value pair to the JobDetail'sJobDataMap.JobBuilderusingJobData(java.lang.String dataKey, java.lang.String value)Add the given key-value pair to the JobDetail'sJobDataMap.JobBuilderusingJobData(JobDataMap newJobDataMap)JobBuilderwithDescription(java.lang.String jobDescription)Set the given (human-meaningful) description of the Job.JobBuilderwithIdentity(java.lang.String name)Use aJobKeywith the given name and default group to identify the JobDetail.JobBuilderwithIdentity(java.lang.String name, java.lang.String group)Use aJobKeywith the given name and group to identify the JobDetail.JobBuilderwithIdentity(JobKey jobKey)Use aJobKeyto identify the JobDetail.
-
-
-
Method Detail
-
newJob
public static JobBuilder newJob()
Create a JobBuilder with which to define aJobDetail.- Returns:
- a new JobBuilder
-
newJob
public static JobBuilder newJob(java.lang.Class<? extends Job> jobClass)
Create a JobBuilder with which to define aJobDetail, and set the class name of theJobto be executed.- Returns:
- a new JobBuilder
-
build
public JobDetail build()
Produce theJobDetailinstance defined by thisJobBuilder.- Returns:
- the defined JobDetail.
-
withIdentity
public JobBuilder withIdentity(java.lang.String name)
Use aJobKeywith the given name and default group to identify the JobDetail.If none of the 'withIdentity' methods are set on the JobBuilder, then a random, unique JobKey will be generated.
- Parameters:
name- the name element for the Job's JobKey- Returns:
- the updated JobBuilder
- See Also:
JobKey,JobDetail.getKey()
-
withIdentity
public JobBuilder withIdentity(java.lang.String name, java.lang.String group)
Use aJobKeywith the given name and group to identify the JobDetail.If none of the 'withIdentity' methods are set on the JobBuilder, then a random, unique JobKey will be generated.
- Parameters:
name- the name element for the Job's JobKeygroup- the group element for the Job's JobKey- Returns:
- the updated JobBuilder
- See Also:
JobKey,JobDetail.getKey()
-
withIdentity
public JobBuilder withIdentity(JobKey jobKey)
Use aJobKeyto identify the JobDetail.If none of the 'withIdentity' methods are set on the JobBuilder, then a random, unique JobKey will be generated.
- Parameters:
jobKey- the Job's JobKey- Returns:
- the updated JobBuilder
- See Also:
JobKey,JobDetail.getKey()
-
withDescription
public JobBuilder withDescription(java.lang.String jobDescription)
Set the given (human-meaningful) description of the Job.- Parameters:
jobDescription- the description for the Job- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getDescription()
-
ofType
public JobBuilder ofType(java.lang.Class<? extends Job> jobClazz)
Set the class which will be instantiated and executed when a Trigger fires that is associated with this JobDetail.- Parameters:
jobClazz- a class implementing the Job interface.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobClass()
-
requestRecovery
public JobBuilder requestRecovery()
Instructs theSchedulerwhether or not theJobshould be re-executed if a 'recovery' or 'fail-over' situation is encountered.If not explicitly set, the default value is
false. - this method sets the value totrue.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.requestsRecovery()
-
requestRecovery
public JobBuilder requestRecovery(boolean jobShouldRecover)
Instructs theSchedulerwhether or not theJobshould be re-executed if a 'recovery' or 'fail-over' situation is encountered.If not explicitly set, the default value is
false.- Parameters:
jobShouldRecover- the desired setting- Returns:
- the updated JobBuilder
-
storeDurably
public JobBuilder storeDurably()
Whether or not theJobshould remain stored after it is orphaned (nopoint to it).TriggersIf not explicitly set, the default value is
false- this method sets the value totrue.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.isDurable()
-
storeDurably
public JobBuilder storeDurably(boolean jobDurability)
Whether or not theJobshould remain stored after it is orphaned (nopoint to it).TriggersIf not explicitly set, the default value is
false.- Parameters:
jobDurability- the value to set for the durability property.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.isDurable()
-
usingJobData
public JobBuilder usingJobData(java.lang.String dataKey, java.lang.String value)
Add the given key-value pair to the JobDetail'sJobDataMap.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
usingJobData
public JobBuilder usingJobData(java.lang.String dataKey, java.lang.Integer value)
Add the given key-value pair to the JobDetail'sJobDataMap.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
usingJobData
public JobBuilder usingJobData(java.lang.String dataKey, java.lang.Long value)
Add the given key-value pair to the JobDetail'sJobDataMap.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
usingJobData
public JobBuilder usingJobData(java.lang.String dataKey, java.lang.Float value)
Add the given key-value pair to the JobDetail'sJobDataMap.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
usingJobData
public JobBuilder usingJobData(java.lang.String dataKey, java.lang.Double value)
Add the given key-value pair to the JobDetail'sJobDataMap.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
usingJobData
public JobBuilder usingJobData(java.lang.String dataKey, java.lang.Boolean value)
Add the given key-value pair to the JobDetail'sJobDataMap.- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
usingJobData
public JobBuilder usingJobData(JobDataMap newJobDataMap)
- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
setJobData
public JobBuilder setJobData(JobDataMap newJobDataMap)
- Returns:
- the updated JobBuilder
- See Also:
JobDetail.getJobDataMap()
-
-