/** * 获取所有计划中的任务列表 * * @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; }
/** * <p> * Resume (un-pause) all of the <code>{@link Trigger}s</code> in the given group. * </p> * <p> * If any <code>Trigger</code> missed one or more fire-times, then the <code>Trigger</code>'s misfire instruction will * be applied. * </p> */ @Override public Collection<String> resumeTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { Collection<String> groups = new HashSet<String>(); lock(); try { Set<TriggerKey> triggerKeys = getTriggerKeys(matcher); for (TriggerKey triggerKey : triggerKeys) { TriggerWrapper tw = triggerFacade.get(triggerKey); if (tw != null) { String jobGroup = tw.getJobKey().getGroup(); if (jobFacade.pausedGroupsContain(jobGroup)) { continue; } groups.add(triggerKey.getGroup()); } resumeTrigger(triggerKey); } triggerFacade.removeAllPausedGroups(groups); } finally { unlock(); } return groups; }
/** * <p> * Resume (un-pause) all triggers - equivalent of calling <code>resumeTriggerGroup(group)</code> on every group. * </p> * <p> * If any <code>Trigger</code> missed one or more fire-times, then the <code>Trigger</code>'s misfire instruction will * be applied. * </p> * * @see #pauseAll() */ @Override public void resumeAll() throws JobPersistenceException { lock(); try { jobFacade.clearPausedJobGroups(); List<String> names = getTriggerGroupNames(); for (String name : names) { resumeTriggers(GroupMatcher.triggerGroupEquals(name)); } } finally { unlock(); } }
@Override @SuppressWarnings("unchecked") public Set<String> getScheduledJobIds() throws KairosDBException { Set<String> scheduledJobs = new HashSet<String>(); try { for (String groupName : scheduler.getJobGroupNames()) { for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { scheduledJobs.add(jobKey.getName()); } } } catch (SchedulerException e) { throw new KairosDBException("Could not get scheduled jobs." + e); } return scheduledJobs; }
/** * <p> * Resume (un-pause) all of the <code>{@link Trigger}s</code> in the * given group. * </p> * * <p> * If any <code>Trigger</code> missed one or more fire-times, then the * <code>Trigger</code>'s misfire instruction will be applied. * </p> * */ public List<String> resumeTriggers(GroupMatcher<TriggerKey> matcher) { Set<String> groups = new HashSet<String>(); synchronized (lock) { Set<TriggerKey> keys = getTriggerKeys(matcher); for (TriggerKey triggerKey: keys) { groups.add(triggerKey.getGroup()); if(triggersByKey.get(triggerKey) != null) { String jobGroup = triggersByKey.get(triggerKey).jobKey.getGroup(); if(pausedJobGroups.contains(jobGroup)) { continue; } } resumeTrigger(triggerKey); } for (String group : groups) { pausedTriggerGroups.remove(group); } } return new ArrayList<String>(groups); }
/** * Returns all Jobs from the Scheduler. * * @return all Jobs from the Scheduler. * @throws FrameworkException in case any internal error occurs. * @throws ApplicationExceptions Indicates application error(s). */ private List<ScheduledTask> getTaskList() throws FrameworkException, ApplicationExceptions { List<ScheduledTask> tasks = null; try { final List<String> names = scheduler.getJobGroupNames(); if (names != null && 0 < names.size()) { tasks = new LinkedList<ScheduledTask>(); for (final String groupName : names) { for (final JobKey jobKey : scheduler.getJobKeys(GroupMatcher .jobGroupEquals(groupName))) { final JobDetail jobDetail = scheduler.getJobDetail(jobKey); final List<? extends Trigger> triggers = scheduler .getTriggersOfJob(jobKey); final ScheduledTask task = jobAndTriggerToTask(jobDetail, triggers); tasks.add(task); } } } return tasks; } catch (SchedulerException e) { LOGGER.error("Error in retriving Jobs from the Scheduler", e); throw new JaffaSchedulerFrameworkException( JaffaSchedulerFrameworkException.TASK_RETRIEVE_ERROR, null, e); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public void pauseJobs(GroupMatcher<JobKey> matcher) throws SchedulerException { String operation = null; switch (matcher.getCompareWithOperator()) { case EQUALS: operation = "pauseJobGroup"; break; case STARTS_WITH: operation = "pauseJobsStartingWith"; break; case ENDS_WITH: operation = "pauseJobsEndingWith"; break; case CONTAINS: operation = "pauseJobsContaining"; case ANYTHING: operation = "pauseJobsAll"; } invoke( operation, new Object[] { matcher.getCompareToValue() }, new String[] { String.class.getName() }); }
/** * <p> * Pause all triggers - equivalent of calling <code>pauseTriggerGroup(group)</code> * on every group. * </p> * * <p> * When <code>resumeAll()</code> is called (to un-pause), trigger misfire * instructions WILL be applied. * </p> * * @see #resumeAll(Connection) * @see #pauseTriggerGroup(java.sql.Connection, org.quartz.impl.matchers.GroupMatcher) */ public void pauseAll(Connection conn) throws JobPersistenceException { List<String> names = getTriggerGroupNames(conn); for (String name: names) { pauseTriggerGroup(conn, GroupMatcher.triggerGroupEquals(name)); } try { if (!getDelegate().isTriggerGroupPaused(conn, ALL_GROUPS_PAUSED)) { getDelegate().insertPausedTriggerGroup(conn, ALL_GROUPS_PAUSED); } } catch (SQLException e) { throw new JobPersistenceException( "Couldn't pause all trigger groups: " + e.getMessage(), e); } }
/** * protected * <p> * Resume (un-pause) all triggers - equivalent of calling <code>resumeTriggerGroup(group)</code> * on every group. * </p> * * <p> * If any <code>Trigger</code> missed one or more fire-times, then the * <code>Trigger</code>'s misfire instruction will be applied. * </p> * * @see #pauseAll(Connection) */ public void resumeAll(Connection conn) throws JobPersistenceException { List<String> names = getTriggerGroupNames(conn); for (String name: names) { resumeTriggerGroup(conn, GroupMatcher.triggerGroupEquals(name)); } try { getDelegate().deletePausedTriggerGroup(conn, ALL_GROUPS_PAUSED); } catch (SQLException e) { throw new JobPersistenceException( "Couldn't resume all trigger groups: " + e.getMessage(), e); } }
/** * <p> * Update all of the triggers of the given group to the given new state, if * they are in the given old state. * </p> * * @param conn * the DB connection * @param matcher * the groupMatcher to evaluate the triggers against * @param newState * the new state for the trigger group * @param oldState * the old state the triggers must be in * @return int the number of rows updated * @throws SQLException */ public int updateTriggerGroupStateFromOtherState(Connection conn, GroupMatcher<TriggerKey> matcher, String newState, String oldState) throws SQLException { PreparedStatement ps = null; try { ps = conn .prepareStatement(rtp(UPDATE_TRIGGER_GROUP_STATE_FROM_STATE)); ps.setString(1, newState); ps.setString(2, toSqlLikeClause(matcher)); ps.setString(3, oldState); return ps.executeUpdate(); } finally { closeStatement(ps); } }
public List<String> selectTriggerGroups(Connection conn, GroupMatcher<TriggerKey> matcher) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_TRIGGER_GROUPS_FILTERED)); ps.setString(1, toSqlLikeClause(matcher)); rs = ps.executeQuery(); LinkedList<String> list = new LinkedList<String>(); while (rs.next()) { list.add(rs.getString(1)); } return list; } finally { closeResultSet(rs); closeStatement(ps); } }
public List<ScheduleJob> getAllJobList(){ List<ScheduleJob> jobList = new ArrayList<>(); try { GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup(); Set<JobKey> jobKeySet = scheduler.getJobKeys(matcher); for (JobKey jobKey : jobKeySet){ List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey); for (Trigger trigger : triggers){ ScheduleJob scheduleJob = new ScheduleJob(); this.wrapScheduleJob(scheduleJob,scheduler,jobKey,trigger); jobList.add(scheduleJob); } } } catch (SchedulerException e) { e.printStackTrace(); } return jobList; }
private List<TriggerDefinition> getTriggersForGroup(GroupMatcher<TriggerKey> groupMatcher) { try { return scheduler.getTriggerKeys(groupMatcher).stream() .map(this::getTriggerSafe) .filter(trigger -> trigger != null) .map(quartzToCronyxSelector::convert) .map(this::enhanceTriggerDefinition) .collect(Collectors.toList()); } catch (SchedulerException e) { throw new SchedulingException(e); } }
public List<String> getJobNames(String groupName) throws Exception { try { List<String> jobNames = new ArrayList<String>(); for(JobKey key: scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { jobNames.add(key.getName()); } return jobNames; } catch (Exception e) { throw newPlainException(e); } }
public List<TaskScheduled> getAllJobDetail() { List<TaskScheduled> result = new LinkedList<TaskScheduled>(); try { GroupMatcher<JobKey> matcher = GroupMatcher.jobGroupContains(""); Set<JobKey> jobKeys = scheduler.getJobKeys(matcher); for (JobKey jobKey : jobKeys) { JobDetail jobDetail = scheduler.getJobDetail(jobKey); List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey); for (Trigger trigger : triggers) { TaskScheduled job = new TaskScheduled(); job.setTaskName(jobKey.getName()); job.setTaskGroup(jobKey.getGroup()); TriggerState triggerState = scheduler.getTriggerState(trigger.getKey()); job.setStatus(triggerState.name()); if (trigger instanceof CronTrigger) { CronTrigger cronTrigger = (CronTrigger)trigger; String cronExpression = cronTrigger.getCronExpression(); job.setTaskCron(cronExpression); } job.setPreviousFireTime(trigger.getPreviousFireTime()); job.setNextFireTime(trigger.getNextFireTime()); JobDataMap jobDataMap = trigger.getJobDataMap(); job.setTaskType(jobDataMap.getString("taskType")); job.setTargetSystem(jobDataMap.getString("targetSystem")); job.setTargetObject(jobDataMap.getString("targetObject")); job.setTargetMethod(jobDataMap.getString("targetMethod")); job.setContactName(jobDataMap.getString("contactName")); job.setContactEmail(jobDataMap.getString("contactEmail")); job.setTaskDesc(jobDetail.getDescription()); String jobClass = jobDetail.getJobClass().getSimpleName(); if (jobClass.equals("StatefulJob")) { job.setJobType("statefulJob"); } else if (jobClass.equals("DefaultJob")) { job.setJobType("job"); } result.add(job); } } } catch (Exception e) { logger.error("Try to load All JobDetail cause error : ", e); } return result; }
/** * Remove all schedules matching the given predicate from the current * scheduler, then from the data base. */ private void unscheduleAll(final Predicate<TriggerKey> predicate) throws SchedulerException { // Remove current schedules from the memory final Scheduler scheduler = vmSchedulerFactoryBean.getObject(); for (final TriggerKey triggerKey : scheduler.getTriggerKeys(GroupMatcher.groupEquals(SCHEDULE_TRIGGER_GROUP))) { if (predicate.test(triggerKey)) { // Match subscription and operation, unschedule this trigger scheduler.unscheduleJob(triggerKey); } } }
@After public void cleanTrigger() throws SchedulerException { // Remove all previous VM trigger final Scheduler scheduler = vmSchedulerFactoryBean.getScheduler(); scheduler.unscheduleJobs(new ArrayList<>(scheduler.getTriggerKeys(GroupMatcher.groupEquals(VmResource.SCHEDULE_TRIGGER_GROUP)))); }
/** * Renders a page listing all scheduled emails. */ public ActionForward showScheduledEmails(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, SchedulerException { getUserManagementService(); Scheduler scheduler = getScheduler(); TreeSet<EmailScheduleMessageJobDTO> scheduleList = new TreeSet<EmailScheduleMessageJobDTO>(); Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); boolean isLessonNotifications = (lessonId != null); Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); if (isLessonNotifications) { if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(), "show scheduled lesson email notifications", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson"); return null; } } else { if (!getSecurityService().isGroupMonitor(organisationId, getCurrentUser().getUserID(), "show scheduled course email notifications", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the organisation"); return null; } } Set<TriggerKey> triggerKeys = scheduler .getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP)); for (TriggerKey triggerKey : triggerKeys) { String triggerName = triggerKey.getName(); if (triggerName.startsWith(EmailNotificationsAction.TRIGGER_PREFIX_NAME)) { Trigger trigger = scheduler.getTrigger(triggerKey); JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey()); JobDataMap jobDataMap = jobDetail.getJobDataMap(); // filter triggers if (isLessonNotifications) { Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID); if ((jobLessonId == null) || (!lessonId.equals(jobLessonId))) { continue; } } else { Object jobOrganisationId = jobDataMap.get(AttributeNames.PARAM_ORGANISATION_ID); if ((jobOrganisationId == null) || (!organisationId.equals(jobOrganisationId))) { continue; } } Date triggerDate = trigger.getNextFireTime(); String emailBody = WebUtil.convertNewlines((String) jobDataMap.get("emailBody")); int searchType = (Integer) jobDataMap.get("searchType"); EmailScheduleMessageJobDTO emailScheduleJobDTO = new EmailScheduleMessageJobDTO(); emailScheduleJobDTO.setTriggerName(triggerName); emailScheduleJobDTO.setTriggerDate(triggerDate); emailScheduleJobDTO.setEmailBody(emailBody); emailScheduleJobDTO.setSearchType(searchType); scheduleList.add(emailScheduleJobDTO); } } request.setAttribute("scheduleList", scheduleList); request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId); request.setAttribute(AttributeNames.PARAM_ORGANISATION_ID, organisationId); return mapping.findForward("scheduledEmailList"); }
/** * Gets learners or monitors of the lesson and organisation containing it. * * @throws SchedulerException */ public ActionForward getEmailProgressDates(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, JSONException, SchedulerException { Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(), "get class members", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); return null; } HttpSession ss = SessionManager.getSession(); UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); JSONObject responseJSON = new JSONObject(); JSONArray datesJSON = new JSONArray(); // find all the current dates set up to send the emails Scheduler scheduler = getScheduler(); String triggerPrefix = getTriggerPrefix(lessonId); SortedSet<Date> currentDatesSet = new TreeSet<Date>(); Set<TriggerKey> triggerKeys = scheduler .getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP)); for (TriggerKey triggerKey : triggerKeys) { String triggerName = triggerKey.getName(); if (triggerName.startsWith(triggerPrefix)) { Trigger trigger = scheduler.getTrigger(triggerKey); JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey()); JobDataMap jobDataMap = jobDetail.getJobDataMap(); // get only the trigger for the current lesson Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID); if (lessonId.equals(jobLessonId)) { Date triggerDate = trigger.getNextFireTime(); currentDatesSet.add(triggerDate); } } } for (Date date : currentDatesSet) { datesJSON.put(createDateJSON(request.getLocale(), user, date, null)); } responseJSON.put("dates", datesJSON); response.setContentType("application/json;charset=utf-8"); response.getWriter().write(responseJSON.toString()); return null; }
@Override public Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { try { return realJobStore.getTriggerKeys(matcher); } catch (RejoinException e) { throw new JobPersistenceException("Trigger key retrieval failed due to client rejoin", e); } }
@Override public Collection<String> pauseJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException { try { return realJobStore.pauseJobs(matcher); } catch (RejoinException e) { throw new JobPersistenceException("Pausing jobs failed due to client rejoin", e); } }
/** * Removes the sleep mode. * @throws SchedulerException when the sleep mode cannot be removed. */ public void removeSleepMode() throws SchedulerException { LOGGER.trace("Removing sleep mode..."); for (TriggerKey tk : this.scheduler.getTriggerKeys(GroupMatcher.anyTriggerGroup())) { Trigger t = this.scheduler.getTrigger(tk); this.scheduler.rescheduleJob(tk, t.getTriggerBuilder().startNow().modifiedByCalendar(null).build()); } this.scheduler.deleteCalendar(CALENDAR_SLEEP); LOGGER.trace("Sleep mode removed"); }
@Override public Collection<String> resumeTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { try { return realJobStore.resumeTriggers(matcher); } catch (RejoinException e) { throw new JobPersistenceException("Resuming triggers failed due to client rejoin", e); } }
public List<Task> getTasks() throws SchedulerException { Scheduler scheduler = schedulerFactoryBean.getScheduler(); GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup(); Set<JobKey> jobKeys = scheduler.getJobKeys(matcher); List<Task> taskList = new ArrayList<>(); for (JobKey jobKey : jobKeys) { List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey); for (Trigger trigger : triggers) { Task task = new Task(); task.setJobGroup(jobKey.getGroup()); task.setJobName(jobKey.getName()); if (trigger instanceof SimpleTrigger) { SimpleTrigger simpleTrigger = (SimpleTrigger) trigger; JobDetail jobDetail = scheduler.getJobDetail(jobKey); task.setDescription(jobDetail.getDescription()); if (simpleTrigger.getRepeatCount()<1) { task.setProgress(0.0); } else { if (jobDetail.getJobDataMap().get("overallCounter")!= null) { Double progress = Double.parseDouble(jobDetail.getJobDataMap().get("overallCounter").toString()); task.setProgress((progress/simpleTrigger.getRepeatCount() * 100)); } else { task.setProgress(0.0); } } } taskList.add(task); } } return taskList; }
/** * <p> * Get the names of all of the <code>{@link org.quartz.Trigger}</code> s that have the given group name. * </p> */ @Override public Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { lock(); try { Set<String> groupNames = new HashSet<String>(); switch (matcher.getCompareWithOperator()) { case EQUALS: groupNames.add(matcher.getCompareToValue()); break; default: for (String group : triggerFacade.allTriggersGroupNames()) { if (matcher.getCompareWithOperator().evaluate(group, matcher.getCompareToValue())) { groupNames.add(group); } } } Set<TriggerKey> out = new HashSet<TriggerKey>(); for (String groupName : groupNames) { Set<String> grpSet = toolkitDSHolder.getOrCreateTriggersGroupMap(groupName); for (String key : grpSet) { TriggerKey triggerKey = new TriggerKey(key, groupName); TriggerWrapper tw = triggerFacade.get(triggerKey); if (tw != null) { out.add(triggerKey); } } } return out; } finally { unlock(); } }
public void resumeJobs(GroupMatcher<JobKey> matcher) throws Exception { try { scheduler.resumeJobs(matcher); } catch (Exception e) { throw newPlainException(e); } }
/** * <p> * Pause all triggers - equivalent of calling <code>pauseTriggerGroup(group)</code> on every group. * </p> * <p> * When <code>resumeAll()</code> is called (to un-pause), trigger misfire instructions WILL be applied. * </p> * * @see #resumeAll() * @see #pauseTriggers(org.quartz.impl.matchers.GroupMatcher) */ @Override public void pauseAll() throws JobPersistenceException { lock(); try { List<String> names = getTriggerGroupNames(); for (String name : names) { pauseTriggers(GroupMatcher.triggerGroupEquals(name)); } } finally { unlock(); } }
public List<String> getTriggerNames(String groupName) throws Exception { try { List<String> triggerNames = new ArrayList<String>(); for(TriggerKey key: scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName))) { triggerNames.add(key.getName()); } return triggerNames; } catch (Exception e) { throw newPlainException(e); } }
/** * <p> * Pause all of the known <code>{@link Trigger}s</code> matching. * </p> * * <p> * The JobStore should "remember" the groups paused, and impose the * pause on any new triggers that are added to one of these groups while the group is * paused. * </p> * */ public List<String> pauseTriggers(GroupMatcher<TriggerKey> matcher) { List<String> pausedGroups; synchronized (lock) { pausedGroups = new LinkedList<String>(); StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator(); switch (operator) { case EQUALS: if(pausedTriggerGroups.add(matcher.getCompareToValue())) { pausedGroups.add(matcher.getCompareToValue()); } break; default : for (String group : triggersByGroup.keySet()) { if(operator.evaluate(group, matcher.getCompareToValue())) { if(pausedTriggerGroups.add(matcher.getCompareToValue())) { pausedGroups.add(group); } } } } for (String pausedGroup : pausedGroups) { Set<TriggerKey> keys = getTriggerKeys(GroupMatcher.triggerGroupEquals(pausedGroup)); for (TriggerKey key: keys) { pauseTrigger(key); } } } return pausedGroups; }
/** * <p> * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the * given group - by pausing all of their <code>Trigger</code>s. * </p> * * * <p> * The JobStore should "remember" that the group is paused, and impose the * pause on any new jobs that are added to the group while the group is * paused. * </p> */ public List<String> pauseJobs(GroupMatcher<JobKey> matcher) { List<String> pausedGroups = new LinkedList<String>(); synchronized (lock) { StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator(); switch (operator) { case EQUALS: if (pausedJobGroups.add(matcher.getCompareToValue())) { pausedGroups.add(matcher.getCompareToValue()); } break; default : for (String group : jobsByGroup.keySet()) { if(operator.evaluate(group, matcher.getCompareToValue())) { if (pausedJobGroups.add(group)) { pausedGroups.add(group); } } } } for (String groupName : pausedGroups) { for (JobKey jobKey: getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { List<OperableTrigger> triggersOfJob = getTriggersForJob(jobKey); for (OperableTrigger trigger: triggersOfJob) { pauseTrigger(trigger.getKey()); } } } } return pausedGroups; }
public void pauseJobs(GroupMatcher<JobKey> matcher) throws Exception { try { scheduler.pauseJobs(matcher); } catch (Exception e) { throw newPlainException(e); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public void pauseTriggers(GroupMatcher<TriggerKey> matcher) throws SchedulerException { String operation = null; switch (matcher.getCompareWithOperator()) { case EQUALS: operation = "pauseTriggerGroup"; break; case CONTAINS: operation = "pauseTriggersContaining"; break; case STARTS_WITH: operation = "pauseTriggersStartingWith"; break; case ENDS_WITH: operation = "pauseTriggersEndingWith"; case ANYTHING: operation = "pauseTriggersAll"; } if (operation != null) { invoke( operation, new Object[] { matcher.getCompareToValue() }, new String[] { String.class.getName() }); } else { throw new SchedulerException("Unsupported GroupMatcher kind for pausing triggers: " + matcher.getCompareWithOperator()); } }
public JobKey getJobKey(final String taskId) { JobKey jobKey = null; try { for (final JobKey key : scheduler.getJobKeys(GroupMatcher .jobGroupEquals(JOB_GROUP))) { if (key.getName().equalsIgnoreCase(taskId)) { jobKey = key; break; } } } catch (SchedulerException e) { LOGGER.error(e); } return jobKey; }
/** * <p> * Get the names of all of the <code>{@link org.quartz.Job}</code> s that * matcher the given groupMatcher. * </p> * * <p> * If there are no jobs in the given group name, the result should be an empty Set * </p> */ @SuppressWarnings("unchecked") public Set<JobKey> getJobKeys(final GroupMatcher<JobKey> matcher) throws JobPersistenceException { return (Set<JobKey>)executeWithoutLock( // no locks necessary for read... new TransactionCallback() { public Object execute(Connection conn) throws JobPersistenceException { return getJobNames(conn, matcher); } }); }
protected Set<JobKey> getJobNames(Connection conn, GroupMatcher<JobKey> matcher) throws JobPersistenceException { Set<JobKey> jobNames; try { jobNames = getDelegate().selectJobsInGroup(conn, matcher); } catch (SQLException e) { throw new JobPersistenceException("Couldn't obtain job names: " + e.getMessage(), e); } return jobNames; }
protected Set<TriggerKey> getTriggerNames(Connection conn, GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { Set<TriggerKey> trigNames; try { trigNames = getDelegate().selectTriggersInGroup(conn, matcher); } catch (SQLException e) { throw new JobPersistenceException("Couldn't obtain trigger names: " + e.getMessage(), e); } return trigNames; }
/** * <p> * Resume (un-pause) all of the <code>{@link org.quartz.JobDetail}s</code> * in the matching groups. * </p> * * <p> * If any of the <code>Job</code> s had <code>Trigger</code> s that * missed one or more fire-times, then the <code>Trigger</code>'s * misfire instruction will be applied. * </p> * */ public void resumeJobs(GroupMatcher<JobKey> matcher) throws SchedulerException { validateState(); if(matcher == null) { matcher = GroupMatcher.groupEquals(Scheduler.DEFAULT_GROUP); } Collection<String> resumedGroups = resources.getJobStore().resumeJobs(matcher); notifySchedulerThread(0L); for (String pausedGroup : resumedGroups) { notifySchedulerListenersResumedJobs(pausedGroup); } }
/** * <p> * Pause all of the <code>{@link org.quartz.Trigger}s</code> matching the * given groupMatcher. * </p> * * @see #resumeTriggerGroup(java.sql.Connection, org.quartz.impl.matchers.GroupMatcher) */ public Set<String> pauseTriggerGroup(Connection conn, GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { try { getDelegate().updateTriggerGroupStateFromOtherStates( conn, matcher, STATE_PAUSED, STATE_ACQUIRED, STATE_WAITING, STATE_WAITING); getDelegate().updateTriggerGroupStateFromOtherState( conn, matcher, STATE_PAUSED_BLOCKED, STATE_BLOCKED); List<String> groups = getDelegate().selectTriggerGroups(conn, matcher); // make sure to account for an exact group match for a group that doesn't yet exist StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator(); if (operator.equals(StringOperatorName.EQUALS) && !groups.contains(matcher.getCompareToValue())) { groups.add(matcher.getCompareToValue()); } for (String group : groups) { if (!getDelegate().isTriggerGroupPaused(conn, group)) { getDelegate().insertPausedTriggerGroup(conn, group); } } return new HashSet<String>(groups); } catch (SQLException e) { throw new JobPersistenceException("Couldn't pause trigger group '" + matcher + "': " + e.getMessage(), e); } }