Class JobSchedulerImpl
java.lang.Object
org.apache.activemq.util.ServiceSupport
org.apache.activemq.store.kahadb.scheduler.JobSchedulerImpl
- All Implemented Interfaces:
Runnable,JobScheduler,org.apache.activemq.Service
-
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voiddoStart()protected voiddoStop(ServiceStopper stopper) getAllJobs(long start, long finish) protected Iterator<org.apache.activemq.store.kahadb.scheduler.JobLocation>Walks the Scheduled Job Tree and collects the add location and last update location for all scheduled jobs.getName()longprotected voidmainLoop()protected voidprocess(Transaction tx, KahaAddScheduledJobCommand command, Location location) Adds a new Scheduled job to the index.protected voidprocess(Transaction tx, KahaRemoveScheduledJobsCommand command, Location location) Removes all scheduled jobs within a given time range.protected voidprocess(Transaction tx, KahaRescheduleJobCommand command, Location location) Reschedules a Job after it has be fired.voidremove(long time) voidprotected voidremoveAll(Transaction tx) Removes all jobs from the schedulers index.voidvoidremoveAllJobs(long start, long finish) protected voidremoveInRange(Transaction tx, long start, long finish, Location location) Removes all scheduled jobs within the target range.protected booleanremoveJobAtTime(Transaction tx, String jobId, long executionTime) Removes a Job from the index using it's Id value and the time it is currently set to be executed.voidvoidrun()voidschedule(String jobId, ByteSequence payload, long delay) voidschedule(String jobId, ByteSequence payload, String cronEntry) voidschedule(String jobId, ByteSequence payload, String cronEntry, long delay, long period, int repeat) voidvoidvoidtoString()voidwrite(DataOutput out) Methods inherited from class org.apache.activemq.util.ServiceSupport
addServiceListener, dispose, isStarted, isStopped, isStopping, postStop, preStart, removeServiceListener, start, stop
-
Method Details
-
setName
-
getName
- Specified by:
getNamein interfaceJobScheduler
-
addListener
- Specified by:
addListenerin interfaceJobScheduler
-
removeListener
- Specified by:
removeListenerin interfaceJobScheduler
-
schedule
- Specified by:
schedulein interfaceJobScheduler- Throws:
IOException
-
schedule
- Specified by:
schedulein interfaceJobScheduler- Throws:
Exception
-
schedule
public void schedule(String jobId, ByteSequence payload, String cronEntry, long delay, long period, int repeat) throws IOException - Specified by:
schedulein interfaceJobScheduler- Throws:
IOException
-
remove
- Specified by:
removein interfaceJobScheduler- Throws:
IOException
-
remove
- Specified by:
removein interfaceJobScheduler- Throws:
IOException
-
removeAllJobs
- Specified by:
removeAllJobsin interfaceJobScheduler- Throws:
IOException
-
removeAllJobs
- Specified by:
removeAllJobsin interfaceJobScheduler- Throws:
IOException
-
getNextScheduleTime
- Specified by:
getNextScheduleTimein interfaceJobScheduler- Throws:
IOException
-
getNextScheduleJobs
- Specified by:
getNextScheduleJobsin interfaceJobScheduler- Throws:
IOException
-
getAllJobs
- Specified by:
getAllJobsin interfaceJobScheduler- Throws:
IOException
-
getAllJobs
- Specified by:
getAllJobsin interfaceJobScheduler- Throws:
IOException
-
process
protected void process(Transaction tx, KahaAddScheduledJobCommand command, Location location) throws IOException Adds a new Scheduled job to the index. Must be called under index lock. This method must ensure that a duplicate add is not processed into the scheduler. On index recover some adds may be replayed and we don't allow more than one instance of a JobId to exist at any given scheduled time, so filter these out to ensure idempotence.- Parameters:
tx- Transaction in which the update is performed.command- The new scheduled job command to process.location- The location where the add command is stored in the journal.- Throws:
IOException- if an error occurs updating the index.
-
process
protected void process(Transaction tx, KahaRescheduleJobCommand command, Location location) throws IOException Reschedules a Job after it has be fired. For jobs that are repeating this method updates the job in the index by adding it to the jobs list for the new execution time. If the job is not a cron type job then this method will reduce the repeat counter if the job has a fixed number of repeats set. The Job will be removed from the jobs list it just executed on. This method must also update the value of the last update location in the JobLocation instance so that the checkpoint worker doesn't drop the log file in which that command lives. This method must ensure that an reschedule command that references a job that doesn't exist does not cause an error since it's possible that on recover the original add might be gone and so the job should not reappear in the scheduler.- Parameters:
tx- The TX under which the index is updated.command- The reschedule command to process.location- The location in the index where the reschedule command was stored.- Throws:
IOException- if an error occurs during the reschedule.
-
process
protected void process(Transaction tx, KahaRemoveScheduledJobsCommand command, Location location) throws IOException Removes all scheduled jobs within a given time range. The method can be used to clear the entire scheduler index by specifying a range that encompasses all time [0...Long.MAX_VALUE] or a single execution time can be removed by setting start and end time to the same value.- Parameters:
tx- The transaction under which the index is updated.command- The remove command to process.location- The location of the remove command in the Journal.- Throws:
IOException- if an error occurs while updating the scheduler index.
-
removeAll
Removes all jobs from the schedulers index. Must be called with the index locked.- Parameters:
tx- The transaction under which the index entries for this scheduler are removed.- Throws:
IOException- if an error occurs removing the jobs from the scheduler index.
-
removeInRange
protected void removeInRange(Transaction tx, long start, long finish, Location location) throws IOException Removes all scheduled jobs within the target range. This method can be used to remove all the stored jobs by passing a range of [0...Long.MAX_VALUE] or it can be used to remove all jobs at a given scheduled time by passing the same time value for both start and end. If the optional location parameter is set then this method will update the store's remove location tracker with the location value and the Jobs that are being removed. This method must be called with the store index locked for writes.- Parameters:
tx- The transaction under which the index is to be updated.start- The start time for the remove operation.finish- The end time for the remove operation.location- (optional) The location of the remove command that triggered this remove.- Throws:
IOException- if an error occurs during the remove operation.
-
removeJobAtTime
protected boolean removeJobAtTime(Transaction tx, String jobId, long executionTime) throws IOException Removes a Job from the index using it's Id value and the time it is currently set to be executed. This method will only remove the Job if it is found at the given execution time. This method must be called under index lock.- Parameters:
tx- the transaction under which this method is being executed.jobId- the target Job Id to remove.executionTime- the scheduled time that for the Job Id that is being removed.- Throws:
IOException- if an error occurs while removing the Job.
-
getAllScheduledJobs
protected Iterator<org.apache.activemq.store.kahadb.scheduler.JobLocation> getAllScheduledJobs(Transaction tx) throws IOException Walks the Scheduled Job Tree and collects the add location and last update location for all scheduled jobs. This method must be called with the index locked.- Parameters:
tx- the transaction under which this operation was invoked.- Returns:
- a iterator of all referenced Location values for this JobSchedulerImpl
- Throws:
IOException- if an error occurs walking the scheduler tree.
-
run
public void run() -
toString
-
mainLoop
protected void mainLoop() -
startDispatching
- Specified by:
startDispatchingin interfaceJobScheduler- Throws:
Exception
-
stopDispatching
- Specified by:
stopDispatchingin interfaceJobScheduler- Throws:
Exception
-
doStart
- Specified by:
doStartin classServiceSupport- Throws:
Exception
-
doStop
- Specified by:
doStopin classServiceSupport- Throws:
Exception
-
write
- Throws:
IOException
-