Java Code Examples for org.quartz.Scheduler#getJobKeys()
The following examples show how to use
org.quartz.Scheduler#getJobKeys() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobTrigger.java From spring-cloud-shop with MIT License | 6 votes |
/** * 获取所有job任务 */ public static List<JobInfo> getJobs(Scheduler scheduler) throws SchedulerException { GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup(); List<JobInfo> jobs = Lists.newArrayList(); Set<JobKey> jobKeys = scheduler.getJobKeys(matcher); for (JobKey jobKey : jobKeys) { List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey); for (Trigger trigger : triggers) { JobInfo event = new JobInfo(); event.setJobName(jobKey.getName()); event.setJobGroup(jobKey.getGroup()); event.setDescription(String.format("触发器 ======== %s", trigger.getKey())); Trigger.TriggerState state = scheduler.getTriggerState(trigger.getKey()); event.setJobStatus(EnumUtils.getEnum(JobStatusEnums.class, state.name()).getCode()); if (trigger instanceof CronTrigger) { CronTrigger cronTrigger = (CronTrigger) trigger; event.setCron(cronTrigger.getCronExpression()); jobs.add(event); } } } return jobs; }
Example 2
Source File: QuartzJobHandler.java From nextreports-server with Apache License 2.0 | 6 votes |
public static void listJobs(Scheduler scheduler) throws SchedulerException { if (!LOG.isDebugEnabled()) { return; } List<String> jobGroups = scheduler.getJobGroupNames(); if (jobGroups.isEmpty()) { LOG.debug("No jobs !!!"); } for (String jobGroup : jobGroups) { LOG.debug("Group '{}' contains the following jobs:", jobGroup); Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup)); for (JobKey jobKey : jobKeys) { LOG.debug("- {}", jobKey.getName()); } } }
Example 3
Source File: Quartz2Adapter.java From javamelody with Apache License 2.0 | 6 votes |
@Override List<JobDetail> getAllJobsOfScheduler(Scheduler scheduler) throws SchedulerException { final List<JobDetail> result = new ArrayList<JobDetail>(); for (final String jobGroupName : scheduler.getJobGroupNames()) { final GroupMatcher<JobKey> groupMatcher = GroupMatcher.groupEquals(jobGroupName); for (final JobKey jobKey : scheduler.getJobKeys(groupMatcher)) { final JobDetail jobDetail; try { jobDetail = scheduler.getJobDetail(jobKey); // le job peut être terminé et supprimé depuis la ligne ci-dessus if (jobDetail != null) { result.add(jobDetail); } } catch (final Exception e) { // si les jobs sont persistés en base de données, il peut y avoir une exception // dans getJobDetail, par exemple si la classe du job n'existe plus dans l'application LOG.debug(e.toString(), e); } } } return result; }
Example 4
Source File: SiteScheduledJobsController.java From engine with GNU General Public License v3.0 | 6 votes |
@GetMapping(URL_LIST) @SuppressWarnings("unchecked") public List<Map<String, String>> listScheduledJobs() throws SchedulerException { List<Map<String, String>> jobs = new LinkedList<>(); SiteContext siteContext = SiteContext.getCurrent(); Scheduler scheduler = siteContext.getScheduler(); if(scheduler != null) { List<String> groups = scheduler.getJobGroupNames(); for (String group : groups) { Set<JobKey> keys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group)); for (JobKey key : keys) { List<Trigger> triggers = (List<Trigger>)scheduler.getTriggersOfJob(key); Map<String, String> job = new HashMap<>(); job.put("name", key.getName()); job.put("nextFireTime", triggers.get(0).getNextFireTime().toInstant().toString()); jobs.add(job); } } } return jobs; }
Example 5
Source File: QuartzQueueAction.java From rice with Educational Community License v2.0 | 6 votes |
@Override public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception { if ("moveToRouteQueue".equals(request.getParameter("methodToCall")) && request.getAttribute(RENDER_LIST_OVERRIDE) == null) { return null; } Scheduler scheduler = KSBServiceLocator.getScheduler(); List<QuartzQueueForm> jobs = new ArrayList<QuartzQueueForm>(); List<String> jobGroups = KSBServiceLocator.getScheduler().getJobGroupNames(); for (int i = 0; i < jobGroups.size(); i++) { String jobGroup = KSBServiceLocator.getScheduler().getJobGroupNames().get(i); for(JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup))) { Trigger trigger = scheduler.getTriggersOfJob(jobKey).get(0); JobDetail jobDetail = scheduler.getJobDetail(jobKey); jobs.add(new QuartzQueueForm(jobDetail, trigger) ); } } request.setAttribute("jobs", jobs); return null; }
Example 6
Source File: ShowScheduler.java From iaf with Apache License 2.0 | 6 votes |
private Map<String,Object> getJobGroupNamesWithJobs(Scheduler scheduler) throws ApiException { Map<String, Object> jobGroups = new HashMap<String, Object>(); try { List<String> jobGroupNames = scheduler.getJobGroupNames(); for(String jobGroupName : jobGroupNames) { Map<String, Object> jobsInGroup = new HashMap<String, Object>(); Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroupName)); for (JobKey jobKey : jobKeys) { jobsInGroup.put(jobKey.getName(), getJobData(jobKey, false)); } jobGroups.put(jobGroupName, jobsInGroup); } } catch (Exception e) { log.error("error retrieving job from jobgroup", e); } return jobGroups; }
Example 7
Source File: ScheduleServiceImpl.java From fixflow with Apache License 2.0 | 6 votes |
public List<JobDetail> getJobList(String queryId){ if(!getIsEnabled()){ throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE); } Scheduler scheduler = getScheduler(); List<JobDetail> jobList = new ArrayList<JobDetail>(); Set<JobKey> set = new HashSet<JobKey>(); try { //如果queryId不为空,则返回queryId对应的job,否则返回所有job if(StringUtil.isNotEmpty(queryId)){ set = scheduler.getJobKeys(GroupMatcher.jobGroupContains(queryId)); }else{ List<String> groupNames = scheduler.getJobGroupNames(); for(String groupName:groupNames){ set.addAll(scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))); } } for(JobKey key :set){ JobDetail job = scheduler.getJobDetail(key); jobList.add(job); } }catch (SchedulerException e) { throw new FixFlowException(e.getMessage(),e); } return jobList; }
Example 8
Source File: QuartzUtil.java From nextreports-server with Apache License 2.0 | 5 votes |
public static List<JobDetail> getAllJobDetails(Scheduler scheduler) throws SchedulerException { List<JobDetail> jobDetails = new ArrayList<JobDetail>(); List<String> groupNames = scheduler.getJobGroupNames(); for (String jobGroup : groupNames) { Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup)); for (JobKey jobKey : jobKeys) { jobDetails.add(scheduler.getJobDetail(jobKey)); } } return jobDetails; }
Example 9
Source File: PlugwiseBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private boolean isExistingJob(Scheduler scheduler, String jobName) { try { for (String group : scheduler.getJobGroupNames()) { for (JobKey jobKey : scheduler.getJobKeys(jobGroupEquals(group))) { if (jobKey.getName().equals(jobName)) { return true; } } } } catch (SchedulerException e1) { logger.error("An exception occurred while querying the Quartz Scheduler ({})", e1.getMessage()); } return false; }
Example 10
Source File: MpdBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Delete all quartz scheduler jobs of the group <code>MPD</code>. */ private void cancelScheduler() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); Set<JobKey> jobKeys = sched.getJobKeys(jobGroupEquals(MPD_SCHEDULER_GROUP)); if (jobKeys.size() > 0) { sched.deleteJobs(new ArrayList<JobKey>(jobKeys)); logger.debug("Found {} jobs to delete from the DefaultScheduler (keys={})", jobKeys.size(), jobKeys); } } catch (SchedulerException e) { logger.warn("Couldn't remove job(s): {}", e.getMessage()); } }
Example 11
Source File: MapDBPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Delete all quartz scheduler jobs of the group <code>Dropbox</code>. */ private void cancelAllJobs() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); Set<JobKey> jobKeys = sched.getJobKeys(jobGroupEquals(SCHEDULER_GROUP)); if (jobKeys.size() > 0) { sched.deleteJobs(new ArrayList<JobKey>(jobKeys)); logger.debug("Found {} MapDB-Jobs to delete from DefaultScheduler (keys={})", jobKeys.size(), jobKeys); } } catch (SchedulerException e) { logger.warn("Couldn't remove Commit-Job: {}", e.getMessage()); } }
Example 12
Source File: Db4oPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Delete all quartz scheduler jobs of the group <code>Dropbox</code>. */ private void cancelAllJobs() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); Set<JobKey> jobKeys = sched.getJobKeys(jobGroupEquals(SCHEDULER_GROUP)); if (jobKeys.size() > 0) { sched.deleteJobs(new ArrayList<JobKey>(jobKeys)); logger.debug("Found {} DB4O-Jobs to delete from DefaultScheduler (keys={})", jobKeys.size(), jobKeys); } } catch (SchedulerException e) { logger.warn("Couldn't remove Commit-Job: {}", e.getMessage()); } }
Example 13
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 5 votes |
/** * 获取scheduler下所有的jobDetail * @param scheduler * @return * @throws SchedulerException */ public static List<JobDetail> getAllJobsOfScheduler(Scheduler scheduler) throws SchedulerException { List<JobDetail> result = new ArrayList<JobDetail>(); List<String> jobGroupNames = scheduler.getJobGroupNames(); for (String groupName : jobGroupNames) { Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.<JobKey>groupEquals(groupName)); for (JobKey jobKey : jobKeys) { JobDetail jobDetail = scheduler.getJobDetail(jobKey); result.add(jobDetail); } } return result; }
Example 14
Source File: SchedulerAdapter.java From iaf with Apache License 2.0 | 4 votes |
/** * Get all jobgroups, jobs within this group, the jobdetail and the * associated triggers in XML format. */ public XmlBuilder getJobGroupNamesWithJobsToXml(Scheduler theScheduler, IbisManager ibisManager) { XmlBuilder xbRoot = new XmlBuilder("jobGroups"); try { // process groups List<String> jgnames = theScheduler.getJobGroupNames(); for (int i = 0; i < jgnames.size(); i++) { XmlBuilder el = new XmlBuilder("jobGroup"); String jobGroupName = jgnames.get(i); el.addAttribute("name", jobGroupName); // process jobs within group XmlBuilder jb = new XmlBuilder("jobs"); Set<JobKey> jobKeys = theScheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroupName)); for (JobKey jobKey : jobKeys) { XmlBuilder jn = new XmlBuilder("job"); String jobName = jobKey.getName(); jn.addAttribute("name", jobName); // details for job JobDetail jobDetail = theScheduler.getJobDetail(jobKey); XmlBuilder jd = jobDetailToXmlBuilder(jobDetail); jn.addSubElement(jd); // get the triggers for this job List<? extends Trigger> triggers = theScheduler.getTriggersOfJob(jobKey); XmlBuilder tr = getJobTriggers(triggers); jn.addSubElement(tr); JobDataMap jobDataMap = jobDetail.getJobDataMap(); XmlBuilder datamap = jobDataMapToXmlBuilder(jobDataMap); jn.addSubElement(datamap); jb.addSubElement(jn); JobDef jobDef = null; if(ibisManager != null) { for (Configuration configuration : ibisManager.getConfigurations()) { jobDef = configuration.getScheduledJob(jobName); if (jobDef != null) { break; } } } XmlBuilder ms = getJobMessages(jobDef); jn.addSubElement(ms); XmlBuilder jrs= getJobRunStatistics(jobDef); jn.addSubElement(jrs); } el.addSubElement(jb); xbRoot.addSubElement(el); } } catch (SchedulerException se) { log.error(se); } return xbRoot; }
Example 15
Source File: SchedulerTool.java From sakai with Educational Community License v2.0 | 4 votes |
public String processRefreshJobs() { try { Scheduler scheduler = schedulerManager.getScheduler(); Set<JobKey> jobs = scheduler.getJobKeys(GroupMatcher.groupEquals(Scheduler.DEFAULT_GROUP)); jobDetailWrapperList = new ArrayList<JobDetailWrapper>(); for (JobKey key : jobs) { JobDetailWrapper jobDetailWrapper = new JobDetailWrapperImpl(); jobDetailWrapper.setJobDetail(scheduler.getJobDetail(key)); List<? extends Trigger> triggers = scheduler.getTriggersOfJob(key); List<TriggerWrapper> triggerWrapperList = new ArrayList<TriggerWrapper>(); for (Trigger trigger : triggers) { TriggerWrapper tw = new TriggerWrapperImpl(); tw.setTrigger(trigger); triggerWrapperList.add(tw); } jobDetailWrapper.setTriggerWrapperList(triggerWrapperList); jobDetailWrapperList.add(jobDetailWrapper); } } catch (SchedulerException e) { log.error("Failed to get job details.", e); } // test for select all if (isSelectAllJobsSelected) { for (Iterator<JobDetailWrapper> i = jobDetailWrapperList.iterator(); i.hasNext();) { if (isSelectAllJobsSelected) { ((JobDetailWrapper) i.next()).setIsSelected(true); } else { ((JobDetailWrapper) i.next()).setIsSelected(false); } } } return "jobs"; }
Example 16
Source File: SchedulerTool.java From sakai with Educational Community License v2.0 | 4 votes |
public String processRefreshJobs() { try { Scheduler scheduler = schedulerManager.getScheduler(); Set<JobKey> jobs = scheduler.getJobKeys(GroupMatcher.groupEquals(Scheduler.DEFAULT_GROUP)); jobDetailWrapperList = new ArrayList<JobDetailWrapper>(); for (JobKey key : jobs) { JobDetailWrapper jobDetailWrapper = new JobDetailWrapperImpl(); jobDetailWrapper.setJobDetail(scheduler.getJobDetail(key)); List<? extends Trigger> triggers = scheduler.getTriggersOfJob(key); List<TriggerWrapper> triggerWrapperList = new ArrayList<TriggerWrapper>(); for (Trigger trigger : triggers) { TriggerWrapper tw = new TriggerWrapperImpl(); tw.setTrigger(trigger); triggerWrapperList.add(tw); } jobDetailWrapper.setTriggerWrapperList(triggerWrapperList); jobDetailWrapperList.add(jobDetailWrapper); } } catch (SchedulerException e) { log.error("Failed to get job details.", e); } // test for select all if (isSelectAllJobsSelected) { for (Iterator<JobDetailWrapper> i = jobDetailWrapperList.iterator(); i.hasNext();) { if (isSelectAllJobsSelected) { ((JobDetailWrapper) i.next()).setIsSelected(true); } else { ((JobDetailWrapper) i.next()).setIsSelected(false); } } } return "jobs"; }
Example 17
Source File: JobServiceImpl.java From spring-boot-quartz-demo with MIT License | 4 votes |
/** * 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; }