public class MemoryClusteredJobDao extends Object implements ClusteredJobDao
ClusteredJobDao that is not fully compliant with the SPI.
WARNING: Although otherwise perfectly functional, this implementation is purely RAM-based,
so it does not persist clustered jobs across restarts. This violates the general contract of the
atlassian-scheduler API. In particular, see RunMode.RUN_ONCE_PER_CLUSTER and ClusteredJobDao,
which both make it clear that clustered jobs should survive an application restart. It would therefore be
inappropriate to use this implementation except in very special cases, like functional testing or "dev mode".
Even applications that do not support clustering should avoid using this implementation, as failing to
preserve the jobs across restarts might confuse cross-product plugins.
| Constructor and Description |
|---|
MemoryClusteredJobDao() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
create(ClusteredJob clusteredJob)
Called to create a new clustered job in the database.
|
boolean |
delete(com.atlassian.scheduler.config.JobId jobId)
Called to remove a scheduled cluster job by its ID.
|
ClusteredJob |
find(com.atlassian.scheduler.config.JobId jobId)
Finds and returns the persisted details for a clustered job.
|
Set<com.atlassian.scheduler.config.JobRunnerKey> |
findAllJobRunnerKeys()
Returns the set of distinct job runner keys that have at least one job schedule stored here.
|
Collection<ClusteredJob> |
findByJobRunnerKey(com.atlassian.scheduler.config.JobRunnerKey jobRunnerKey)
Returns all jobs that use the given job runner.
|
Date |
getNextRunTime(com.atlassian.scheduler.config.JobId jobId)
Returns the next run time for the given job ID, if there is one.
|
Long |
getVersion(com.atlassian.scheduler.config.JobId jobId)
Returns the current version of the persisted clustered job with this ID.
|
Map<com.atlassian.scheduler.config.JobId,Date> |
refresh()
Returns the job ID and next run time for every clustered job that should be in the queue.
|
boolean |
updateNextRunTime(com.atlassian.scheduler.config.JobId jobId,
Date nextRunTime,
long expectedVersion)
Updates the next run time for an existing clustered job.
|
@Nullable public Date getNextRunTime(com.atlassian.scheduler.config.JobId jobId)
ClusteredJobDaoImplementations MAY implement this with:
ClusteredJob clusteredJob = find(jobId);
return (clusteredJob != null) ? clusteredJob.getNextRunTime() : null;
However, this would be wasteful, and implementations SHOULD use a more efficient query when possible.
getNextRunTime in interface ClusteredJobDaojobId - the job ID whose existence and current version is to be checkedjobId; null if no such job exists
or if it exists but its schedule prevents it from ever running again.@Nullable public Long getVersion(com.atlassian.scheduler.config.JobId jobId)
ClusteredJobDaoImplementations MAY implement this with:
ClusteredJob clusteredJob = find(jobId);
return (clusteredJob != null) ? clusteredJob.getVersion() : null;
However, this would be wasteful, and implementations SHOULD use a more efficient query when possible.
getVersion in interface ClusteredJobDaojobId - the job ID whose existence and current version is to be checkedjobId, or null if no such job exists@Nullable public ClusteredJob find(com.atlassian.scheduler.config.JobId jobId)
ClusteredJobDaofind in interface ClusteredJobDaojobId - the job ID for the job details to be loadednull if the job does not exist@Nonnull public Collection<ClusteredJob> findByJobRunnerKey(com.atlassian.scheduler.config.JobRunnerKey jobRunnerKey)
ClusteredJobDaoImplementations:
SELECT * FROM jobs WHERE jobRunnerKey = ?
to retrieve all job details that match the given jobRunnerKey.ClusteredJob for each clustered job that has been persisted
with the specified jobRunnerKey.findByJobRunnerKey in interface ClusteredJobDaojobRunnerKey - the job runner key for which to search@Nonnull public Map<com.atlassian.scheduler.config.JobId,Date> refresh()
ClusteredJobDaoImplementations:
SELECT jobId, nextRunTime FROM jobs WHERE nextRunTime IS NOT NULL to retrieve all
existing job IDs that have scheduled next time to run.null for any entry in the
returned map.refresh in interface ClusteredJobDao@Nonnull public Set<com.atlassian.scheduler.config.JobRunnerKey> findAllJobRunnerKeys()
ClusteredJobDaoImplementations:
SELECT DISTINCT jobRunnerKey FROM jobs
to retrieve all unique job runner keys.nextRunTime is null or not.findAllJobRunnerKeys in interface ClusteredJobDaopublic boolean create(ClusteredJob clusteredJob)
ClusteredJobDaoImplementations:
INSERT INTO jobs ... VALUES ...
to create a representation of this job.false rather than throw an exception if the request fails
due to a UNIQUE constraintSELECT for a conflicting
entry if the persistence layer does not make it possible to distinguish UNIQUE constraint
failures reliably.create in interface ClusteredJobDaoclusteredJob - the job details to be createdpublic boolean updateNextRunTime(com.atlassian.scheduler.config.JobId jobId,
@Nullable
Date nextRunTime,
long expectedVersion)
ClusteredJobDaoImplementations:
UPDATE jobs SET nextRunTime = ?, version = ? WHERE jobId = ? AND version = ?false if no rows are updated, whether because the job does not
exist or because the specified version is incorrect.updateNextRunTime in interface ClusteredJobDaojobId - the job ID for which to update the next run timenextRunTime - the new next run time, or null if it will never run againexpectedVersion - the version of the job details that are expected to be foundtrue if the update is successful; false otherwisepublic boolean delete(com.atlassian.scheduler.config.JobId jobId)
ClusteredJobDaoImplementations:
DELETE FROM jobs WHERE jobId = ?false if there is no matching row to delete; note that this
is not an error and the implementation MUST NOT throw an exception for itdelete in interface ClusteredJobDaojobId - the job to be unscheduledtrue if the job is successfully removed; false, otherwiseCopyright © 2019 Atlassian. All rights reserved.