public class Quartz2SchedulerService extends AbstractSchedulerService
SchedulerService.
JobKey names, with the Job being created or
destroyed automatically based on whether or not it has any existing Triggers.Jobs use Quartz2Job, which immediately delegates to JobLauncher.TriggerKey names.byte[] and stored in the JobDataMap
for the Quartz Trigger.LifecycleAwareSchedulerService.StateBY_JOB_ID| Constructor and Description |
|---|
Quartz2SchedulerService(RunDetailsDao runDetailsDao,
Quartz2SchedulerConfiguration config) |
Quartz2SchedulerService(RunDetailsDao runDetailsDao,
SchedulerServiceConfiguration config,
org.quartz.Scheduler localScheduler,
org.quartz.Scheduler clusteredScheduler) |
| Modifier and Type | Method and Description |
|---|---|
Date |
calculateNextRunTime(Schedule schedule)
Returns the next time that a job with the given schedule would be expected to run.
|
JobDetails |
getJobDetails(JobId jobId)
Retrieves the details for the specified job ID.
|
Set<JobRunnerKey> |
getJobRunnerKeysForAllScheduledJobs()
Returns all of the job runner keys that have been used to schedule jobs, regardless
of whether or not
JobRunners are currently registered for them. |
List<JobDetails> |
getJobsByJobRunnerKey(JobRunnerKey jobRunnerKey)
Retrieves the job details for all jobs with the given job runner key.
|
void |
scheduleJob(JobId jobId,
JobConfig jobConfig)
Schedules a job with the given job ID.
|
protected void |
shutdownImpl()
Provided by the scheduler service to implement
AbstractSchedulerService.shutdown() requests. |
protected void |
standbyImpl()
Stop the threads associated with each quartz scheduler
|
protected void |
startImpl()
Start the threads associated with each quartz scheduler.
|
void |
unscheduleJob(JobId jobId)
Unschedules a previously scheduled job ID.
|
addRunDetails, checked, getJobRunner, getLocallyRunningJobs, getParameterMapSerializer, getRegisteredJobRunnerKeys, getState, postJob, preJob, registerJobRunner, scheduleJobWithGeneratedId, shutdown, standby, start, unregisterJobRunner, waitUntilIdlepublic Quartz2SchedulerService(RunDetailsDao runDetailsDao, Quartz2SchedulerConfiguration config) throws SchedulerServiceException
SchedulerServiceExceptionpublic Quartz2SchedulerService(RunDetailsDao runDetailsDao, SchedulerServiceConfiguration config, org.quartz.Scheduler localScheduler, org.quartz.Scheduler clusteredScheduler) throws SchedulerServiceException
SchedulerServiceExceptionpublic void scheduleJob(JobId jobId, JobConfig jobConfig) throws SchedulerServiceException
SchedulerServiceIf a job already exists with the given ID, then it will be replaced with the new run config. If the schedule is eligible to run immediately and multiple nodes take this action at close to the same time, then the job might run more than once as the instances replace one another.
In most cases, this will be harmless, but it can be avoided by making sure the job will not be eligible to run until some time in the future. For example, when using an interval schedule, the caller can first check whether or not the job already exists, and if it does not then specify an initial start date for the schedule, as in:
Schedule.forInterval(120000L, new Date(System.currentTimeMillis() + 15000L))
Since the schedule will not be eligible to run until 15 seconds after the current time, any race conditions between two nodes starting up at once and trying to schedule the same job should resolve before the job actually fires. For cron expressions, this is a little bit more difficult, but you can set the seconds field to an explicit value to accomplish the same thing. For example:
final Calendar calendar = new GregorianCalendar();
calendar.add(15, Calendar.SECOND);
final Schedule schedule = Schedule.forCronExpression(
calendar.get(Calendar.SECOND) + " 0 2 * * ?"); // at or just after 2 A.M.
scheduleJob(...
jobId - the Job IDjobConfig - the configuration details for the job instance including schedule,
run mode, run parameters, etc.SchedulerServiceException - if the job cannot be scheduled because there is a problem
with either the provided configuration or within the scheduler implementation itselfpublic void unscheduleJob(JobId jobId)
SchedulerServiceIf no such job exists, then the request is ignored.
jobId - the Job ID to be unregistered@Nullable public Date calculateNextRunTime(Schedule schedule) throws SchedulerServiceException
SchedulerServiceCaveats:
JobDetails are not aware of the job that they came from
or whether or not that job has previously run. They are calculated on the basis of the current
time, not the original job's history.cron expressions are implicitly
validated by this request.schedule - the schedule to evaluatenull if it would never runSchedulerServiceException - if schedule is invalid.@Nullable public JobDetails getJobDetails(JobId jobId)
SchedulerServicejobId - the Job ID for which to retrieve the detailsnull if no such job is defined@Nonnull public Set<JobRunnerKey> getJobRunnerKeysForAllScheduledJobs()
SchedulerServiceJobRunners are currently registered for them. The job
runner keys are not guaranteed to be returned in any particular order.SchedulerService.getRegisteredJobRunnerKeys()@Nonnull public List<JobDetails> getJobsByJobRunnerKey(JobRunnerKey jobRunnerKey)
SchedulerServicejobRunnerKey - the job runner key to look upnullprotected void startImpl()
throws SchedulerServiceException
startImpl in class AbstractSchedulerServiceSchedulerServiceException - if the scheduler implementation fails to startprotected void standbyImpl()
throws SchedulerServiceException
standbyImpl in class AbstractSchedulerServiceSchedulerServiceException - if the scheduler implementation fails to enter standby modeprotected void shutdownImpl()
AbstractSchedulerServiceAbstractSchedulerService.shutdown() requests. This
is only ever called if the scheduler has not already been shut down, and throwing an
exception does not prevent the scheduler service from entering this state.shutdownImpl in class AbstractSchedulerServiceCopyright © 2017 Atlassian. All rights reserved.