Class JobTrigger

  • Direct Known Subclasses:
    CronJobTrigger, FixedDateTimeJobTrigger, FixedPeriodJobTrigger

    public abstract class JobTrigger
    extends Object
    A trigger of a job execution. A job trigger specifies the time, regular or not, at which a job must be executed. A job trigger is a schema about the triggering of job executions. It is is used for actually scheduling a job in the scheduling backend. This class is an abstract one from which new job trigger can be defined. Currently two types of trigger is supported: a trigger with an Unix-like cron expression and another one with a simple periodicity.
    • Constructor Detail

      • JobTrigger

        public JobTrigger()
    • Method Detail

      • accept

        public abstract void accept​(JobTriggerVisitor visitor)
        Accepts the specified visitor to visit it. See the Visitor pattern.
        Parameters:
        visitor - the visitor to accept.
      • getStartDate

        public Date getStartDate()
        Gets the date at which the trigger's scheduling should start. For one shot trigger, this date is the one at which the trigger will be fired. For other triggers it is the date at which the scheduling should start; in that case the trigger may or may not fire at this time, depending upon the schedule configured for the Trigger.

        For repeatedly trigger, null means no explicit starting date and the first fire of the trigger will be done according to the triggering definition. It may or not be the first actual fire time of the trigger, depending on the type of this trigger and its triggering definition. However, the first actual fire time won't be done after this date.

        Returns:
        the job trigger's scheduling start date.
      • triggerEvery

        public static JobTrigger triggerEvery​(int time,
                                              TimeUnit unit)
        Creates a job trigger that will fire a job execution every the specified time.
        Parameters:
        time - the time at every which the trigger will fire the execution of a job.
        unit - the temporal unit in which is expressed the time.
        Returns:
        a job trigger whose the triggering is scheduled periodically at a given time.
      • triggerAt

        public static JobTrigger triggerAt​(String cron)
                                    throws ParseException
        Creates a job trigger that will fire a job execution at given moments in time, defined by the specified cron expression. For more information on the syntax of the cron expression, please see the CronJobTrigger documentation.
        Parameters:
        cron - the Unix cron-like expression.
        Returns:
        a job trigger whose the triggering is scheduled at given moments in time.
        Throws:
        ParseException - if the specified cron expression isn't valid.
        See Also:
        CronJobTrigger
      • triggerAt

        public static JobTrigger triggerAt​(OffsetDateTime dateTime)
        Creates a new job trigger that will fire a job execution only once at the specified date time.
        Parameters:
        dateTime - an OffsetDateTime value.
        Returns:
        the one shot job trigger.
      • startAt

        public JobTrigger startAt​(Date startDate)
        Sets the date at which the trigger's scheduling should start. May or may not be the first actual fire time of the trigger. However the first actual first time will not be before this date.
        Parameters:
        startDate - the job trigger's scheduling start date.
        Returns:
        itself.