Package com.avoka.fc.core.service
Class SchedulerService
- java.lang.Object
-
- com.avoka.fc.core.service.BaseService
-
- com.avoka.fc.core.service.SchedulerService
-
public class SchedulerService extends BaseService
Provides a schedule service.This service provides schedule jobs handling with the quartz library.
-
-
Field Summary
Fields Modifier and Type Field Description static String
FC_GROUP_NAME
The group name for TM jobs
-
Constructor Summary
Constructors Constructor Description SchedulerService(org.quartz.Scheduler scheduler)
Create a scheduler service given a scheduler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adjustTriggerTimezones()
Go through the existing TM cron triggers and adjust their timezone.boolean
deleteJob(String jobName)
Delete the job for the given name, return true if the job was found.static SchedulerService
getInstance()
Return the singleton instance of the scheduler service.JobAndTrigger
getJobAndTrigger(String jobName)
Return the Job and Trigger for the given job nameJobAndTrigger
getJobAndTrigger(String jobName, String groupName)
Return the Job and Trigger for the given job nameList<JobAndTrigger>
getJobAndTriggerList()
Return the list of JobDetail and Trigger associations.org.quartz.JobDetail
getJobDetail(String jobName)
Return the JobDetail for the given name.org.quartz.JobDetail
getJobDetail(String jobName, String groupName)
Return the JobDetail for the given name.List<org.quartz.JobDetail>
getJobDetailList()
Return the list of scheduled JobDetails for the group name: "fc-group".org.quartz.Scheduler
getScheduler()
Return the scheduler instance.boolean
hasJob(String jobName)
Return true if the scheduler has the named job.boolean
hasJob(String jobName, String groupName)
Return true if the scheduler has the named job.boolean
interruptJob(String jobName)
Interrupt the job for the given name, return true if the job was found.boolean
isJobExecuting(String jobName)
Return true if any job with the specified job name is currently executing.boolean
isPaused()
Return true if the scheduler is paused.void
pauseAll()
Pause all the scheduled jobs, and interrupt any currently executing jobs.void
pauseJob(String jobName)
Pause the job for the given name.void
resumeAll()
Resume all paused jobs.void
resumeJob(String jobName)
Resume the job for the given name.Date
scheduleCronJob(org.quartz.JobDetail jobDetail, Date startDate, Date endDate, String cronExpression)
Perform a schedule cron jobDate
scheduleSimpleJob(org.quartz.JobDetail jobDetail, Date startDate, Date endDate, int repeatCount, long repeatInterval)
Schedule a simple jobvoid
setScheduler(org.quartz.Scheduler scheduler)
Sets the scheduler.void
triggerJob(String jobName)
Trigger the job for the given name.void
triggerJob(String jobName, String groupName)
Trigger the job for the given name.-
Methods inherited from class com.avoka.fc.core.service.BaseService
getLogger
-
-
-
-
Field Detail
-
FC_GROUP_NAME
public static final String FC_GROUP_NAME
The group name for TM jobs- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static SchedulerService getInstance()
Return the singleton instance of the scheduler service.- Returns:
- the singleton instance of the scheduler service
-
getScheduler
public org.quartz.Scheduler getScheduler()
Return the scheduler instance.- Returns:
- the scheduler instance
-
setScheduler
public void setScheduler(org.quartz.Scheduler scheduler)
Sets the scheduler.- Parameters:
scheduler
- the new scheduler
-
scheduleSimpleJob
public Date scheduleSimpleJob(org.quartz.JobDetail jobDetail, Date startDate, Date endDate, int repeatCount, long repeatInterval)
Schedule a simple job- Parameters:
jobDetail
- job detailsstartDate
- start date of the jobendDate
- end date of the jobrepeatCount
- the repeat countrepeatInterval
- the repeat interval- Returns:
- the schedule date
-
scheduleCronJob
public Date scheduleCronJob(org.quartz.JobDetail jobDetail, Date startDate, Date endDate, String cronExpression)
Perform a schedule cron job- Parameters:
jobDetail
- job detailsstartDate
- start date of the jobendDate
- end date of the jobcronExpression
- the cron expression for this cron job- Returns:
- the schedule date
-
isPaused
public boolean isPaused()
Return true if the scheduler is paused.- Returns:
- true if the scheduler is paused
-
isJobExecuting
public boolean isJobExecuting(String jobName)
Return true if any job with the specified job name is currently executing.- Parameters:
jobName
- the name of the job- Returns:
- true if any job with the specified job name is currently executing
- Since:
- 4.1.0
-
pauseAll
public void pauseAll()
Pause all the scheduled jobs, and interrupt any currently executing jobs.
-
resumeAll
public void resumeAll()
Resume all paused jobs.
-
pauseJob
public void pauseJob(String jobName)
Pause the job for the given name.- Parameters:
jobName
- the name of the job to pause
-
resumeJob
public void resumeJob(String jobName)
Resume the job for the given name.- Parameters:
jobName
- the name of the job to resume
-
triggerJob
public void triggerJob(String jobName)
Trigger the job for the given name.- Parameters:
jobName
- the name of the job to trigger
-
triggerJob
public void triggerJob(String jobName, String groupName)
Trigger the job for the given name.- Parameters:
jobName
- the name of the job to triggergroupName
- the name of the group the job belongs to- Since:
- 4.2.0
-
interruptJob
public boolean interruptJob(String jobName)
Interrupt the job for the given name, return true if the job was found.- Parameters:
jobName
- the name of the job to interrupt- Returns:
- true if the job was found and interrupted.
-
deleteJob
public boolean deleteJob(String jobName)
Delete the job for the given name, return true if the job was found.- Parameters:
jobName
- the name of the job to delete- Returns:
- true if the Job was found and deleted.
-
getJobDetailList
public List<org.quartz.JobDetail> getJobDetailList()
Return the list of scheduled JobDetails for the group name: "fc-group".- Returns:
- the list of scheduled JobDetails for the group name: "fc-group"
- See Also:
JobDetail
-
getJobDetail
public org.quartz.JobDetail getJobDetail(String jobName)
Return the JobDetail for the given name.- Parameters:
jobName
- the job name- Returns:
- the JobDetail for the given name
-
getJobDetail
public org.quartz.JobDetail getJobDetail(String jobName, String groupName)
Return the JobDetail for the given name.- Parameters:
jobName
- the job namegroupName
- the group name- Returns:
- the JobDetail for the given name and group
- Since:
- 4.2.0
-
hasJob
public boolean hasJob(String jobName)
Return true if the scheduler has the named job.- Parameters:
jobName
- the name of the job- Returns:
- true if the scheduler has the named job
-
hasJob
public boolean hasJob(String jobName, String groupName)
Return true if the scheduler has the named job.- Parameters:
jobName
- the name of the jobgroupName
- the name of the job group- Returns:
- true if the scheduler has the named job
-
getJobAndTriggerList
public List<JobAndTrigger> getJobAndTriggerList()
Return the list of JobDetail and Trigger associations.- Returns:
- the list of JobDetail and Trigger associations
-
getJobAndTrigger
public JobAndTrigger getJobAndTrigger(String jobName)
Return the Job and Trigger for the given job name- Parameters:
jobName
- the name of the job- Returns:
- the Job and Trigger for the given job name
-
getJobAndTrigger
public JobAndTrigger getJobAndTrigger(String jobName, String groupName)
Return the Job and Trigger for the given job name- Parameters:
jobName
- the name of the job (required)groupName
- the group the job belongs to (required)- Returns:
- the Job and Trigger for the given job name
- Since:
- 4.2.0
-
adjustTriggerTimezones
public void adjustTriggerTimezones()
Go through the existing TM cron triggers and adjust their timezone. This is needed if the system timezone has changed to avoid existing jobs being scheduled at inappropriate times.- Since:
- 4.2.0
-
-