org.quartz
Class TriggerBuilder<T extends Trigger>

java.lang.Object
  extended by org.quartz.TriggerBuilder<T>

public class TriggerBuilder<T extends Trigger>
extends java.lang.Object

TriggerBuilder is used to instantiate Triggers.

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, TriggerKey and the various ScheduleBuilder implementations.

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, ScheduleBuilder, DateBuilder, Trigger

Method Summary
 T build()
          Produce the Trigger.
 TriggerBuilder<T> endAt(java.util.Date endTime)
          Set the time at which the Trigger will no longer fire - even if it's schedule has remaining repeats.
 TriggerBuilder<T> forJob(JobDetail jobDetail)
          Set the identity of the Job which should be fired by the produced Trigger, by extracting the JobKey from the given job.
 TriggerBuilder<T> forJob(JobKey jobKey)
          Set the identity of the Job which should be fired by the produced Trigger.
 TriggerBuilder<T> forJob(java.lang.String jobName)
          Set the identity of the Job which should be fired by the produced Trigger - a JobKey will be produced with the given name and default group.
 TriggerBuilder<T> forJob(java.lang.String jobName, java.lang.String jobGroup)
          Set the identity of the Job which should be fired by the produced Trigger - a JobKey will be produced with the given name and group.
 TriggerBuilder<T> modifiedByCalendar(java.lang.String calendarName)
          Set the name of the Calendar that should be applied to this Trigger's schedule.
static TriggerBuilder<Trigger> newTrigger()
          Create a new TriggerBuilder with which to define a specification for a Trigger.
 TriggerBuilder<T> startAt(java.util.Date startTime)
          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.
 TriggerBuilder<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.
 TriggerBuilder<T> usingJobData(JobDataMap newJobDataMap)
          Set the Trigger's JobDataMap, adding any values to it that were already set on this TriggerBuilder using any of the other 'usingJobData' methods.
 TriggerBuilder<T> usingJobData(java.lang.String key, java.lang.Boolean value)
          Add the given key-value pair to the Trigger's JobDataMap.
 TriggerBuilder<T> usingJobData(java.lang.String key, java.lang.Double value)
          Add the given key-value pair to the Trigger's JobDataMap.
 TriggerBuilder<T> usingJobData(java.lang.String key, java.lang.Float value)
          Add the given key-value pair to the Trigger's JobDataMap.
 TriggerBuilder<T> usingJobData(java.lang.String key, java.lang.Integer value)
          Add the given key-value pair to the Trigger's JobDataMap.
 TriggerBuilder<T> usingJobData(java.lang.String key, java.lang.Long value)
          Add the given key-value pair to the Trigger's JobDataMap.
 TriggerBuilder<T> usingJobData(java.lang.String key, java.lang.String value)
          Add the given key-value pair to the Trigger's JobDataMap.
 TriggerBuilder<T> withDescription(java.lang.String description)
          Set the given (human-meaningful) description of the Trigger.
 TriggerBuilder<T> withIdentity(java.lang.String name)
          Use a TriggerKey with the given name and default group to identify the Trigger.
 TriggerBuilder<T> withIdentity(java.lang.String name, java.lang.String group)
          Use a TriggerKey with the given name and group to identify the Trigger.
 TriggerBuilder<T> withIdentity(TriggerKey key)
          Use the given TriggerKey to identify the Trigger.
 TriggerBuilder<T> withPriority(int priority)
          Set the Trigger's priority.
<SBT extends T>
TriggerBuilder<SBT>
withSchedule(ScheduleBuilder<SBT> scheduleBuilder)
          Set the ScheduleBuilder that will be used to define the Trigger's schedule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newTrigger

public static TriggerBuilder<Trigger> newTrigger()
Create a new TriggerBuilder with which to define a specification for a Trigger.

Returns:
the new TriggerBuilder

build

public T build()
Produce the Trigger.

Returns:
a Trigger that meets the specifications of the builder.

withIdentity

public TriggerBuilder<T> withIdentity(java.lang.String name)
Use a TriggerKey with the given name and default group to identify the Trigger.

If none of the 'withIdentity' methods are set on the TriggerBuilder, then a random, unique TriggerKey will be generated.

Parameters:
name - the name element for the Trigger's TriggerKey
Returns:
the updated TriggerBuilder
See Also:
TriggerKey, Trigger.getKey()

withIdentity

