public abstract class AbstractSchedulerService extends Object implements LifecycleAwareSchedulerService
JobRunner registration,
and job status tracking.LifecycleAwareSchedulerService.State| Modifier and Type | Field and Description |
|---|---|
protected static Comparator<JobDetails> |
BY_JOB_ID
Sorts by job ID (and nothing else).
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSchedulerService(RunDetailsDao runDetailsDao) |
protected |
AbstractSchedulerService(RunDetailsDao runDetailsDao,
ParameterMapSerializer parameterMapSerializer) |
| Modifier and Type | Method and Description |
|---|---|
RunDetails |
addRunDetails(JobId jobId,
Date startedAt,
RunOutcome runOutcome,
String message)
Creates or updates the job status record for the given job ID.
|
protected static SchedulerServiceException |
checked(SchedulerRuntimeException sre)
Converts the unchecked
SchedulerRuntimeException to the checked
SchedulerServiceException. |
JobRunner |
getJobRunner(JobRunnerKey jobRunnerKey) |
Collection<RunningJob> |
getLocallyRunningJobs()
Returns the list of jobs that are currently executing on this node.
|
ParameterMapSerializer |
getParameterMapSerializer()
Returns the parameter map serializer used by this scheduler.
|
Set<JobRunnerKey> |
getRegisteredJobRunnerKeys()
Returns all of the job runner keys that currently have registered job runners, regardless
of whether or not any jobs have actually been
scheduled
for them. |
LifecycleAwareSchedulerService.State |
getState()
Returns the scheduler service's running state.
|
void |
postJob()
This method is called after a job has finished execution.
|
void |
preJob()
This method is called before a job begins execution.
|
void |
registerJobRunner(JobRunnerKey jobRunnerKey,
JobRunner jobRunner)
Registers the job runner for a given job runner key.
|
JobId |
scheduleJobWithGeneratedId(JobConfig jobConfig)
Schedules a "dynamic" job by generating a new unique job ID.
|
void |
shutdown()
Permanent shutdown of the scheduler.
|
protected abstract void |
shutdownImpl()
Provided by the scheduler service to implement
shutdown() requests. |
void |
standby()
Places the scheduler into standby mode.
|
protected abstract void |
standbyImpl()
Provided by the scheduler service to implement
standby() requests. |
void |
start()
Starts the scheduler if it had never been started or had been placed in
SchedulerServiceController.standby() mode. |
protected abstract void |
startImpl()
Provided by the scheduler service to implement
start() requests. |
void |
unregisterJobRunner(JobRunnerKey jobRunnerKey)
Unregisters the specified job runner.
|
boolean |
waitUntilIdle(long timeout,
TimeUnit units)
Waits for up to
timeout units for any currently executing jobs to complete. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcalculateNextRunTime, getJobDetails, getJobRunnerKeysForAllScheduledJobs, getJobsByJobRunnerKey, scheduleJob, unscheduleJobprotected static final Comparator<JobDetails> BY_JOB_ID
SchedulerService.getJobsByJobRunnerKey(JobRunnerKey).protected AbstractSchedulerService(RunDetailsDao runDetailsDao)
protected AbstractSchedulerService(RunDetailsDao runDetailsDao, ParameterMapSerializer parameterMapSerializer)
public void registerJobRunner(JobRunnerKey jobRunnerKey, JobRunner jobRunner)
SchedulerServicejobRunnerKey will replace any existing registration.
A job that is scheduled to run but has no registered job runner is reported as
unavailable.
registerJobRunner in interface SchedulerServicejobRunnerKey - Globally unique job runner key.jobRunner - the concrete object capable of running instances of this jobpublic void unregisterJobRunner(JobRunnerKey jobRunnerKey)
SchedulerServiceJobs that fire with no registered job runner will fail to start.
unregisterJobRunner in interface SchedulerServicejobRunnerKey - Globally unique job runner key.public JobRunner getJobRunner(JobRunnerKey jobRunnerKey)
@Nonnull public Set<JobRunnerKey> getRegisteredJobRunnerKeys()
SchedulerServicescheduled
for them. The job runner keys are not guaranteed to be returned in any particular order.getRegisteredJobRunnerKeys in interface SchedulerServiceSchedulerService.getJobRunnerKeysForAllScheduledJobs()@Nonnull public JobId scheduleJobWithGeneratedId(JobConfig jobConfig) throws SchedulerServiceException
SchedulerServiceThis method should normally only be used when creating multiple jobs for a given job runner key that need to run independently — most likely because these are created in response to user input.
scheduleJobWithGeneratedId in interface SchedulerServicejobConfig - 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 RunDetails addRunDetails(JobId jobId, Date startedAt, RunOutcome runOutcome, @Nullable String message)
jobId - the job ID for which the status is being updatedstartedAt - the clock time that the run started atrunOutcome - the result of the runmessage - an optional informational message to include in the RunDetailspublic void preJob()
public void postJob()
public final void start()
throws SchedulerServiceException
SchedulerServiceControllerSchedulerServiceController.standby() mode.
If the scheduler was already active, then the request has no effect.start in interface SchedulerServiceControllerSchedulerServiceException - if the scheduler cannot be startedpublic final void standby()
throws SchedulerServiceException
SchedulerServiceControllerstarted
again. If the scheduler was already in standby, then the request has no effect. The standby mode only
affects the local node's ability to schedule jobs. For any
RunMode.RUN_ONCE_PER_CLUSTER jobs the jobs may still run on other
nodes if they exist and have started. If a job should have run while the scheduler was in standby mode, the
implementation may trigger those jobs when restarted, but this is not guaranteed.standby in interface SchedulerServiceControllerSchedulerServiceException - if the scheduler cannot be be placed in standby modepublic final void shutdown()
SchedulerServiceControllershutdown in interface SchedulerServiceControllerpublic boolean waitUntilIdle(long timeout,
TimeUnit units)
throws InterruptedException
timeout units for any currently executing jobs to complete.
Note that if the scheduler has not been SchedulerServiceController.shutdown() or placed in SchedulerServiceController.standby()
mode, then jobs could start after this returns true. As with SchedulerServiceController.getLocallyRunningJobs(),
this is only aware of jobs running on this node of the cluster, and it is guaranteed to be safe to
call even after a SchedulerServiceController.shutdown().
Implementations may override the default implementation for waitUntilIdle.
The default implementation that AbstractSchedulerService provides will poll
getLocallyRunningJobs() every 100ms until one of the following occurs:
getLocallyRunningJobs() returns an empty collection.waitUntilIdle in interface SchedulerServiceControllertimeout - the timeout period, in the specified units; non-positive values request an immediate
poll — that is, it is equivalent to getLocallyRunningJobs().isEmpty()true if the scheduler is now idle; false if jobs are still executing.InterruptedException - if the current thread is interrupted while waiting for the
scheduler to become idle.@Nonnull public Collection<RunningJob> getLocallyRunningJobs()
SchedulerServiceControllerSchedulerServiceController.shutdown().getLocallyRunningJobs in interface SchedulerServiceController@Nonnull public final LifecycleAwareSchedulerService.State getState()
SchedulerServiceControllerLifecycleAwareSchedulerService.State.STANDBY
and can be moved between this state and LifecycleAwareSchedulerService.State.STANDBY freely. LifecycleAwareSchedulerService.State.SHUTDOWN is
terminal — that is, once shut down, the scheduler's state can no longer be changed.getState in interface SchedulerServiceControllerprotected abstract void startImpl()
throws SchedulerServiceException
start() requests. This
is only ever called while in State#STANDBY, and throwing an exception will
prevent the state from being updated.SchedulerServiceException - if the scheduler implementation fails to startprotected abstract void standbyImpl()
throws SchedulerServiceException
standby() requests. This
is only ever called while in State#STARTED, and throwing an exception will
prevent the state from being updated.SchedulerServiceException - if the scheduler implementation fails to enter standby modeprotected abstract void shutdownImpl()
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.public ParameterMapSerializer getParameterMapSerializer()
protected static SchedulerServiceException checked(SchedulerRuntimeException sre)
SchedulerRuntimeException to the checked
SchedulerServiceException. It makes sense to do this in many cases
where the checked exception is declared, as the caller is already having to
handle it.
The message and cause of the SchedulerServiceException are taken from
the cause of the runtime exception. If no cause
was set, then the runtime exception itself is used.
sre - the scheduler runtime exception to convertCopyright © 2017 Atlassian. All rights reserved.