Class InMemoryJobScheduler
- java.lang.Object
-
- org.apache.activemq.broker.scheduler.memory.InMemoryJobScheduler
-
- All Implemented Interfaces:
JobScheduler
public class InMemoryJobScheduler extends Object implements JobScheduler
Implements an in-memory JobScheduler instance.
-
-
Constructor Summary
Constructors Constructor Description InMemoryJobScheduler(String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(JobListener listener)Add a Job listener which will receive events related to scheduled jobs.List<Job>getAllJobs()Get all the outstanding JobsList<Job>getAllJobs(long start, long finish)Get all outstanding jobs due to run between start and finishStringgetName()List<Job>getNextScheduleJobs()Get all the jobs scheduled to run nextlonggetNextScheduleTime()Get the next time jobs will be firedinthashCode()booleanisDispatchEnabled()booleanisStarted()voidremove(long time)remove all jobs scheduled to run at this timevoidremove(String jobId)remove a job with the matching jobIdvoidremoveAllJobs()remove all the Jobs from the schedulervoidremoveAllJobs(long start, long finish)remove all the Jobs from the scheduler that are due between the start and finish timesvoidremoveListener(JobListener listener)remove a JobListener that was previously registered.voidschedule(String jobId, org.apache.activemq.util.ByteSequence payload, long delay)Add a job to be scheduledvoidschedule(String jobId, org.apache.activemq.util.ByteSequence payload, String cronEntry)Add a job to be scheduledvoidschedule(String jobId, org.apache.activemq.util.ByteSequence payload, String cronEntry, long delay, long period, int repeat)Add a job to be scheduledvoidstart()voidstartDispatching()Starts dispatch of scheduled Jobs to registered listeners.voidstop()voidstopDispatching()Stops dispatching of scheduled Jobs to registered listeners.StringtoString()
-
-
-
Constructor Detail
-
InMemoryJobScheduler
public InMemoryJobScheduler(String name)
-
-
Method Detail
-
getName
public String getName() throws Exception
- Specified by:
getNamein interfaceJobScheduler- Returns:
- the name of the scheduler
- Throws:
Exception
-
isStarted
public boolean isStarted()
-
isDispatchEnabled
public boolean isDispatchEnabled()
-
startDispatching
public void startDispatching() throws ExceptionDescription copied from interface:JobSchedulerStarts dispatch of scheduled Jobs to registered listeners. Any listener added after the start dispatch method can miss jobs so its important to register critical listeners before the start of job dispatching.- Specified by:
startDispatchingin interfaceJobScheduler- Throws:
Exception
-
stopDispatching
public void stopDispatching() throws ExceptionDescription copied from interface:JobSchedulerStops dispatching of scheduled Jobs to registered listeners.- Specified by:
stopDispatchingin interfaceJobScheduler- Throws:
Exception
-
addListener
public void addListener(JobListener listener) throws Exception
Description copied from interface:JobSchedulerAdd a Job listener which will receive events related to scheduled jobs.- Specified by:
addListenerin interfaceJobScheduler- Parameters:
listener- The job listener to add.- Throws:
Exception
-
removeListener
public void removeListener(JobListener listener) throws Exception
Description copied from interface:JobSchedulerremove a JobListener that was previously registered. If the given listener is not in the registry this method has no effect.- Specified by:
removeListenerin interfaceJobScheduler- Parameters:
listener- The listener that should be removed from the listener registry.- Throws:
Exception
-
schedule
public void schedule(String jobId, org.apache.activemq.util.ByteSequence payload, long delay) throws Exception
Description copied from interface:JobSchedulerAdd a job to be scheduled- Specified by:
schedulein interfaceJobScheduler- Parameters:
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 run- Throws:
Exception- if an error occurs while scheduling the Job.
-
schedule
public void schedule(String jobId, org.apache.activemq.util.ByteSequence payload, String cronEntry) throws Exception
Description copied from interface:JobSchedulerAdd a job to be scheduled- Specified by:
schedulein interfaceJobScheduler- Parameters:
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.- Throws:
Exception- if an error occurs while scheduling the Job.
-
schedule
public void schedule(String jobId, org.apache.activemq.util.ByteSequence payload, String cronEntry, long delay, long period, int repeat) throws Exception
Description copied from interface:JobSchedulerAdd a job to be scheduled- Specified by:
schedulein interfaceJobScheduler- Parameters:
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 forever- Throws:
Exception
-
remove
public void remove(long time) throws ExceptionDescription copied from interface:JobSchedulerremove all jobs scheduled to run at this time- Specified by:
removein interfaceJobScheduler- Parameters:
time- The UTC time to use to remove a batch of scheduled Jobs.- Throws:
Exception
-
remove
public void remove(String jobId) throws Exception
Description copied from interface:JobSchedulerremove a job with the matching jobId- Specified by:
removein interfaceJobScheduler- Parameters:
jobId- The unique Job Id to search for and remove from the scheduled set of jobs.- Throws:
Exception- if an error occurs while removing the Job.
-
removeAllJobs
public void removeAllJobs() throws ExceptionDescription copied from interface:JobSchedulerremove all the Jobs from the scheduler- Specified by:
removeAllJobsin interfaceJobScheduler- Throws:
Exception
-
removeAllJobs
public void removeAllJobs(long start, long finish) throws ExceptionDescription copied from interface:JobSchedulerremove all the Jobs from the scheduler that are due between the start and finish times- Specified by:
removeAllJobsin interfaceJobScheduler- Parameters:
start- time in millisecondsfinish- time in milliseconds- Throws:
Exception
-
getNextScheduleTime
public long getNextScheduleTime() throws ExceptionDescription copied from interface:JobSchedulerGet the next time jobs will be fired- Specified by:
getNextScheduleTimein interfaceJobScheduler- Returns:
- the time in milliseconds
- Throws:
Exception
-
getNextScheduleJobs
public List<Job> getNextScheduleJobs() throws Exception
Description copied from interface:JobSchedulerGet all the jobs scheduled to run next- Specified by:
getNextScheduleJobsin interfaceJobScheduler- Returns:
- a list of jobs that will be scheduled next
- Throws:
Exception
-
getAllJobs
public List<Job> getAllJobs() throws Exception
Description copied from interface:JobSchedulerGet all the outstanding Jobs- Specified by:
getAllJobsin interfaceJobScheduler- Returns:
- a list of all jobs
- Throws:
Exception
-
getAllJobs
public List<Job> getAllJobs(long start, long finish) throws Exception
Description copied from interface:JobSchedulerGet all outstanding jobs due to run between start and finish- Specified by:
getAllJobsin interfaceJobScheduler- Returns:
- a list of jobs
- Throws:
Exception
-
-