Class JobScheduler
Jobs are created either with clusterJob(String) or localJob(String)
and then scheduled to execute.
- Since:
- 3.11.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Job.BuilderclusterJob(String jobId) Creates a builder for a job that must run on only one node of the cluster each time that it triggers.protected voiddispose()Disposes the resources used by this scheduler and unschedules all jobs.protected abstract voiddoSchedule(Job job) Performs the scheduling of the job.protected abstract voiddoUnschedule(Job job) Performs the job unscheduling.static JobSchedulerReturns the scheduler instance.Returns the job of given identifier built by this scheduler, if anygetJobConfig(Job job) Returns a resource describing the configuration of the job.getJobs()Returns an unmodifiable collection of jobs built by this scheduler.protected abstract Job.BuilderCreates a builder of job.final Job.BuilderCreates builder for a job scheduled so that it will apply only to this particular node of the cluster.final voidschedule(Job job, JobSchedule defaultSchedule) Schedules the background job.final voidschedule(Job job, JobScheduleConfig scheduleConfig) Changes the schedule of the background job.static voidsetInstance(JobScheduler instance) Changes the scheduler instance.
-
Constructor Details
-
JobScheduler
protected JobScheduler()
-
-
Method Details
-
getInstance
Returns the scheduler instance.- Returns:
- the scheduler instance.
- See Also:
-
setInstance
Changes the scheduler instance. The default scheduler is already cluster compatible. Applications may provide an alternate scheduler if they want to rely on a different job framework than the default.- Parameters:
instance- the new scheduler
-
clusterJob
Creates a builder for a job that must run on only one node of the cluster each time that it triggers. UselocalJob(String)if the job must run on each node of the cluster.Note a cluster job cannot use a
fixed delayschedule.- Parameters:
jobId- the identifier of the job to create- Returns:
- a job builder instance
- Throws:
NullPointerException- if jobId is null or empty
-
localJob
Creates builder for a job scheduled so that it will apply only to this particular node of the cluster. UseclusterJob(String)for a job that must run on only one node of the cluster each time that it triggers.- Parameters:
jobId- the identifier of the job to create- Returns:
- a job builder instance
- Throws:
NullPointerException- if jobId is null or empty
-
jobBuilder
Creates a builder of job.- Returns:
- a new builder instance
-
getJobs
Returns an unmodifiable collection of jobs built by this scheduler.- Returns:
- the known jobs
-
getJob
Returns the job of given identifier built by this scheduler, if any- Parameters:
id- the job identifier to look for- Returns:
- the corresponding job, or an empty optional
-
schedule
Schedules the background job. This method is to call when a job is just created and is to schedule initially.The given schedule is used as a default. If an administrator has edited the schedule for this job, to use a more suitable time for triggering it, the default schedule is discarded and the edited one is applied.
This method automatically cancels previous scheduling, if any. All jobs are also automatically unscheduled when the application is
disposed.This method may also be used to
disablejob scheduling, so that the job no longer runs.- Parameters:
job- the job to scheduledefaultSchedule- the default schedule to use- Throws:
NullPointerException- if job or defaultSchedule is nullIllegalArgumentException- if it is aclusterjob and afixed delayschedule.JobSchedulerException- if anything prevents scheduling the job
-
getJobConfig
Returns a resource describing the configuration of the job.- Parameters:
job- the job for which a configuration is to retrieve- Returns:
- the job config resource
- Since:
- 3.12.0
-
schedule
public final void schedule(Job job, JobScheduleConfig scheduleConfig) throws JobSchedulerException, SettingStoreException Changes the schedule of the background job. This method is called byJobConfigServicewhen an administrator edited a job schedule.The given schedule is first
validated, to ensure the edited settings are applicable to the job. The new schedule is then saved inserver settingsandappliedon the job.- Parameters:
job- the job to schedulescheduleConfig- the edited schedule configuration- Throws:
JobSchedulerException- if anything prevents scheduling the jobSettingStoreException- if the edited schedule cannot be stored in server settingsIllegalArgumentException- if the schedule is invalid and cannot be applied- Since:
- 3.12.0
-
doSchedule
Performs the scheduling of the job. The job is known to be alreadyunscheduledat this stage.- Parameters:
job- the job to schedule- Throws:
JobSchedulerException- if anything prevents scheduling the job
-
doUnschedule
Performs the job unscheduling.- Parameters:
job- the job to unschedule- Throws:
JobSchedulerException- if anything prevents unscheduling the job
-
dispose
protected void dispose()Disposes the resources used by this scheduler and unschedules all jobs.
-