Interface JobStore
-
- All Known Implementing Classes:
JobStoreCMT
,JobStoreSupport
,JobStoreTX
,RAMJobStore
public interface JobStore
The interface to be implemented by classes that want to provide a
andJob
storage mechanism for theTrigger
's use.QuartzScheduler
Storage of
Job
s andTrigger
s should be keyed on the combination of their name and group for uniqueness.- Author:
- James House, Eric Mueller
- See Also:
QuartzScheduler
,Trigger
,Job
,JobDetail
,JobDataMap
,Calendar
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.List<OperableTrigger>
acquireNextTriggers(long noLaterThan, int maxCount, long timeWindow)
Get a handle to the next trigger to be fired, and mark it as 'reserved' by the calling scheduler.boolean
checkExists(JobKey jobKey)
Determine whether aJob
with the given identifier already exists within the scheduler.boolean
checkExists(TriggerKey triggerKey)
Determine whether aTrigger
with the given identifier already exists within the scheduler.void
clearAllSchedulingData()
long
getAcquireRetryDelay(int failureCount)
Get the amount of time (in ms) to wait when accessing this job store repeatedly fails.java.util.List<java.lang.String>
getCalendarNames()
Get the names of all of the
s in theCalendar
JobStore
.long
getEstimatedTimeToReleaseAndAcquireTrigger()
How long (in milliseconds) theJobStore
implementation estimates that it will take to release a trigger and acquire a new one.java.util.List<java.lang.String>
getJobGroupNames()
Get the names of all of the
groups.Job
java.util.Set<JobKey>
getJobKeys(GroupMatcher<JobKey> matcher)
Get the keys of all of the
s that have the given group name.Job
int
getNumberOfCalendars()
Get the number of
s that are stored in theCalendar
JobsStore
.int
getNumberOfJobs()
Get the number of
s that are stored in theJob
JobsStore
.int
getNumberOfTriggers()
Get the number of
s that are stored in theTrigger
JobsStore
.java.util.Set<java.lang.String>
getPausedTriggerGroups()
java.util.List<java.lang.String>
getTriggerGroupNames()
Get the names of all of the
groups.Trigger
java.util.Set<TriggerKey>
getTriggerKeys(GroupMatcher<TriggerKey> matcher)
Get the names of all of the
s that have the given group name.Trigger
java.util.List<OperableTrigger>
getTriggersForJob(JobKey jobKey)
Get all of the Triggers that are associated to the given Job.Trigger.TriggerState
getTriggerState(TriggerKey triggerKey)
Get the current state of the identified
.Trigger
void
initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler)
Called by the QuartzScheduler before theJobStore
is used, in order to give the it a chance to initialize.boolean
isClustered()
Whether or not theJobStore
implementation is clustered.void
pauseAll()
Pause all triggers - equivalent of callingpauseTriggerGroup(group)
on every group.void
pauseJob(JobKey jobKey)
Pause the
with the given name - by pausing all of its currentJob
Trigger
s.java.util.Collection<java.lang.String>
pauseJobs(GroupMatcher<JobKey> groupMatcher)
Pause all of the
in the given group - by pausing all of theirJob
sTrigger
s.void
pauseTrigger(TriggerKey triggerKey)
Pause the
with the given key.Trigger
java.util.Collection<java.lang.String>
pauseTriggers(GroupMatcher<TriggerKey> matcher)
Pause all of the
in the given group.Trigger
svoid
releaseAcquiredTrigger(OperableTrigger trigger)
Inform theJobStore
that the scheduler no longer plans to fire the givenTrigger
, that it had previously acquired (reserved).boolean
removeCalendar(java.lang.String calName)
Remove (delete) the
with the given name.Calendar
boolean
removeJob(JobKey jobKey)
boolean
removeJobs(java.util.List<JobKey> jobKeys)
boolean
removeTrigger(TriggerKey triggerKey)
Remove (delete) the
with the given key.Trigger
boolean
removeTriggers(java.util.List<TriggerKey> triggerKeys)
boolean
replaceTrigger(TriggerKey triggerKey, OperableTrigger newTrigger)
Remove (delete) the
with the given key, and store the new given one - which must be associated with the same job.Trigger
void
resetTriggerFromErrorState(TriggerKey triggerKey)
Reset the current state of the identified
fromTrigger
Trigger.TriggerState.ERROR
toTrigger.TriggerState.NORMAL
orTrigger.TriggerState.PAUSED
as appropriate.void
resumeAll()
Resume (un-pause) all triggers - equivalent of callingresumeTriggerGroup(group)
on every group.void
resumeJob(JobKey jobKey)
Resume (un-pause) the
with the given key.Job
java.util.Collection<java.lang.String>
resumeJobs(GroupMatcher<JobKey> matcher)
Resume (un-pause) all of the
in the given group.Job
svoid
resumeTrigger(TriggerKey triggerKey)
Resume (un-pause) the
with the given key.Trigger
java.util.Collection<java.lang.String>
resumeTriggers(GroupMatcher<TriggerKey> matcher)
Resume (un-pause) all of the
in the given group.Trigger
sCalendar
retrieveCalendar(java.lang.String calName)
Retrieve the given
.Trigger
JobDetail
retrieveJob(JobKey jobKey)
OperableTrigger
retrieveTrigger(TriggerKey triggerKey)
Retrieve the given
.Trigger
void
schedulerPaused()
Called by the QuartzScheduler to inform theJobStore
that the scheduler has been paused.void
schedulerResumed()
Called by the QuartzScheduler to inform theJobStore
that the scheduler has resumed after being paused.void
schedulerStarted()
Called by the QuartzScheduler to inform theJobStore
that the scheduler has started.void
setInstanceId(java.lang.String schedInstId)
Inform theJobStore
of the Scheduler instance's Id, prior to initialize being invoked.void
setInstanceName(java.lang.String schedName)
Inform theJobStore
of the Scheduler instance's name, prior to initialize being invoked.void
setThreadPoolSize(int poolSize)
Tells the JobStore the pool size used to execute jobsvoid
shutdown()
Called by the QuartzScheduler to inform theJobStore
that it should free up all of it's resources because the scheduler is shutting down.void
storeCalendar(java.lang.String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers)
Store the given
.Calendar
void
storeJob(JobDetail newJob, boolean replaceExisting)
Store the given
.JobDetail
void
storeJobAndTrigger(JobDetail newJob, OperableTrigger newTrigger)
void
storeJobsAndTriggers(java.util.Map<JobDetail,java.util.Set<? extends Trigger>> triggersAndJobs, boolean replace)
void
storeTrigger(OperableTrigger newTrigger, boolean replaceExisting)
Store the given
.Trigger
boolean
supportsPersistence()
void
triggeredJobComplete(OperableTrigger trigger, JobDetail jobDetail, Trigger.CompletedExecutionInstruction triggerInstCode)
Inform theJobStore
that the scheduler has completed the firing of the givenTrigger
(and the execution of its associatedJob
completed, threw an exception, or was vetoed), and that the
in the givenJobDataMap
JobDetail
should be updated if theJob
is stateful.java.util.List<TriggerFiredResult>
triggersFired(java.util.List<OperableTrigger> triggers)
Inform theJobStore
that the scheduler is now firing the givenTrigger
(executing its associatedJob
), that it had previously acquired (reserved).
-
-
-
Method Detail
-
initialize
void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException
Called by the QuartzScheduler before theJobStore
is used, in order to give the it a chance to initialize.- Throws:
SchedulerConfigException
-
schedulerStarted
void schedulerStarted() throws SchedulerException
Called by the QuartzScheduler to inform theJobStore
that the scheduler has started.- Throws:
SchedulerException
-
schedulerPaused
void schedulerPaused()
Called by the QuartzScheduler to inform theJobStore
that the scheduler has been paused.
-
schedulerResumed
void schedulerResumed()
Called by the QuartzScheduler to inform theJobStore
that the scheduler has resumed after being paused.
-
shutdown
void shutdown()
Called by the QuartzScheduler to inform theJobStore
that it should free up all of it's resources because the scheduler is shutting down.
-
supportsPersistence
boolean supportsPersistence()
-
getEstimatedTimeToReleaseAndAcquireTrigger
long getEstimatedTimeToReleaseAndAcquireTrigger()
How long (in milliseconds) theJobStore
implementation estimates that it will take to release a trigger and acquire a new one.
-
isClustered
boolean isClustered()
Whether or not theJobStore
implementation is clustered.
-
storeJobAndTrigger
void storeJobAndTrigger(JobDetail newJob, OperableTrigger newTrigger) throws ObjectAlreadyExistsException, JobPersistenceException
- Parameters:
newJob
- TheJobDetail
to be stored.newTrigger
- TheTrigger
to be stored.- Throws:
ObjectAlreadyExistsException
- if aJob
with the same name/group already exists.JobPersistenceException
-
storeJob
void storeJob(JobDetail newJob, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException
Store the given
.JobDetail
- Parameters:
newJob
- TheJobDetail
to be stored.replaceExisting
- Iftrue
, anyJob
existing in theJobStore
with the same name and group should be over-written.- Throws:
ObjectAlreadyExistsException
- if aJob
with the same name/group already exists, and replaceExisting is set to false.JobPersistenceException
-
storeJobsAndTriggers
void storeJobsAndTriggers(java.util.Map<JobDetail,java.util.Set<? extends Trigger>> triggersAndJobs, boolean replace) throws ObjectAlreadyExistsException, JobPersistenceException
-
removeJob
boolean removeJob(JobKey jobKey) throws JobPersistenceException
Remove (delete) the
with the given key, and anyJob
s that reference it.Trigger
If removal of the
Job
results in an empty group, the group should be removed from theJobStore
's list of known group names.- Returns:
true
if aJob
with the given name and group was found and removed from the store.- Throws:
JobPersistenceException
-
removeJobs
boolean removeJobs(java.util.List<JobKey> jobKeys) throws JobPersistenceException
- Throws:
JobPersistenceException
-
retrieveJob
JobDetail retrieveJob(JobKey jobKey) throws JobPersistenceException
- Returns:
- The desired
Job
, or null if there is no match. - Throws:
JobPersistenceException
-
storeTrigger
void storeTrigger(OperableTrigger newTrigger, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException
Store the given
.Trigger
- Parameters:
newTrigger
- TheTrigger
to be stored.replaceExisting
- Iftrue
, anyTrigger
existing in theJobStore
with the same name and group should be over-written.- Throws:
ObjectAlreadyExistsException
- if aTrigger
with the same name/group already exists, and replaceExisting is set to false.JobPersistenceException
- See Also:
pauseTriggers(org.quartz.impl.matchers.GroupMatcher)
-
removeTrigger
boolean removeTrigger(TriggerKey triggerKey) throws JobPersistenceException
Remove (delete) the
with the given key.Trigger
If removal of the
Trigger
results in an empty group, the group should be removed from theJobStore
's list of known group names.If removal of the
Trigger
results in an 'orphaned'Job
that is not 'durable', then theJob
should be deleted also.- Returns:
true
if aTrigger
with the given name and group was found and removed from the store.- Throws:
JobPersistenceException
-
removeTriggers
boolean removeTriggers(java.util.List<TriggerKey> triggerKeys) throws JobPersistenceException
- Throws:
JobPersistenceException
-
replaceTrigger
boolean replaceTrigger(TriggerKey triggerKey, OperableTrigger newTrigger) throws JobPersistenceException
Remove (delete) the
with the given key, and store the new given one - which must be associated with the same job.Trigger
- Parameters:
newTrigger
- The newTrigger
to be stored.- Returns:
true
if aTrigger
with the given name and group was found and removed from the store.- Throws:
JobPersistenceException
-
retrieveTrigger
OperableTrigger retrieveTrigger(TriggerKey triggerKey) throws JobPersistenceException
Retrieve the given
.Trigger
- Returns:
- The desired
Trigger
, or null if there is no match. - Throws:
JobPersistenceException
-
checkExists
boolean checkExists(JobKey jobKey) throws JobPersistenceException
Determine whether aJob
with the given identifier already exists within the scheduler.- Parameters:
jobKey
- the identifier to check for- Returns:
- true if a Job exists with the given identifier
- Throws:
JobPersistenceException
-
checkExists
boolean checkExists(TriggerKey triggerKey) throws JobPersistenceException
Determine whether aTrigger
with the given identifier already exists within the scheduler.- Parameters:
triggerKey
- the identifier to check for- Returns:
- true if a Trigger exists with the given identifier
- Throws:
JobPersistenceException
-
clearAllSchedulingData
void clearAllSchedulingData() throws JobPersistenceException
- Throws:
JobPersistenceException
-
storeCalendar
void storeCalendar(java.lang.String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers) throws ObjectAlreadyExistsException, JobPersistenceException
Store the given
.Calendar
- Parameters:
calendar
- TheCalendar
to be stored.replaceExisting
- Iftrue
, anyCalendar
existing in theJobStore
with the same name and group should be over-written.updateTriggers
- Iftrue
, anyTrigger
s existing in theJobStore
that reference an existing Calendar with the same name with have their next fire time re-computed with the newCalendar
.- Throws:
ObjectAlreadyExistsException
- if aCalendar
with the same name already exists, and replaceExisting is set to false.JobPersistenceException
-
removeCalendar
boolean removeCalendar(java.lang.String calName) throws JobPersistenceException
Remove (delete) the
with the given name.Calendar
If removal of the
*Calendar
would result inTrigger
s pointing to non-existent calendars, then aJobPersistenceException
will be thrown.- Parameters:
calName
- The name of theCalendar
to be removed.- Returns:
true
if aCalendar
with the given name was found and removed from the store.- Throws:
JobPersistenceException
-
retrieveCalendar
Calendar retrieveCalendar(java.lang.String calName) throws JobPersistenceException
Retrieve the given
.Trigger
- Parameters:
calName
- The name of theCalendar
to be retrieved.- Returns:
- The desired
Calendar
, or null if there is no match. - Throws:
JobPersistenceException
-
getNumberOfJobs
int getNumberOfJobs() throws JobPersistenceException
Get the number of
s that are stored in theJob
JobsStore
.- Throws:
JobPersistenceException
-
getNumberOfTriggers
int getNumberOfTriggers() throws JobPersistenceException
Get the number of
s that are stored in theTrigger
JobsStore
.- Throws:
JobPersistenceException
-
getNumberOfCalendars
int getNumberOfCalendars() throws JobPersistenceException
Get the number of
s that are stored in theCalendar
JobsStore
.- Throws:
JobPersistenceException
-
getJobKeys
java.util.Set<JobKey> getJobKeys(GroupMatcher<JobKey> matcher) throws JobPersistenceException
Get the keys of all of the
s that have the given group name.Job
If there are no jobs in the given group name, the result should be an empty collection (not
null
).- Throws:
JobPersistenceException
-
getTriggerKeys
java.util.Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException
Get the names of all of the
s that have the given group name.Trigger
If there are no triggers in the given group name, the result should be a zero-length array (not
null
).- Throws:
JobPersistenceException
-
getJobGroupNames
java.util.List<java.lang.String> getJobGroupNames() throws JobPersistenceException
Get the names of all of the
groups.Job
If there are no known group names, the result should be a zero-length array (not
null
).- Throws:
JobPersistenceException
-
getTriggerGroupNames
java.util.List<java.lang.String> getTriggerGroupNames() throws JobPersistenceException
Get the names of all of the
groups.Trigger
If there are no known group names, the result should be a zero-length array (not
null
).- Throws:
JobPersistenceException
-
getCalendarNames
java.util.List<java.lang.String> getCalendarNames() throws JobPersistenceException
Get the names of all of the
s in theCalendar
JobStore
.If there are no Calendars in the given group name, the result should be a zero-length array (not
null
).- Throws:
JobPersistenceException
-
getTriggersForJob
java.util.List<OperableTrigger> getTriggersForJob(JobKey jobKey) throws JobPersistenceException
Get all of the Triggers that are associated to the given Job.If there are no matches, a zero-length array should be returned.
- Throws:
JobPersistenceException
-
getTriggerState
Trigger.TriggerState getTriggerState(TriggerKey triggerKey) throws JobPersistenceException
Get the current state of the identified
.Trigger
- Throws:
JobPersistenceException
- See Also:
Trigger.TriggerState
-
resetTriggerFromErrorState
void resetTriggerFromErrorState(TriggerKey triggerKey) throws JobPersistenceException
Reset the current state of the identified
fromTrigger
Trigger.TriggerState.ERROR
toTrigger.TriggerState.NORMAL
orTrigger.TriggerState.PAUSED
as appropriate.Only affects triggers that are in ERROR state - if identified trigger is not in that state then the result is a no-op.
The result will be the trigger returning to the normal, waiting to be fired state, unless the trigger's group has been paused, in which case it will go into the PAUSED state.
- Throws:
JobPersistenceException
-
pauseTrigger
void pauseTrigger(TriggerKey triggerKey) throws JobPersistenceException
Pause the
with the given key.Trigger
- Throws:
JobPersistenceException
- See Also:
resumeTrigger(TriggerKey)
-
pauseTriggers
java.util.Collection<java.lang.String> pauseTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException
Pause all of the
in the given group.Trigger
sThe JobStore should "remember" that the group is paused, and impose the pause on any new triggers that are added to the group while the group is paused.
- Throws:
JobPersistenceException
- See Also:
resumeTriggers(GroupMatcher)
-
pauseJob
void pauseJob(JobKey jobKey) throws JobPersistenceException
Pause the
with the given name - by pausing all of its currentJob
Trigger
s.- Throws:
JobPersistenceException
- See Also:
resumeJob(JobKey)
-
pauseJobs
java.util.Collection<java.lang.String> pauseJobs(GroupMatcher<JobKey> groupMatcher) throws JobPersistenceException
Pause all of the
in the given group - by pausing all of theirJob
sTrigger
s.The JobStore should "remember" that the group is paused, and impose the pause on any new jobs that are added to the group while the group is paused.
- Throws:
JobPersistenceException
- See Also:
resumeJobs(GroupMatcher)
-
resumeTrigger
void resumeTrigger(TriggerKey triggerKey) throws JobPersistenceException
Resume (un-pause) the
with the given key.Trigger
If the
Trigger
missed one or more fire-times, then theTrigger
's misfire instruction will be applied.- Throws:
JobPersistenceException
- See Also:
pauseTrigger(TriggerKey)
-
resumeTriggers
java.util.Collection<java.lang.String> resumeTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException
Resume (un-pause) all of the
in the given group.Trigger
sIf any
Trigger
missed one or more fire-times, then theTrigger
's misfire instruction will be applied.- Throws:
JobPersistenceException
- See Also:
pauseTriggers(GroupMatcher)
-
getPausedTriggerGroups
java.util.Set<java.lang.String> getPausedTriggerGroups() throws JobPersistenceException
- Throws:
JobPersistenceException
-
resumeJob
void resumeJob(JobKey jobKey) throws JobPersistenceException
Resume (un-pause) the
with the given key.Job
If any of the
Job
'sTrigger
s missed one or more fire-times, then theTrigger
's misfire instruction will be applied.- Throws:
JobPersistenceException
- See Also:
pauseJob(JobKey)
-
resumeJobs
java.util.Collection<java.lang.String> resumeJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException
Resume (un-pause) all of the
in the given group.Job
sIf any of the
Job
s hadTrigger
s that missed one or more fire-times, then theTrigger
's misfire instruction will be applied.- Throws:
JobPersistenceException
- See Also:
pauseJobs(GroupMatcher)
-
pauseAll
void pauseAll() throws JobPersistenceException
Pause all triggers - equivalent of callingpauseTriggerGroup(group)
on every group.When
resumeAll()
is called (to un-pause), trigger misfire instructions WILL be applied.- Throws:
JobPersistenceException
- See Also:
resumeAll()
,pauseTriggers(GroupMatcher)
-
resumeAll
void resumeAll() throws JobPersistenceException
Resume (un-pause) all triggers - equivalent of callingresumeTriggerGroup(group)
on every group.If any
Trigger
missed one or more fire-times, then theTrigger
's misfire instruction will be applied.- Throws:
JobPersistenceException
- See Also:
pauseAll()
-
acquireNextTriggers
java.util.List<OperableTrigger> acquireNextTriggers(long noLaterThan, int maxCount, long timeWindow) throws JobPersistenceException
Get a handle to the next trigger to be fired, and mark it as 'reserved' by the calling scheduler.- Parameters:
noLaterThan
- If > 0, the JobStore should only return a Trigger that will fire no later than the time represented in this value as milliseconds.- Throws:
JobPersistenceException
- See Also:
releaseAcquiredTrigger(OperableTrigger)
-
releaseAcquiredTrigger
void releaseAcquiredTrigger(OperableTrigger trigger)
Inform theJobStore
that the scheduler no longer plans to fire the givenTrigger
, that it had previously acquired (reserved).
-
triggersFired
java.util.List<TriggerFiredResult> triggersFired(java.util.List<OperableTrigger> triggers) throws JobPersistenceException
Inform theJobStore
that the scheduler is now firing the givenTrigger
(executing its associatedJob
), that it had previously acquired (reserved).- Returns:
- may return null if all the triggers or their calendars no longer exist, or if the trigger was not successfully put into the 'executing' state. Preference is to return an empty list if none of the triggers could be fired.
- Throws:
JobPersistenceException
-
triggeredJobComplete
void triggeredJobComplete(OperableTrigger trigger, JobDetail jobDetail, Trigger.CompletedExecutionInstruction triggerInstCode)
Inform theJobStore
that the scheduler has completed the firing of the givenTrigger
(and the execution of its associatedJob
completed, threw an exception, or was vetoed), and that the
in the givenJobDataMap
JobDetail
should be updated if theJob
is stateful.
-
setInstanceId
void setInstanceId(java.lang.String schedInstId)
Inform theJobStore
of the Scheduler instance's Id, prior to initialize being invoked.- Since:
- 1.7
-
setInstanceName
void setInstanceName(java.lang.String schedName)
Inform theJobStore
of the Scheduler instance's name, prior to initialize being invoked.- Since:
- 1.7
-
setThreadPoolSize
void setThreadPoolSize(int poolSize)
Tells the JobStore the pool size used to execute jobs- Parameters:
poolSize
- amount of threads allocated for job execution- Since:
- 2.0
-
getAcquireRetryDelay
long getAcquireRetryDelay(int failureCount)
Get the amount of time (in ms) to wait when accessing this job store repeatedly fails. Called by the executor thread(s) when calls toacquireNextTriggers(long, int, long)
fail more than once in succession, and the thread thus wants to wait a bit before trying again, to not consume 100% CPU, write huge amounts of errors into logs, etc. in cases like the DB being offline/restarting. The delay returned by implementations should be between 20 and 600000 milliseconds.- Parameters:
failureCount
- the number of successive failures seen so far- Returns:
- the time (in milliseconds) to wait before trying again
-
-