本文整理汇总了Java中org.quartz.Scheduler.getTriggersOfJob方法的典型用法代码示例。如果您正苦于以下问题:Java Scheduler.getTriggersOfJob方法的具体用法?Java Scheduler.getTriggersOfJob怎么用?Java Scheduler.getTriggersOfJob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.Scheduler
的用法示例。
在下文中一共展示了Scheduler.getTriggersOfJob方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllJob
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* 获取所有计划中的任务列表
*
* @return
* @throws SchedulerException
*/
public List<ScheduleJob> getAllJob() throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup();
Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
List<ScheduleJob> jobList = new ArrayList<ScheduleJob>();
for (JobKey jobKey : jobKeys) {
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
for (Trigger trigger : triggers) {
ScheduleJob job = new ScheduleJob();
job.setName(jobKey.getName());
job.setGroup(jobKey.getGroup());
job.setDescription("触发器:" + trigger.getKey());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
job.setStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger) trigger;
String cronExpression = cronTrigger.getCronExpression();
job.setCron(cronExpression);
}
jobList.add(job);
}
}
return jobList;
}
示例2: getTriggers
import org.quartz.Scheduler; //导入方法依赖的package包/类
@Override
public List<ScheduleJobEntity> getTriggers(ScheduleJobEntity job){
List<ScheduleJobEntity> scheduleJobList = new ArrayList<ScheduleJobEntity>();
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
JobKey jobKey = JobKey.jobKey(job.getJobName(), job.getJobGroup());
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
for (Trigger jobTrigger : triggers) {
ScheduleJobEntity scheduleJob = new ScheduleJobEntity();
this.wrapScheduleJob(scheduleJob, scheduler, jobKey, jobTrigger);
scheduleJobList.add(scheduleJob);
}
} catch (SchedulerException e) {
logger.error("jobName: "+job.getJobName()+" jobGroup: "+job.getJobGroup()+" 获取trigger异常:",e);
throw new ServiceException("获取job失败", e);
}
return scheduleJobList;
}
示例3: getJobState
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* Get the current state of job
*/
public String getJobState(String jobName) {
System.out.println("JobServiceImpl.getJobState()");
try {
String groupKey = "SampleGroup";
JobKey jobKey = new JobKey(jobName, groupKey);
Scheduler scheduler = schedulerFactoryBean.getScheduler();
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobDetail.getKey());
if(triggers != null && triggers.size() > 0){
for (Trigger trigger : triggers) {
TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
if (TriggerState.PAUSED.equals(triggerState)) {
return "PAUSED";
}else if (TriggerState.BLOCKED.equals(triggerState)) {
return "BLOCKED";
}else if (TriggerState.COMPLETE.equals(triggerState)) {
return "COMPLETE";
}else if (TriggerState.ERROR.equals(triggerState)) {
return "ERROR";
}else if (TriggerState.NONE.equals(triggerState)) {
return "NONE";
}else if (TriggerState.NORMAL.equals(triggerState)) {
return "SCHEDULED";
}
}
}
} catch (SchedulerException e) {
System.out.println("SchedulerException while checking job with name and group exist:"+e.getMessage());
e.printStackTrace();
}
return null;
}
示例4: execute
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* Get all waitting queue jobs scheduled in Quartz table and display job name, job start time and description. The
* description will be in format "Lesson Name":"the lesson creator", or "The gate name":"The relatived lesson name".
*
* @param mapping
* The ActionMapping used to select this instance
* @param actionForm
* The optional ActionForm bean for this request (if any)
* @param request
* The HTTP request we are processing
* @param response
* The HTTP response we are creating
*
* @exception IOException
* if an input/output error occurs
* @exception ServletException
* if a servlet exception occurs
*
*/
@SuppressWarnings("unchecked")
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
WebApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(this.getServlet().getServletContext());
Scheduler scheduler = (Scheduler) ctx.getBean("scheduler");
ArrayList<ScheduledJobDTO> jobList = new ArrayList<ScheduledJobDTO>();
try {
Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(Scheduler.DEFAULT_GROUP));
for (JobKey jobKey : jobKeys) {
ScheduledJobDTO jobDto = new ScheduledJobDTO();
JobDetail detail = scheduler.getJobDetail(jobKey);
jobDto.setName(jobKey.getName());
jobDto.setDescription(detail.getDescription());
List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
for (Trigger trigger : triggers) {
jobDto.setStartDate(trigger.getStartTime());
jobList.add(jobDto);
}
}
} catch (SchedulerException e) {
ScheduledJobListAction.log.equals("Failed get job names:" + e.getMessage());
}
request.setAttribute("jobList", jobList);
return mapping.findForward("list");
}
示例5: jobs
import org.quartz.Scheduler; //导入方法依赖的package包/类
@Override
public Collection<JobDetailInfo> jobs() throws SchedulerException {
List<JobDetailInfo> jobDetailInfoes = new ArrayList<>();
Scheduler scheduler = schedulerFactoryBean.getScheduler();
GroupMatcher<JobKey> jobMatcher = GroupMatcher.anyJobGroup();
Set<JobKey> jobKeys = scheduler.getJobKeys(jobMatcher);
for (JobKey jobKey : jobKeys) {
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
for (Trigger trigger : triggers) {
JobDetailInfo jobDetailInfo = new JobDetailInfo();
jobDetailInfo.setJobName(jobKey.getName());
jobDetailInfo.setJobGroupName(jobKey.getGroup());
jobDetailInfo.setJobDescription(jobDetail.getDescription());
jobDetailInfo.setJobClassName(jobDetail.getJobClass().getName());
jobDetailInfo.setTriggerName(trigger.getKey().getName());
jobDetailInfo.setTriggerGroupName(trigger.getKey().getGroup());
jobDetailInfo.setTriggerDescription(trigger.getDescription());
CronTrigger cronTrigger = (CronTrigger) trigger;
jobDetailInfo.setTriggerCronExpression(cronTrigger.getCronExpression());
jobDetailInfo.setStartTime(new DateTime(trigger.getStartTime()).toString("yyyy-MM-dd HH:mm:ss"));
jobDetailInfo.setEndTime(new DateTime(trigger.getEndTime()).toString("yyyy-MM-dd HH:mm:ss"));
jobDetailInfo
.setFinalFireTime(new DateTime(trigger.getFinalFireTime()).toString("yyyy-MM-dd HH:mm:ss"));
jobDetailInfo.setPreviousFireTime(
new DateTime(trigger.getPreviousFireTime()).toString("yyyy-MM-dd HH:mm:ss"));
jobDetailInfo.setNextFireTime(new DateTime(trigger.getNextFireTime()).toString("yyyy-MM-dd HH:mm:ss"));
jobDetailInfo.setMisfireInstruction(trigger.getMisfireInstruction());
TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
jobDetailInfo.setJobState(triggerState.name());
jobDetailInfoes.add(jobDetailInfo);
}
}
return jobDetailInfoes;
}
示例6: getTriggersOfJob
import org.quartz.Scheduler; //导入方法依赖的package包/类
public static List<? extends Trigger> getTriggersOfJob(String jobName,String jobGroup, Scheduler scheduler) throws SchedulerException {
JobKey jobKey = getJobKey(jobName, jobGroup);
return scheduler.getTriggersOfJob(jobKey);
}
示例7: getAllJobs
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* Get all jobs
*/
@Override
public List<Map<String, Object>> getAllJobs() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
for (String groupName : scheduler.getJobGroupNames()) {
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
String jobName = jobKey.getName();
String jobGroup = jobKey.getGroup();
//get job's trigger
List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
Date scheduleTime = triggers.get(0).getStartTime();
Date nextFireTime = triggers.get(0).getNextFireTime();
Date lastFiredTime = triggers.get(0).getPreviousFireTime();
Map<String, Object> map = new HashMap<String, Object>();
map.put("jobName", jobName);
map.put("groupName", jobGroup);
map.put("scheduleTime", scheduleTime);
map.put("lastFiredTime", lastFiredTime);
map.put("nextFireTime", nextFireTime);
if(isJobRunning(jobName)){
map.put("jobStatus", "RUNNING");
}else{
String jobState = getJobState(jobName);
map.put("jobStatus", jobState);
}
/* Date currentDate = new Date();
if (scheduleTime.compareTo(currentDate) > 0) {
map.put("jobStatus", "scheduled");
} else if (scheduleTime.compareTo(currentDate) < 0) {
map.put("jobStatus", "Running");
} else if (scheduleTime.compareTo(currentDate) == 0) {
map.put("jobStatus", "Running");
}*/
list.add(map);
System.out.println("Job details:");
System.out.println("Job Name:"+jobName + ", Group Name:"+ groupName + ", Schedule Time:"+scheduleTime);
}
}
} catch (SchedulerException e) {
System.out.println("SchedulerException while fetching all jobs. error message :"+e.getMessage());
e.printStackTrace();
}
return list;
}