Class JDK8TriggerBuilder<T extends com.helger.quartz.ITrigger>
- java.lang.Object
-
- com.helger.schedule.quartz.trigger.JDK8TriggerBuilder<T>
-
- Type Parameters:
T- Trigger type to create
public class JDK8TriggerBuilder<T extends com.helger.quartz.ITrigger> extends Object
JDK8TriggerBuilderis used to instantiateITriggers.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 withSchedule(..) method, a default schedule of firing once immediately will be used. As another example, if you do not invoked withIdentity(..) a trigger 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
JDK8TriggerBuilder,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:
JobBuilder,IScheduleBuilder,DateBuilder,ITrigger
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJDK8TriggerBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tbuild()Produce theTrigger.JDK8TriggerBuilder<T>endAt(LocalDateTime triggerEndTime)Set the time at which the Trigger will no longer fire - even if it's schedule has remaining repeats.JDK8TriggerBuilder<T>forJob(com.helger.quartz.IJobDetail jobDetail)Set the identity of the Job which should be fired by the produced Trigger, by extracting the JobKey from the given job.JDK8TriggerBuilder<T>forJob(com.helger.quartz.JobKey keyOfJobToFire)Set the identity of the Job which should be fired by the produced Trigger.JDK8TriggerBuilder<T>forJob(String jobName)Set the identity of the Job which should be fired by the produced Trigger - aJobKeywill be produced with the given name and default group.JDK8TriggerBuilder<T>forJob(String jobName, String jobGroup)Set the identity of the Job which should be fired by the produced Trigger - aJobKeywill be produced with the given name and group.JDK8TriggerBuilder<T>modifiedByCalendar(String calName)Set the name of theICalendarthat should be applied to this Trigger's schedule.static JDK8TriggerBuilder<com.helger.quartz.ITrigger>newTrigger()Create a new JDK8TriggerBuilder with which to define a specification for a Trigger.JDK8TriggerBuilder<T>startAt(LocalDateTime triggerStartTime)Set the time the Trigger should start at - the trigger may or may not fire at this time - depending upon the schedule configured for the Trigger.JDK8TriggerBuilder<T>startNow()Set the time the Trigger should start at to the current moment - the trigger may or may not fire at this time - depending upon the schedule configured for the Trigger.JDK8TriggerBuilder<T>usingJobData(com.helger.quartz.JobDataMap newJobDataMap)Set the Trigger'sJobDataMap, adding any values to it that were already set on this JDK8TriggerBuilder using any of the other 'usingJobData' methods.JDK8TriggerBuilder<T>usingJobData(String dataKey, boolean value)Add the given key-value pair to the Trigger'sJobDataMap.JDK8TriggerBuilder<T>usingJobData(String dataKey, double value)Add the given key-value pair to the Trigger'sJobDataMap.JDK8TriggerBuilder<T>usingJobData(String dataKey, float value)Add the given key-value pair to the Trigger'sJobDataMap.JDK8TriggerBuilder<T>usingJobData(String dataKey, int value)Add the given key-value pair to the Trigger'sJobDataMap.JDK8TriggerBuilder<T>usingJobData(String dataKey, long value)Add the given key-value pair to the Trigger'sJobDataMap.JDK8TriggerBuilder<T>usingJobData(String dataKey, Object value)Add the given key-value pair to the Trigger'sJobDataMap.JDK8TriggerBuilder<T>withDescription(String triggerDescription)Set the given (human-meaningful) description of the Trigger.JDK8TriggerBuilder<T>withIdentity(com.helger.quartz.TriggerKey triggerKey)Use the given TriggerKey to identify the Trigger.JDK8TriggerBuilder<T>withIdentity(String name)Use aTriggerKeywith the given name and default group to identify the Trigger.JDK8TriggerBuilder<T>withIdentity(String name, String group)Use a TriggerKey with the given name and group to identify the Trigger.JDK8TriggerBuilder<T>withPriority(int triggerPriority)Set the Trigger's priority.JDK8TriggerBuilder<T>withSchedule(com.helger.quartz.IScheduleBuilder<? extends T> schedBuilder)Set theIScheduleBuilderthat will be used to define the Trigger's schedule.
-
-
-
Method Detail
-
newTrigger
@Nonnull public static JDK8TriggerBuilder<com.helger.quartz.ITrigger> newTrigger()
Create a new JDK8TriggerBuilder with which to define a specification for a Trigger.- Returns:
- the new JDK8TriggerBuilder
-
build
@Nonnull public T build()
Produce theTrigger.- Returns:
- a Trigger that meets the specifications of the builder.
-
withIdentity
@Nonnull public JDK8TriggerBuilder<T> withIdentity(String name)
Use aTriggerKeywith the given name and default group to identify the Trigger.If none of the 'withIdentity' methods are set on the JDK8TriggerBuilder, then a random, unique TriggerKey will be generated.
- Parameters:
name- the name element for the Trigger's TriggerKey- Returns:
- the updated JDK8TriggerBuilder
- See Also:
TriggerKey,ITrigger.getKey()
-
withIdentity
@Nonnull public JDK8TriggerBuilder<T> withIdentity(String name, String group)
Use a TriggerKey with the given name and group to identify the Trigger.If none of the 'withIdentity' methods are set on the JDK8TriggerBuilder, then a random, unique TriggerKey will be generated.
- Parameters:
name- the name element for the Trigger's TriggerKeygroup- the group element for the Trigger's TriggerKey- Returns:
- the updated JDK8TriggerBuilder
- See Also:
TriggerKey,ITrigger.getKey()
-
withIdentity
@Nonnull public JDK8TriggerBuilder<T> withIdentity(com.helger.quartz.TriggerKey triggerKey)
Use the given TriggerKey to identify the Trigger.If none of the 'withIdentity' methods are set on the JDK8TriggerBuilder, then a random, unique TriggerKey will be generated.
- Parameters:
triggerKey- the TriggerKey for the Trigger to be built- Returns:
- the updated JDK8TriggerBuilder
- See Also:
TriggerKey,ITrigger.getKey()
-
withDescription
@Nonnull public JDK8TriggerBuilder<T> withDescription(String triggerDescription)
Set the given (human-meaningful) description of the Trigger.- Parameters:
triggerDescription- the description for the Trigger- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getDescription()
-
withPriority
public JDK8TriggerBuilder<T> withPriority(int triggerPriority)
Set the Trigger's priority. When more than one Trigger have the same fire time, the scheduler will fire the one with the highest priority first.- Parameters:
triggerPriority- the priority for the Trigger- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.DEFAULT_PRIORITY,ITrigger.getPriority()
-
modifiedByCalendar
@Nonnull public JDK8TriggerBuilder<T> modifiedByCalendar(String calName)
Set the name of theICalendarthat should be applied to this Trigger's schedule.- Parameters:
calName- the name of the Calendar to reference.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ICalendar,ITrigger.getCalendarName()
-
startAt
@Nonnull public JDK8TriggerBuilder<T> startAt(LocalDateTime triggerStartTime)
Set the time the Trigger should start at - the trigger may or may not fire at this time - depending upon the schedule configured for the Trigger. However the Trigger will NOT fire before this time, regardless of the Trigger's schedule.- Parameters:
triggerStartTime- the start time for the Trigger.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getStartTime(),DateBuilder
-
startNow
@Nonnull public JDK8TriggerBuilder<T> startNow()
Set the time the Trigger should start at to the current moment - the trigger may or may not fire at this time - depending upon the schedule configured for the Trigger.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getStartTime()
-
endAt
@Nonnull public JDK8TriggerBuilder<T> endAt(LocalDateTime triggerEndTime)
Set the time at which the Trigger will no longer fire - even if it's schedule has remaining repeats.- Parameters:
triggerEndTime- the end time for the Trigger. If null, the end time is indefinite.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getEndTime(),DateBuilder
-
withSchedule
@Nonnull public JDK8TriggerBuilder<T> withSchedule(com.helger.quartz.IScheduleBuilder<? extends T> schedBuilder)
Set theIScheduleBuilderthat will be used to define the Trigger's schedule.The particular
SchedulerBuilderused will dictate the concrete type of Trigger that is produced by the JDK8TriggerBuilder.- Parameters:
schedBuilder- the SchedulerBuilder to use.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
SimpleScheduleBuilder
-
forJob
public JDK8TriggerBuilder<T> forJob(com.helger.quartz.JobKey keyOfJobToFire)
Set the identity of the Job which should be fired by the produced Trigger.- Parameters:
keyOfJobToFire- the identity of the Job to fire.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobKey()
-
forJob
@Nonnull public JDK8TriggerBuilder<T> forJob(String jobName)
Set the identity of the Job which should be fired by the produced Trigger - aJobKeywill be produced with the given name and default group.- Parameters:
jobName- the name of the job (in default group) to fire.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobKey()
-
forJob
@Nonnull public JDK8TriggerBuilder<T> forJob(String jobName, String jobGroup)
Set the identity of the Job which should be fired by the produced Trigger - aJobKeywill be produced with the given name and group.- Parameters:
jobName- the name of the job to fire.jobGroup- the group of the job to fire.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobKey()
-
forJob
@Nonnull public JDK8TriggerBuilder<T> forJob(com.helger.quartz.IJobDetail jobDetail)
Set the identity of the Job which should be fired by the produced Trigger, by extracting the JobKey from the given job.- Parameters:
jobDetail- the Job to fire.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobKey()
-
usingJobData
@Nonnull public JDK8TriggerBuilder<T> usingJobData(String dataKey, Object value)
Add the given key-value pair to the Trigger'sJobDataMap.- Parameters:
dataKey- Job data key.value- Job data value- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobDataMap()
-
usingJobData
@Nonnull public JDK8TriggerBuilder<T> usingJobData(String dataKey, int value)
Add the given key-value pair to the Trigger'sJobDataMap.- Parameters:
dataKey- Job data key.value- Job data value- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobDataMap()
-
usingJobData
@Nonnull public JDK8TriggerBuilder<T> usingJobData(String dataKey, long value)
Add the given key-value pair to the Trigger'sJobDataMap.- Parameters:
dataKey- Job data key.value- Job data value- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobDataMap()
-
usingJobData
@Nonnull public JDK8TriggerBuilder<T> usingJobData(String dataKey, float value)
Add the given key-value pair to the Trigger'sJobDataMap.- Parameters:
dataKey- Job data key.value- Job data value- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobDataMap()
-
usingJobData
@Nonnull public JDK8TriggerBuilder<T> usingJobData(String dataKey, double value)
Add the given key-value pair to the Trigger'sJobDataMap.- Parameters:
dataKey- Job data key.value- Job data value- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobDataMap()
-
usingJobData
@Nonnull public JDK8TriggerBuilder<T> usingJobData(String dataKey, boolean value)
Add the given key-value pair to the Trigger'sJobDataMap.- Parameters:
dataKey- Job data key.value- Job data value- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobDataMap()
-
usingJobData
@Nonnull public JDK8TriggerBuilder<T> usingJobData(@Nonnull com.helger.quartz.JobDataMap newJobDataMap)
Set the Trigger'sJobDataMap, adding any values to it that were already set on this JDK8TriggerBuilder using any of the other 'usingJobData' methods.- Parameters:
newJobDataMap- New map to use. May not benull.- Returns:
- the updated JDK8TriggerBuilder
- See Also:
ITrigger.getJobDataMap()
-
-