Class TriggerBuilder

java.lang.Object
org.quartz.builders.TriggerBuilder
Direct Known Subclasses:
CronTriggerBuilder, SimpleTriggerBuilder

public abstract class TriggerBuilder extends 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);

 
  • Constructor Details

    • TriggerBuilder

      public TriggerBuilder()
  • Method Details

    • instantiate

      public abstract OperableTrigger instantiate()
    • build

      public OperableTrigger build()
      Produce the OperableTrigger.
      Returns:
      a OperableTrigger that meets the specifications of the builder.
    • withIdentity

      public TriggerBuilder withIdentity(String name)
      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:
      name - the TriggerKey for the Trigger to be built
      Returns:
      the updated TriggerBuilder
    • withDescription

      public TriggerBuilder withDescription(String description)
      Set the given (human-meaningful) description of the Trigger.
      Parameters:
      description - the description for the Trigger
      Returns:
      the updated TriggerBuilder
    • withPriority

      public TriggerBuilder 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
    • modifiedByCalendar

      public TriggerBuilder modifiedByCalendar(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
    • startNow

      public TriggerBuilder 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
    • startAt

      public TriggerBuilder startAt(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
    • endAt

      public TriggerBuilder endAt(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
    • withTriggerImplementation

      public TriggerBuilder withTriggerImplementation(OperableTrigger operableTrigger)
      Set the
      invalid @link
      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
    • forJob

      public TriggerBuilder forJob(String jobName)
      Set the identity of the Job which should be fired by the produced Trigger.
      Parameters:
      jobName - the identity of the Job to fire.
      Returns:
      the updated TriggerBuilder
    • usingJobData

      public TriggerBuilder usingJobData(JobDataMap newJobDataMap)
      Set the Trigger's JobDataMap.
      Returns:
      the updated TriggerBuilder