public class JobSchedulerImpl extends ServiceSupport implements Runnable, JobScheduler
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(JobListener l)
Add a Job listener which will receive events related to scheduled jobs.
|
protected void |
doStart() |
protected void |
doStop(ServiceStopper stopper) |
List<Job> |
getAllJobs()
Get all the outstanding Jobs
|
List<Job> |
getAllJobs(long start,
long finish)
Get all outstanding jobs due to run between start and finish
|
protected List<org.apache.activemq.store.kahadb.scheduler.JobLocation> |
getAllScheduledJobs(Transaction tx)
Walks the Scheduled Job Tree and collects the add location and last update location
for all scheduled jobs.
|
String |
getName() |
List<Job> |
getNextScheduleJobs()
Get all the jobs scheduled to run next
|
long |
getNextScheduleTime()
Get the next time jobs will be fired
|
protected void |
mainLoop() |
protected void |
process(Transaction tx,
KahaAddScheduledJobCommand command,
Location location)
Adds a new Scheduled job to the index.
|
protected void |
process(Transaction tx,
KahaRemoveScheduledJobsCommand command,
Location location)
Removes all scheduled jobs within a given time range.
|
protected void |
process(Transaction tx,
KahaRescheduleJobCommand command,
Location location)
Reschedules a Job after it has be fired.
|
void |
remove(long time)
remove all jobs scheduled to run at this time
|
void |
remove(String jobId)
remove a job with the matching jobId
|
protected void |
removeAll(Transaction tx)
Removes all jobs from the schedulers index.
|
void |
removeAllJobs()
remove all the Jobs from the scheduler
|
void |
removeAllJobs(long start,
long finish)
remove all the Jobs from the scheduler that are due between the start and finish times
|
protected void |
removeInRange(Transaction tx,
long start,
long finish,
Location location)
Removes all scheduled jobs within the target range.
|
protected boolean |
removeJobAtTime(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.
|
void |
removeListener(JobListener l)
remove a JobListener that was previously registered.
|
void |
run() |
void |
schedule(String jobId,
ByteSequence payload,
long delay)
Add a job to be scheduled
|
void |
schedule(String jobId,
ByteSequence payload,
String cronEntry)
Add a job to be scheduled
|
void |
schedule(String jobId,
ByteSequence payload,
String cronEntry,
long delay,
long period,
int repeat)
Add a job to be scheduled
|
void |
setName(String name) |
void |
startDispatching()
Starts dispatch of scheduled Jobs to registered listeners.
|
void |
stopDispatching()
Stops dispatching of scheduled Jobs to registered listeners.
|
String |
toString() |
void |
write(DataOutput out) |
addServiceListener, dispose, isStarted, isStopped, isStopping, postStop, preStart, removeServiceListener, start, stoppublic String getName()
getName in interface JobSchedulerpublic void addListener(JobListener l)
JobScheduleraddListener in interface JobSchedulerl - The job listener to add.public void removeListener(JobListener l)
JobSchedulerremoveListener in interface JobSchedulerl - The listener that should be removed from the listener registry.public void schedule(String jobId, ByteSequence payload, long delay) throws IOException
JobSchedulerschedule in interface JobSchedulerjobId - a unique identifier for the jobpayload - the message to be sent when the job is scheduleddelay - the time in milliseconds before the job will be runIOExceptionpublic void schedule(String jobId, ByteSequence payload, String cronEntry) throws Exception
JobSchedulerschedule in interface JobSchedulerjobId - a unique identifier for the jobpayload - the message to be sent when the job is scheduledcronEntry - The cron entry to use to schedule this job.Exception - if an error occurs while scheduling the Job.public void schedule(String jobId, ByteSequence payload, String cronEntry, long delay, long period, int repeat) throws IOException
JobSchedulerschedule in interface JobSchedulerjobId - a unique identifier for the jobpayload - the message to be sent when the job is scheduledcronEntry - cron entrydelay - time in ms to wait before schedulingperiod - the time in milliseconds between successive executions of the Jobrepeat - the number of times to execute the job - less than 0 will be repeated foreverIOExceptionpublic void remove(long time) throws IOException
JobSchedulerremove in interface JobSchedulertime - The UTC time to use to remove a batch of scheduled Jobs.IOExceptionpublic void remove(String jobId) throws IOException
JobSchedulerremove in interface JobSchedulerjobId - The unique Job Id to search for and remove from the scheduled set of jobs.IOExceptionpublic void removeAllJobs() throws IOException
JobSchedulerremoveAllJobs in interface JobSchedulerIOExceptionpublic void removeAllJobs(long start, long finish) throws IOException
JobSchedulerremoveAllJobs in interface JobSchedulerstart - time in millisecondsfinish - time in millisecondsIOExceptionpublic long getNextScheduleTime() throws IOException
JobSchedulergetNextScheduleTime in interface JobSchedulerIOExceptionpublic List<Job> getNextScheduleJobs() throws IOException
JobSchedulergetNextScheduleJobs in interface JobSchedulerIOExceptionpublic List<Job> getAllJobs() throws IOException
JobSchedulergetAllJobs in interface JobSchedulerIOExceptionpublic List<Job> getAllJobs(long start, long finish) throws IOException
JobSchedulergetAllJobs in interface JobSchedulerIOExceptionprotected void process(Transaction tx, KahaAddScheduledJobCommand command, Location location) throws IOException
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.IOException - if an error occurs updating the index.protected void process(Transaction tx, KahaRescheduleJobCommand command, Location location) throws IOException
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.IOException - if an error occurs during the reschedule.protected void process(Transaction tx, KahaRemoveScheduledJobsCommand command, Location location) throws IOException
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.IOException - if an error occurs while updating the scheduler index.protected void removeAll(Transaction tx) throws IOException
tx - The transaction under which the index entries for this scheduler are removed.IOException - if an error occurs removing the jobs from the scheduler index.protected void removeInRange(Transaction tx, long start, long finish, Location location) throws IOException
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.IOException - if an error occurs during the remove operation.protected boolean removeJobAtTime(Transaction tx, String jobId, long executionTime) throws IOException
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.IOException - if an error occurs while removing the Job.protected List<org.apache.activemq.store.kahadb.scheduler.JobLocation> getAllScheduledJobs(Transaction tx) throws IOException
tx - the transaction under which this operation was invoked.IOException - if an error occurs walking the scheduler tree.protected void mainLoop()
public void startDispatching() throws Exception
JobSchedulerstartDispatching in interface JobSchedulerExceptionpublic void stopDispatching() throws Exception
JobSchedulerstopDispatching in interface JobSchedulerExceptionprotected void doStart() throws Exception
doStart in class ServiceSupportExceptionprotected void doStop(ServiceStopper stopper) throws Exception
doStop in class ServiceSupportExceptionpublic void write(DataOutput out) throws IOException
IOExceptionCopyright © 2005–2016 The Apache Software Foundation. All rights reserved.