org.quartz.TriggerKey Java Examples
The following examples show how to use
org.quartz.TriggerKey.
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: DefaultClusteredJobStore.java From lams with GNU General Public License v2.0 | 6 votes |
/** * <p> * Remove (delete) the <code>{@link org.quartz.Calendar}</code> with the given name. * </p> * <p> * If removal of the <code>Calendar</code> would result in <code.Trigger</code>s pointing to non-existent calendars, * then a <code>JobPersistenceException</code> will be thrown. * </p> * * * * @param calName The name of the <code>Calendar</code> to be removed. * @return <code>true</code> if a <code>Calendar</code> with the given name was found and removed from the store. */ @Override public boolean removeCalendar(String calName) throws JobPersistenceException { int numRefs = 0; lock(); try { for (TriggerKey triggerKey : triggerFacade.allTriggerKeys()) { TriggerWrapper tw = triggerFacade.get(triggerKey); if (tw.getCalendarName() != null && tw.getCalendarName().equals(calName)) { numRefs++; } } if (numRefs > 0) { throw new JobPersistenceException("Calender cannot be removed if it referenced by a Trigger!"); } return (calendarsByName.remove(calName) != null); } finally { unlock(); } }
Example #2
Source File: JobInstanceTest.java From griffin with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testExecuteWithRangeLessThanZero() throws Exception { JobExecutionContext context = mock(JobExecutionContext.class); Scheduler scheduler = mock(Scheduler.class); GriffinMeasure measure = createGriffinMeasure("measureName"); JobDetail jd = createJobDetail(JsonUtil.toJson(measure), ""); BatchJob job = new BatchJob(1L, "jobName", "qName", "qGroup", false); List<Trigger> triggers = Arrays.asList(createSimpleTrigger(2, 0)); given(context.getJobDetail()).willReturn(jd); given(measureRepo.findOne(Matchers.anyLong())).willReturn(measure); given(jobRepo.findOne(Matchers.anyLong())).willReturn(job); given(factory.getScheduler()).willReturn(scheduler); given((List<Trigger>) scheduler.getTriggersOfJob(Matchers.any( JobKey.class))).willReturn(triggers); given(scheduler.checkExists(Matchers.any(TriggerKey.class))) .willReturn(false); given(jobRepo.save(Matchers.any(BatchJob.class))).willReturn(job); given(scheduler.checkExists(Matchers.any(JobKey.class))) .willReturn(false); jobInstance.execute(context); }
Example #3
Source File: StdJDBCDelegate.java From lams with GNU General Public License v2.0 | 6 votes |
/** * <p> * Delete the base trigger data for a trigger. * </p> * * @param conn * the DB Connection * @return the number of rows deleted */ public int deleteTrigger(Connection conn, TriggerKey triggerKey) throws SQLException { PreparedStatement ps = null; deleteTriggerExtension(conn, triggerKey); try { ps = conn.prepareStatement(rtp(DELETE_TRIGGER)); ps.setString(1, triggerKey.getName()); ps.setString(2, triggerKey.getGroup()); return ps.executeUpdate(); } finally { closeStatement(ps); } }
Example #4
Source File: AbstractQuartzTaskManager.java From micro-integrator with Apache License 2.0 | 6 votes |
protected synchronized void resumeLocalTask(String taskName) throws TaskException { String taskGroup = this.getTenantTaskGroup(); if (!this.isPreviouslyScheduled(taskName, taskGroup)) { throw new TaskException("Non-existing task for resuming with name: " + taskName, TaskException.Code.NO_TASK_EXISTS); } try { Trigger trigger = this.getScheduler().getTrigger(new TriggerKey(taskName, taskGroup)); if (trigger instanceof OperableTrigger) { ((OperableTrigger) trigger).setNextFireTime(trigger.getFireTimeAfter(null)); } this.getScheduler().resumeJob(new JobKey(taskName, taskGroup)); log.info("Task resumed: [" + this.getTaskType() + "][" + taskName + "]"); } catch (SchedulerException e) { throw new TaskException("Error in resuming task with name: " + taskName, TaskException.Code.UNKNOWN, e); } }
Example #5
Source File: SchedulerTool.java From sakai with Educational Community License v2.0 | 6 votes |
public void validateTriggerName(FacesContext context, UIComponent component, Object object) { if (object instanceof String) { String value = (String)object; try { Trigger trigger = schedulerManager.getScheduler().getTrigger(TriggerKey.triggerKey(value, Scheduler.DEFAULT_GROUP)); if (trigger != null) { FacesMessage message = new FacesMessage(rb.getString("existing_trigger_name")); message.setSeverity(FacesMessage.SEVERITY_WARN); throw new ValidatorException(message); } } catch (SchedulerException e) { log.error("Scheduler down!"); } } }
Example #6
Source File: RedisJobStore.java From redis-quartz with MIT License | 6 votes |
@Override public boolean replaceTrigger(TriggerKey triggerKey, OperableTrigger newTrigger) throws JobPersistenceException { boolean replaced = false; String triggerHashKey = createTriggerHashKey(triggerKey.getGroup(), triggerKey.getName()); try (Jedis jedis = pool.getResource()) { lockPool.acquire(); String jobHashKey =jedis.hget(triggerHashKey, JOB_HASH_KEY); if (jobHashKey == null || jobHashKey.isEmpty()) throw new JobPersistenceException("trigger does not exist or no job is associated with the trigger"); if (!jobHashKey.equals(createJobHashKey(newTrigger.getJobKey().getGroup(), newTrigger.getJobKey().getName()))) throw new JobPersistenceException("the new trigger is associated with a diffrent job than the existing trigger"); removeTrigger(triggerKey, jedis); storeTrigger(newTrigger, false, jedis); replaced = true; } catch (Exception ex) { log.error("could not replace trigger: " + triggerHashKey, ex); throw new JobPersistenceException(ex.getMessage(), ex.getCause()); } finally { lockPool.release(); } return replaced; }
Example #7
Source File: JobStoreSupport.java From lams with GNU General Public License v2.0 | 6 votes |
public boolean removeTriggers(final List<TriggerKey> triggerKeys) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, new TransactionCallback() { public Object execute(Connection conn) throws JobPersistenceException { boolean allFound = true; // FUTURE_TODO: make this more efficient with a true bulk operation... for (TriggerKey triggerKey : triggerKeys) allFound = removeTrigger(conn, triggerKey) && allFound; return allFound ? Boolean.TRUE : Boolean.FALSE; } }); }
Example #8
Source File: QuartzManageController.java From EserKnife with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/remove") public @ResponseBody Map<String,Object> remove(HttpServletRequest request) { Map<String,Object> map = new HashMap<String,Object>(); String name = request.getParameter("name"); String group = request.getParameter("group"); if (StringUtils.isNotBlank(name) || StringUtils.isNotBlank(group)) { boolean result = schedulerCenter.unscheduleJob(new TriggerKey(name, group)); map.put("success", result); if(result) { map.put("msg", "删除成功!"); }else { map.put("msg", "删除失败!"); } } return map; }
Example #9
Source File: StdJDBCDelegate.java From lams with GNU General Public License v2.0 | 6 votes |
public List<TriggerKey> selectMisfiredTriggersInState(Connection conn, String state, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_STATE)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, state); rs = ps.executeQuery(); LinkedList<TriggerKey> list = new LinkedList<TriggerKey>(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); list.add(triggerKey(triggerName, groupName)); } return list; } finally { closeResultSet(rs); closeStatement(ps); } }
Example #10
Source File: SchedulerTool.java From sakai with Educational Community License v2.0 | 6 votes |
public void validateTriggerName(FacesContext context, UIComponent component, Object object) { if (object instanceof String) { String value = (String)object; try { Trigger trigger = schedulerManager.getScheduler().getTrigger(TriggerKey.triggerKey(value, Scheduler.DEFAULT_GROUP)); if (trigger != null) { FacesMessage message = new FacesMessage(rb.getString("existing_trigger_name")); message.setSeverity(FacesMessage.SEVERITY_WARN); throw new ValidatorException(message); } } catch (SchedulerException e) { log.error("Scheduler down!"); } } }
Example #11
Source File: RedisJobStore.java From redis-quartz with MIT License | 6 votes |
@Override public void resumeTrigger(TriggerKey triggerKey) throws JobPersistenceException { String triggerHashKey = createTriggerHashKey(triggerKey.getGroup(), triggerKey.getName()); try (Jedis jedis = pool.getResource()) { lockPool.acquire(); OperableTrigger trigger = retrieveTrigger(new TriggerKey(triggerHashKey.split(":")[2], triggerHashKey.split(":")[1]), jedis); resumeTrigger(trigger, jedis); if (trigger != null) applyMisfire(trigger, jedis); } catch (Exception ex) { log.error("could not resume trigger: " + triggerHashKey, ex); throw new JobPersistenceException(ex.getMessage(), ex.getCause()); } finally { lockPool.release(); } }
Example #12
Source File: JobStoreSupport.java From lams with GNU General Public License v2.0 | 6 votes |
protected boolean updateMisfiredTrigger(Connection conn, TriggerKey triggerKey, String newStateIfNotComplete, boolean forceState) throws JobPersistenceException { try { OperableTrigger trig = retrieveTrigger(conn, triggerKey); long misfireTime = System.currentTimeMillis(); if (getMisfireThreshold() > 0) { misfireTime -= getMisfireThreshold(); } if (trig.getNextFireTime().getTime() > misfireTime) { return false; } doUpdateOfMisfiredTrigger(conn, trig, forceState, newStateIfNotComplete, false); return true; } catch (Exception e) { throw new JobPersistenceException( "Couldn't update misfired trigger '" + triggerKey + "': " + e.getMessage(), e); } }
Example #13
Source File: QuartzSchedulerMBeanImpl.java From lams with GNU General Public License v2.0 | 6 votes |
public Date scheduleJob(String jobName, String jobGroup, String triggerName, String triggerGroup) throws Exception { try { JobKey jobKey = jobKey(jobName, jobGroup); JobDetail jobDetail = scheduler.getJobDetail(jobKey); if (jobDetail == null) { throw new IllegalArgumentException("No such job: " + jobKey); } TriggerKey triggerKey = triggerKey(triggerName, triggerGroup); Trigger trigger = scheduler.getTrigger(triggerKey); if (trigger == null) { throw new IllegalArgumentException("No such trigger: " + triggerKey); } return scheduler.scheduleJob(jobDetail, trigger); } catch (Exception e) { throw newPlainException(e); } }
Example #14
Source File: StdJDBCDelegate.java From lams with GNU General Public License v2.0 | 6 votes |
/** * <p> * Get the names of all of the triggers in the given group and state that * have misfired. * </p> * * @param conn * the DB Connection * @return an array of <code>{@link * org.quartz.utils.Key}</code> objects */ public List<TriggerKey> selectMisfiredTriggersInGroupInState(Connection conn, String groupName, String state, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn .prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_GROUP_IN_STATE)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, groupName); ps.setString(3, state); rs = ps.executeQuery(); LinkedList<TriggerKey> list = new LinkedList<TriggerKey>(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); list.add(triggerKey(triggerName, groupName)); } return list; } finally { closeResultSet(rs); closeStatement(ps); } }
Example #15
Source File: JobServiceImpl.java From spring-boot-quartz-demo with MIT License | 6 votes |
/** * Remove the indicated Trigger from the scheduler. * If the related job does not have any other triggers, and the job is not durable, then the job will also be deleted. */ @Override public boolean unScheduleJob(String jobName) { System.out.println("Request received for Unscheduleding job."); String jobKey = jobName; TriggerKey tkey = new TriggerKey(jobKey); System.out.println("Parameters received for unscheduling job : tkey :"+jobKey); try { boolean status = schedulerFactoryBean.getScheduler().unscheduleJob(tkey); System.out.println("Trigger associated with jobKey :"+jobKey+ " unscheduled with status :"+status); return status; } catch (SchedulerException e) { System.out.println("SchedulerException while unscheduling job with key :"+jobKey + " message :"+e.getMessage()); e.printStackTrace(); return false; } }
Example #16
Source File: JobStoreSupport.java From lams with GNU General Public License v2.0 | 6 votes |
/** * <p> * Pause the <code>{@link org.quartz.Trigger}</code> with the given name. * </p> * * @see #resumeTrigger(Connection, TriggerKey) */ public void pauseTrigger(Connection conn, TriggerKey triggerKey) throws JobPersistenceException { try { String oldState = getDelegate().selectTriggerState(conn, triggerKey); if (oldState.equals(STATE_WAITING) || oldState.equals(STATE_ACQUIRED)) { getDelegate().updateTriggerState(conn, triggerKey, STATE_PAUSED); } else if (oldState.equals(STATE_BLOCKED)) { getDelegate().updateTriggerState(conn, triggerKey, STATE_PAUSED_BLOCKED); } } catch (SQLException e) { throw new JobPersistenceException("Couldn't pause trigger '" + triggerKey + "': " + e.getMessage(), e); } }
Example #17
Source File: TestTriggerEventManagerHibernateImpl.java From sakai with Educational Community License v2.0 | 6 votes |
@Test public void testCreateTriggerEventSucceds() throws Exception { final TriggerEventHibernateImpl evt = getTestTriggerEvent(); final TriggerEventHibernateImpl result = (TriggerEventHibernateImpl)mgr.createTriggerEvent(evt.getEventType(), JobKey.jobKey(evt.getJobName()), TriggerKey.triggerKey(evt.getTriggerName()), evt.getTime(), evt.getMessage(), "server1"); Assert.assertNotNull(result); Assert.assertNotNull(result.getId()); assertEquals(evt, result); }
Example #18
Source File: ScheduledInvocationManagerImpl.java From sakai with Educational Community License v2.0 | 6 votes |
@Transactional(propagation = REQUIRES_NEW) public DelayedInvocation[] findDelayedInvocations(String componentId, String opaqueContext) { log.debug("componentId=" + componentId + ", opaqueContext=" + opaqueContext); Collection<String> uuids = dao.find(componentId, opaqueContext); List<DelayedInvocation> invocations = new ArrayList<>(); for (String uuid: uuids) { TriggerKey key = new TriggerKey(uuid, GROUP_NAME); try { Trigger trigger = schedulerFactory.getScheduler().getTrigger(key); if (trigger == null) { log.error("Failed to trigger with key: {}", key); } else { invocations.add(new DelayedInvocation(trigger.getKey().getName(), trigger.getNextFireTime(), key.getName(), opaqueContext)); } } catch (SchedulerException e) { log.warn("Problem finding delayed invocations.", e); return null; } } return invocations.toArray(new DelayedInvocation[]{}); }
Example #19
Source File: QuartzUtil.java From fixflow with Apache License 2.0 | 5 votes |
/** * 根据定时任务和触发器名称得到触发器 * @param scheduler 定时任务 * @param triggerKey 触发器名称 * @return */ public static Trigger getTrigger(Scheduler scheduler, String triggerKey) { Trigger trigger = null; try { trigger = scheduler.getTrigger(new TriggerKey(triggerKey)); } catch (SchedulerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return trigger; }
Example #20
Source File: AbstractTerracottaJobStore.java From lams with GNU General Public License v2.0 | 5 votes |
@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); } }
Example #21
Source File: BroadcastSchedulerListener.java From lams with GNU General Public License v2.0 | 5 votes |
public void triggerPaused(TriggerKey key) { Iterator<SchedulerListener> itr = listeners.iterator(); while(itr.hasNext()) { SchedulerListener l = itr.next(); l.triggerPaused(key); } }
Example #22
Source File: JobScheduleControllerTest.java From shardingsphere-elasticjob-lite with Apache License 2.0 | 5 votes |
@Test public void assertRescheduleJobSuccess() throws SchedulerException { when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new CronTriggerImpl()); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); jobScheduleController.rescheduleJob("0/1 * * * * ?"); verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); }
Example #23
Source File: RedisCenterImpl.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public boolean unDeployRedisSlowLogCollection(long appId, String host, int port) { Assert.isTrue(appId > 0); Assert.hasText(host); Assert.isTrue(port > 0); TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_SLOWLOG_TRIGGER_GROUP + appId); Trigger trigger = schedulerCenter.getTrigger(triggerKey); if (trigger == null) { return true; } return schedulerCenter.unscheduleJob(triggerKey); }
Example #24
Source File: QuartzSchedulerMBeanImpl.java From lams with GNU General Public License v2.0 | 5 votes |
public void triggerPaused(TriggerKey triggerKey) { Map<String, String> map = new HashMap<String, String>(); if(triggerKey != null) { map.put("triggerName", triggerKey.getName()); map.put("triggerGroup", triggerKey.getGroup()); } sendNotification(TRIGGERS_PAUSED, map); }
Example #25
Source File: ScheduleService.java From elasticsearch-quartz with Apache License 2.0 | 5 votes |
public void resumeTriggers(final GroupMatcher<TriggerKey> matcher) { try { scheduler.resumeTriggers(matcher); } catch (final SchedulerException e) { throw new QuartzSchedulerException(e); } }
Example #26
Source File: TriggerCenterImpl.java From cachecloud with Apache License 2.0 | 5 votes |
/** * 删除一个trigger * * @param triggerKey * @return */ @Override public boolean removeTrigger(TriggerKey triggerKey) { boolean opResult = true; try { clusterScheduler.unscheduleJob(triggerKey); } catch (SchedulerException e) { logger.error(e.getMessage(), e); opResult = false; } return opResult; }
Example #27
Source File: JobTrigger.java From spring-cloud-shop with MIT License | 5 votes |
/** * 更新定时任务 * * @param scheduler the scheduler * @param jobName the job name * @param jobGroup the job group * @param cronExpression the cron expression * @param param the param */ private static void updateJob(Scheduler scheduler, String jobName, String jobGroup, String cronExpression, Object param) throws SchedulerException { // 同步或异步 Class<? extends Job> jobClass = JobQuartzJobBean.class; JobDetail jobDetail = scheduler.getJobDetail(getJobKey(jobName, jobGroup)); jobDetail = jobDetail.getJobBuilder().ofType(jobClass).build(); // 更新参数 实际测试中发现无法更新 JobDataMap jobDataMap = jobDetail.getJobDataMap(); jobDataMap.put("JobAdapter", param); jobDetail.getJobBuilder().usingJobData(jobDataMap); TriggerKey triggerKey = getTriggerKey(jobName, jobGroup); // 表达式调度构建器 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 按新的cronExpression表达式重新构建trigger trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey()); // 忽略状态为PAUSED的任务,解决集群环境中在其他机器设置定时任务为PAUSED状态后,集群环境启动另一台主机时定时任务全被唤醒的bug if (!JobEnums.PAUSE.name().equalsIgnoreCase(triggerState.name())) { // 按新的trigger重新设置job执行 scheduler.rescheduleJob(triggerKey, trigger); } }
Example #28
Source File: JobStoreImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Collection<String> resumeTriggers(final GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { log.debug("Resume triggers: {}", matcher); return executeWrite(db -> { Set<String> groups = getTriggerGroups(db, matcher); for (String group : groups) { for (TriggerKey triggerKey : getTriggerKeys(db, GroupMatcher.triggerGroupEquals(group))) { resumeTrigger(db, triggerKey); } } return groups; }); }
Example #29
Source File: RemoteScheduler.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>. * </p> */ public void pauseTrigger(TriggerKey triggerKey) throws SchedulerException { try { getRemoteScheduler() .pauseTrigger(triggerKey); } catch (RemoteException re) { throw invalidateHandleCreateException( "Error communicating with remote scheduler.", re); } }
Example #30
Source File: TriggerCenterImpl.java From EserKnife with Apache License 2.0 | 5 votes |
/** * 恢复暂停的trigger * * @param triggerKey */ @Override public boolean resumeTrigger(TriggerKey triggerKey) { boolean opResult = true; try { clusterScheduler.resumeTrigger(triggerKey); } catch (SchedulerException e) { LOGGER.error(e.getMessage(), e); opResult = false; } return opResult; }