com.atlassian.scheduler.quartz1
Class Quartz1SchedulerService

java.lang.Object
  extended by com.atlassian.scheduler.core.AbstractSchedulerService
      extended by com.atlassian.scheduler.quartz1.Quartz1SchedulerService
All Implemented Interfaces:
LifecycleAwareSchedulerService, SchedulerService

public class Quartz1SchedulerService
extends AbstractSchedulerService

Quartz 1.x implementation of a SchedulerService.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.scheduler.core.LifecycleAwareSchedulerService
LifecycleAwareSchedulerService.State
 
Field Summary
 
Fields inherited from class com.atlassian.scheduler.core.AbstractSchedulerService
BY_JOB_ID
 
Constructor Summary
Quartz1SchedulerService(RunDetailsDao runDetailsDao, Quartz1SchedulerConfiguration config)
           
Quartz1SchedulerService(RunDetailsDao runDetailsDao, SchedulerServiceConfiguration config, org.quartz.Scheduler localScheduler, org.quartz.Scheduler clusteredScheduler)
           
 
Method Summary
 org.quartz.Scheduler getClusteredQuartzScheduler()
          Deprecated. Provided as a last resort only. Avoid accessing Quartz directly if possible. Since v1.0
 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.
 org.quartz.Scheduler getLocalQuartzScheduler()
          Deprecated. Provided as a last resort only. Avoid accessing Quartz directly if possible. Since v1.0
 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()
          Provided by the scheduler service to implement AbstractSchedulerService.standby() requests.
protected  void startImpl()
          Provided by the scheduler service to implement AbstractSchedulerService.start() requests.
 void unscheduleJob(JobId jobId)
          Unschedules a previously scheduled job ID.
 
Methods inherited from class com.atlassian.scheduler.core.AbstractSchedulerService
addRunDetails, checked, getJobRunner, getRegisteredJobRunnerKeys, getState, registerJobRunner, scheduleJobWithGeneratedId, shutdown, standby, start, unregisterJobRunner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Quartz1SchedulerService

public Quartz1SchedulerService(RunDetailsDao runDetailsDao,
                               Quartz1SchedulerConfiguration config)
                        throws SchedulerServiceException
Throws:
SchedulerServiceException

Quartz1SchedulerService

public Quartz1SchedulerService(RunDetailsDao runDetailsDao,
                               SchedulerServiceConfiguration config,
                               org.quartz.Scheduler localScheduler,
                               org.quartz.Scheduler clusteredScheduler)
                        throws SchedulerServiceException
Throws:
SchedulerServiceException
Since:
1.1
Method Detail

scheduleJob

public void scheduleJob(@Nonnull
                        JobId jobId,
                        @Nonnull
                        JobConfig jobConfig)
                 throws SchedulerServiceException
Description copied from interface: SchedulerService
Schedules a job with the given job ID.

If 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 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(...
 

Parameters:
jobId - the Job ID
jobConfig - the configuration details for the job instance including schedule, run mode, run parameters, etc.
Throws:
SchedulerServiceException - if the job cannot be scheduled because there is a problem with either the provided configuration or within the scheduler implementation itself

unscheduleJob

public void unscheduleJob(@Nonnull
                          JobId jobId)
Description copied from interface: SchedulerService
Unschedules a previously scheduled job ID.

If no such job exists, then the request is ignored.

Parameters:
jobId - the Job ID to be unregistered

getJobDetails

@Nullable
public JobDetails getJobDetails(@Nonnull
                                         JobId jobId)
Description copied from interface: SchedulerService
Retrieves the details for the specified job ID.

Parameters:
jobId - the Job ID for which to retrieve the details
Returns:
the job details, or null if no such job is defined

getJobRunnerKeysForAllScheduledJobs

@Nonnull
public Set<JobRunnerKey> getJobRunnerKeysForAllScheduledJobs()
Description copied from interface: SchedulerService
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. The job runner keys are not guaranteed to be returned in any particular order.

Returns:
an immutable set containing all of the job runner keys with scheduled jobs
See Also:
SchedulerService.getRegisteredJobRunnerKeys()

getJobsByJobRunnerKey

@Nonnull
public List<JobDetails> getJobsByJobRunnerKey(@Nonnull
                                                      JobRunnerKey jobRunnerKey)
Description copied from interface: SchedulerService
Retrieves the job details for all jobs with the given job runner key.

Parameters:
jobRunnerKey - the job runner key to look up
Returns:
the jobs that are registered with the given job runner key, or an empty collection if there are no jobs that use the given key; never null

getLocalQuartzScheduler

@Deprecated
public org.quartz.Scheduler getLocalQuartzScheduler()
Deprecated. Provided as a last resort only. Avoid accessing Quartz directly if possible. Since v1.0

Returns the actual Quartz scheduler providing local scheduling. This method will be removed in a future release and its use should be avoided if at all possible. It is provided only because Atlassian applications have historically exposed Quartz 1.x to plugins and may need to continue to do so as part of the migration to the atlassian-scheduler library.

Returns:
the actual Quartz scheduler providing local scheduling
See Also:
getClusteredQuartzScheduler()

getClusteredQuartzScheduler

@Deprecated
public org.quartz.Scheduler getClusteredQuartzScheduler()
Deprecated. Provided as a last resort only. Avoid accessing Quartz directly if possible. Since v1.0

Returns the actual Quartz scheduler providing clustered scheduling. This method will be removed in a future release and its use should be avoided if at all possible. It is provided only because Atlassian applications have historically exposed Quartz 1.x to plugins and may need to continue to do so as part of the migration to the atlassian-scheduler library.

Returns:
the actual Quartz scheduler providing clustered scheduling
See Also:
getLocalQuartzScheduler()

startImpl

protected void startImpl()
                  throws SchedulerServiceException
Description copied from class: AbstractSchedulerService
Provided by the scheduler service to implement AbstractSchedulerService.start() requests. This is only ever called while in State#STANDBY, and throwing an exception will prevent the state from being updated.

Specified by:
startImpl in class AbstractSchedulerService
Throws:
SchedulerServiceException - if the scheduler implementation fails to start

standbyImpl

protected void standbyImpl()
                    throws SchedulerServiceException
Description copied from class: AbstractSchedulerService
Provided by the scheduler service to implement AbstractSchedulerService.standby() requests. This is only ever called while in State#STARTED, and throwing an exception will prevent the state from being updated.

Specified by:
standbyImpl in class AbstractSchedulerService
Throws:
SchedulerServiceException - if the scheduler implementation fails to enter standby mode

shutdownImpl

protected void shutdownImpl()
Description copied from class: AbstractSchedulerService
Provided by the scheduler service to implement AbstractSchedulerService.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.

Specified by:
shutdownImpl in class AbstractSchedulerService


Copyright © 2014 Atlassian. All Rights Reserved.