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, stop
public String getName()
getName
in interface JobScheduler
public void addListener(JobListener l)
JobScheduler
addListener
in interface JobScheduler
l
- The job listener to add.public void removeListener(JobListener l)
JobScheduler
removeListener
in interface JobScheduler
l
- The listener that should be removed from the listener registry.public void schedule(String jobId, ByteSequence payload, long delay) throws IOException
JobScheduler
schedule
in interface JobScheduler
jobId
- 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 runIOException
public void schedule(String jobId, ByteSequence payload, String cronEntry) throws Exception
JobScheduler
schedule
in interface JobScheduler
jobId
- 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
JobScheduler
schedule
in interface JobScheduler
jobId
- 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 foreverIOException
public void remove(long time) throws IOException
JobScheduler
remove
in interface JobScheduler
time
- The UTC time to use to remove a batch of scheduled Jobs.IOException
public void remove(String jobId) throws IOException
JobScheduler
remove
in interface JobScheduler
jobId
- The unique Job Id to search for and remove from the scheduled set of jobs.IOException
public void removeAllJobs() throws IOException
JobScheduler
removeAllJobs
in interface JobScheduler
IOException
public void removeAllJobs(long start, long finish) throws IOException
JobScheduler
removeAllJobs
in interface JobScheduler
start
- time in millisecondsfinish
- time in millisecondsIOException
public long getNextScheduleTime() throws IOException
JobScheduler
getNextScheduleTime
in interface JobScheduler
IOException
public List<Job> getNextScheduleJobs() throws IOException
JobScheduler
getNextScheduleJobs
in interface JobScheduler
IOException
public List<Job> getAllJobs() throws IOException
JobScheduler
getAllJobs
in interface JobScheduler
IOException
public List<Job> getAllJobs(long start, long finish) throws IOException
JobScheduler
getAllJobs
in interface JobScheduler
IOException
protected 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
JobScheduler
startDispatching
in interface JobScheduler
Exception
public void stopDispatching() throws Exception
JobScheduler
stopDispatching
in interface JobScheduler
Exception
protected void doStart() throws Exception
doStart
in class ServiceSupport
Exception
protected void doStop(ServiceStopper stopper) throws Exception
doStop
in class ServiceSupport
Exception
public void write(DataOutput out) throws IOException
IOException
Copyright © 2005–2019 The Apache Software Foundation. All rights reserved.