public TriggerBuilder<T> withIdentity(java.lang.String name,
                                      java.lang.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 TriggerBuilder, then a random, unique TriggerKey will be generated.

Parameters:
name - the name element for the Trigger's TriggerKey
group - the group element for the Trigger's TriggerKey
Returns:
the updated TriggerBuilder
See Also:
TriggerKey, Trigger.getKey()

withIdentity

public TriggerBuilder<T> withIdentity(TriggerKey key)
Use the given TriggerKey to identify the Trigger.

If none of the 'withIdentity' methods are set on the TriggerBuilder, then a random, unique TriggerKey will be generated.

Parameters:
key - the TriggerKey for the Trigger to be built
Returns:
the updated TriggerBuilder
See Also:
TriggerKey, Trigger.getKey()

withDescription

public TriggerBuilder<T> withDescription(java.lang.String description)
Set the given (human-meaningful) description of the Trigger.

Parameters:
description - the description for the Trigger
Returns:
the updated TriggerBuilder
See Also:
Trigger.getDescription()

withPriority

public TriggerBuilder<T> withPriority(int priority)
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:
priority - the priority for the Trigger
Returns:
the updated TriggerBuilder
See Also:
Trigger.DEFAULT_PRIORITY, Trigger.getPriority()

modifiedByCalendar

public TriggerBuilder<T> modifiedByCalendar(java.lang.String calendarName)
Set the name of the Calendar that should be applied to this Trigger's schedule.

Parameters:
calendarName - the name of the Calendar to reference.
Returns:
the updated TriggerBuilder
See Also:
Calendar, Trigger.getCalendarName()

startAt

public TriggerBuilder<T> startAt(java.util.Date startTime)
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:
startTime - the start time for the Trigger.
Returns:
the updated TriggerBuilder
See Also:
Trigger.getStartTime(), DateBuilder

startNow

public TriggerBuilder<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 TriggerBuilder
See Also:
Trigger.getStartTime()

endAt

public TriggerBuilder<T> endAt(java.util.Date endTime)
Set the time at which the Trigger will no longer fire - even if it's schedule has remaining repeats.

Parameters:
endTime - the end time for the Trigger. If null, the end time is indefinite.
Returns:
the updated TriggerBuilder
See Also:
Trigger.getEndTime(), DateBuilder

withSchedule

public <SBT extends T> TriggerBuilder<SBT> withSchedule(ScheduleBuilder<SBT> scheduleBuilder)
Set the ScheduleBuilder that will be used to define the Trigger's schedule.

The particular SchedulerBuilder used will dictate the concrete type of Trigger that is produced by the TriggerBuilder.

Parameters:
scheduleBuilder - the SchedulerBuilder to use.
Returns:
the updated TriggerBuilder
See Also:
ScheduleBuilder, SimpleScheduleBuilder, CronScheduleBuilder, CalendarIntervalScheduleBuilder

forJob

public TriggerBuilder<T> forJob(JobKey jobKey)
Set the identity of the Job which should be fired by the produced Trigger.

Parameters:
jobKey - the identity of the Job to fire.
Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobKey()

forJob

public TriggerBuilder<T> forJob(java.lang.String jobName)
Set the identity of the Job which should be fired by the produced Trigger - a JobKey will be produced with the given name and default group.

Parameters:
jobName - the name of the job (in default group) to fire.
Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobKey()

forJob

public TriggerBuilder<T> forJob(java.lang.String jobName,
                                java.lang.String jobGroup)
Set the identity of the Job which should be fired by the produced Trigger - a JobKey will 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 TriggerBuilder
See Also:
Trigger.getJobKey()

forJob

public TriggerBuilder<T> forJob(JobDetail 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 TriggerBuilder
See Also:
Trigger.getJobKey()

usingJobData

public TriggerBuilder<T> usingJobData(java.lang.String key,
                                      java.lang.String value)
Add the given key-value pair to the Trigger's JobDataMap.

Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobDataMap()

usingJobData

public TriggerBuilder<T> usingJobData(java.lang.String key,
                                      java.lang.Integer value)
Add the given key-value pair to the Trigger's JobDataMap.

Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobDataMap()

usingJobData

public TriggerBuilder<T> usingJobData(java.lang.String key,
                                      java.lang.Long value)
Add the given key-value pair to the Trigger's JobDataMap.

Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobDataMap()

usingJobData

public TriggerBuilder<T> usingJobData(java.lang.String key,
                                      java.lang.Float value)
Add the given key-value pair to the Trigger's JobDataMap.

Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobDataMap()

usingJobData

public TriggerBuilder<T> usingJobData(java.lang.String key,
                                      java.lang.Double value)
Add the given key-value pair to the Trigger's JobDataMap.

Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobDataMap()

usingJobData

public TriggerBuilder<T> usingJobData(java.lang.String key,
                                      java.lang.Boolean value)
Add the given key-value pair to the Trigger's JobDataMap.

Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobDataMap()

usingJobData

public TriggerBuilder<T> usingJobData(JobDataMap newJobDataMap)
Set the Trigger's JobDataMap, adding any values to it that were already set on this TriggerBuilder using any of the other 'usingJobData' methods.

Returns:
the updated TriggerBuilder
See Also:
Trigger.getJobDataMap()


Copyright 2001-2019, Terracotta, Inc.