Class QuartzScheduler

  • All Implemented Interfaces:
    Initialization, Scheduler
    Direct Known Subclasses:
    PersistentQuartzScheduler, VolatileQuartScheduler

    public abstract class QuartzScheduler
    extends Object
    implements Scheduler, Initialization
    An abstract scheduler implementation using Quartz as scheduling backend. It wraps a Quartz scheduler and delegates to it all of the calls after transforming the parameters into their Quartz counterparts. The way the jobs are stored depends on the concrete type of this abstract class. It defines the job scheduling mechanism by using the Quartz API.
    • Constructor Detail

      • QuartzScheduler

        protected QuartzScheduler()
    • Method Detail

      • getPriority

        public int getPriority()
        Description copied from interface: Initialization
        Gets the priority level of the execution of Initialization.init() method.

        The less is the value of the priority the more the priority is high.

        Specified by:
        getPriority in interface Initialization
        Returns:
        an integer priority.
      • encodeJob

        protected abstract Object encodeJob​(Job job)
        Encodes the specified job into an object ready to be handled by the job executor related to this scheduler. Each type of scheduler has its own way to encode a job in order to be retrieved by the job executor related by the scheduler.
        Parameters:
        job - the job to encode for the job executor related to this scheduler.
        Returns:
        the encoded job.
      • encodeEventListener

        protected abstract Object encodeEventListener​(SchedulerEventListener listener)
        Encodes the specified scheduler event listener into an object ready to be handled by the job executor related to this scheduler. Each type of scheduler has its own way to encode an event listener in order to be retrieved by the job executor related by the scheduler.
        Parameters:
        listener - the event listener to encode for the job executor related to this scheduler.
        Returns:
        the encoded scheduler event listener.
      • getJobExecutor

        protected abstract <T extends JobExecutorClass<T> getJobExecutor()
        Gets the job executor related to this scheduler. Each type of scheduler has its own job executor that knows how to handle jobs and event listeners.
        Type Parameters:
        T - the concrete type of the job executor
        Returns:
        the class of the job executor.
      • execute

        protected abstract <T> void execute​(QuartzScheduler.SchedulingTask<T> schedulingTask)
                                     throws org.quartz.SchedulerException
        Executes the specified task. The execution of the task is delegated to this method that can wraps the task execution within a peculiar execution context like a transaction for example for persistent jobs.
        Parameters:
        schedulingTask - the scheduling task to execute.
        Throws:
        org.quartz.SchedulerException
      • scheduleJob

        public ScheduledJob scheduleJob​(String jobName,
                                        JobTrigger trigger,
                                        SchedulerEventListener listener)
                                 throws SchedulerException
        Description copied from interface: Scheduler
        Schedules a job under the specified name, that will be fired with the specified trigger, and by setting the specified listener to recieve the events mapped with the job execution state. A scheduled job will be registered in the scheduler under the specified name and its execution will be fired by the specified trigger. The computation of the job will be delegated to the event listener when the associated trigger fires (it will recieve the event mapped with this trigger firing). If a job is already scheduled under the specified name, then a SchedulerException exception is thrown.
        Specified by:
        scheduleJob in interface Scheduler
        Parameters:
        jobName - the name under which the job should be registered in this scheduler.
        trigger - the trigger that will command the job execution in the timeline.
        listener - a listener of scheduler's events. It will recieve the different events fired by the scheduler and mapped with the job execution state. It is expected it will accomplish the job itself at trigger firing. It is required.
        Returns:
        the job scheduled in the scheduler.
        Throws:
        SchedulerException - if either a job is already scheduled under the specified name or if the job scheduling fails.
      • scheduleJob

        public ScheduledJob scheduleJob​(Job theJob,
                                        JobTrigger jobTrigger,
                                        SchedulerEventListener listener)
                                 throws SchedulerException
        Description copied from interface: Scheduler
        Schedules the specified job. It will be fired with the specified trigger and the specified event listener will recieve the events mapped with the state of the job execution. The specified job will be registered as a scheduled job in the scheduler under its name and its execution will be fired by the specified trigger. In the case an event listener is specified, it will recieve the events mapped with the state of the job execution. If a job is already scheduled under the same name of the specified job, then a SchedulerException exception is thrown.
        Specified by:
        scheduleJob in interface Scheduler
        Parameters:
        theJob - the job to schedule.
        jobTrigger - the trigger that will fire the job execution.
        listener - a listener of scheduler's events mapped with the state of the job execution. Null means no listener to register with the job.
        Returns:
        the job scheduled in the scheduler.
        Throws:
        SchedulerException - if either a job is already scheduled under the same name that the specified job or if the job scheduling fails.
      • scheduleJob

        public ScheduledJob scheduleJob​(Job theJob,
                                        JobTrigger trigger)
                                 throws SchedulerException
        Description copied from interface: Scheduler
        Schedules the specified job. It will be fired with the specified trigger. The specified job will be registered as a scheduled job in the scheduler under its name and its execution will be fired by the specified trigger. If a job is already scheduled under the same name of the specified job, then a SchedulerException exception is thrown.
        Specified by:
        scheduleJob in interface Scheduler
        Parameters:
        theJob - the job to schedule.
        trigger - the trigger that will fire the job execution.
        Returns:
        the job scheduled in the scheduler.
        Throws:
        SchedulerException - if either a job is already scheduled under the same name that the specified job or if the job scheduling fails.
      • unscheduleJob

        public void unscheduleJob​(String jobName)
                           throws SchedulerException
        Description copied from interface: Scheduler
        Unschedules the job with the specified name. If no job is scheduled under the specified name, nothing is done.
        Specified by:
        unscheduleJob in interface Scheduler
        Parameters:
        jobName - the name of the job to unschedule.
        Throws:
        SchedulerException - if the specified job cannot be unscheduled.
      • isJobScheduled

        public boolean isJobScheduled​(String jobName)
        Description copied from interface: Scheduler
        Is the job identified by the specified name is scheduled by this scheduler?
        Specified by:
        isJobScheduled in interface Scheduler
        Parameters:
        jobName - the job name.
        Returns:
        true if the job identified by the specified name is scheduled by this scheduler, false otherwise.
      • getScheduledJob

        public Optional<ScheduledJob> getScheduledJob​(String jobName)
        Description copied from interface: Scheduler
        Gets detail about the job that was scheduled under the specified name.
        Specified by:
        getScheduledJob in interface Scheduler
        Parameters:
        jobName - a name of a scheduled job.
        Returns:
        optionally the scheduled job or nothing if no such job is scheduled.
      • shutdown

        public void shutdown()
                      throws SchedulerException
        Description copied from interface: Scheduler
        Shutdowns this scheduler. The firing of triggers are halted and the jobs removed. All of the resources are cleaned up. Once shutdown done, the scheduler cannot be restarted and used for scheduling new jobs.
        Specified by:
        shutdown in interface Scheduler
        Throws:
        SchedulerException - if the scheduler shutdown failed.