@Test public void testScheduleTask() throws TaskSchedulerException { Scheduler scheduler = new FakeQuartzScheduler(); QuartzTaskScheduler quartzTaskScheduler = new QuartzTaskScheduler(); quartzTaskScheduler.setScheduler(scheduler); TestTask task = new TestTask(); TaskRegistration registration = quartzTaskScheduler.scheduleTask( new TaskConfiguration("*/15 * * ? * *", "name", "group", false), task); registration.trigger(); assertTrue("Job was not executed", task.isExecuted()); }
@Override public TaskRegistration scheduleTask(TaskConfiguration config, Object bean) throws TaskSchedulerException { if (config == null) { throw new IllegalArgumentException("config is null"); } if (bean == null) { throw new IllegalArgumentException("bean is null"); } if (this.scheduler == null) { throw new IllegalStateException("schedule is null"); } try { if (Task.class.isAssignableFrom(bean.getClass())) { } else if (Job.class.isAssignableFrom(bean.getClass())) { log.warn("[DEPRECATION] '{}' Implementing {} directly is deprecated, please implement {}", bean.getClass().getCanonicalName(), Job.class.getName(), Task.class.getName()); } else { throw new IllegalArgumentException(String.format("argument 'bean' does not implement interface " + Task.class.getName())); } CronTrigger trigger = new CronTrigger(config.getName(), config.getGroup(), config.getCron()); JobDetail jobDetail = new JobDetail(config.getName(), config.getGroup(), this.getJobClass(config)); JobDataMap map = new JobDataMap(); map.put(BEAN_ID, bean); map.put(JOB_LOCK_SERVICE, this.jobLockService); map.put("name", trigger.getKey().toString()); jobDetail.setJobDataMap(map); scheduler.scheduleJob(jobDetail, trigger); return new QuartzTaskRegistration(scheduler, config); } catch (ParseException | org.quartz.SchedulerException e) { throw new TaskSchedulerException(e); } }
QuartzTaskScheduler implements TaskScheduler { @Override public TaskRegistration scheduleTask(TaskConfiguration config, Object bean) throws TaskSchedulerException { if (config == null) { throw new IllegalArgumentException("config is null"); } if (bean == null) { throw new IllegalArgumentException("bean is null"); } if (this.scheduler == null) { throw new IllegalStateException("schedule is null"); } try { if (Task.class.isAssignableFrom(bean.getClass())) { } else if (Job.class.isAssignableFrom(bean.getClass())) { log.warn("[DEPRECATION] '{}' Implementing {} directly is deprecated, please implement {}", bean.getClass().getCanonicalName(), Job.class.getName(), Task.class.getName()); } else { throw new IllegalArgumentException(String.format("argument 'bean' does not implement interface " + Task.class.getName())); } CronTrigger trigger = new CronTrigger(config.getName(), config.getGroup(), config.getCron()); JobDetail jobDetail = new JobDetail(config.getName(), config.getGroup(), this.getJobClass(config)); JobDataMap map = new JobDataMap(); map.put(BEAN_ID, bean); map.put(JOB_LOCK_SERVICE, this.jobLockService); map.put("name", trigger.getKey().toString()); jobDetail.setJobDataMap(map); scheduler.scheduleJob(jobDetail, trigger); return new QuartzTaskRegistration(scheduler, config); } catch (ParseException | org.quartz.SchedulerException e) { throw new TaskSchedulerException(e); } } }
QuartzTaskScheduler implements TaskScheduler { @Override public TaskRegistration scheduleTask(TaskConfiguration config, Object bean) throws TaskSchedulerException { if (config == null) { throw new IllegalArgumentException("config is null"); } if (bean == null) { throw new IllegalArgumentException("bean is null"); } if (this.scheduler == null) { throw new IllegalStateException("schedule is null"); } try { if (Task.class.isAssignableFrom(bean.getClass())) { } else if (Job.class.isAssignableFrom(bean.getClass())) { log.warn("[DEPRECATION] '{}' Implementing {} directly is deprecated, please implement {}", bean.getClass().getCanonicalName(), Job.class.getName(), Task.class.getName()); } else { throw new IllegalArgumentException(String.format("argument 'bean' does not implement interface " + Task.class.getName())); } CronTrigger trigger = new CronTrigger(config.getName(), config.getGroup(), config.getCron()); JobDetail jobDetail = new JobDetail(config.getName(), config.getGroup(), this.getJobClass(config)); JobDataMap map = new JobDataMap(); map.put(BEAN_ID, bean); map.put(JOB_LOCK_SERVICE, this.jobLockService); map.put("name", trigger.getKey().toString()); jobDetail.setJobDataMap(map); scheduler.scheduleJob(jobDetail, trigger); return new QuartzTaskRegistration(scheduler, config); } catch (ParseException | org.quartz.SchedulerException e) { throw new TaskSchedulerException(e); } }  }
QuartzTaskScheduler implements TaskScheduler { @Override public TaskRegistration scheduleTask(TaskConfiguration config, Object bean) throws TaskSchedulerException { if (config == null) { throw new IllegalArgumentException("config is null"); } if (bean == null) { throw new IllegalArgumentException("bean is null"); } if (this.scheduler == null) { throw new IllegalStateException("schedule is null"); } try { if (Task.class.isAssignableFrom(bean.getClass())) { } else if (Job.class.isAssignableFrom(bean.getClass())) { log.warn("[DEPRECATION] '{}' Implementing {} directly is deprecated, please implement {}", bean.getClass().getCanonicalName(), Job.class.getName(), Task.class.getName()); } else { throw new IllegalArgumentException(String.format("argument 'bean' does not implement interface " + Task.class.getName())); } CronTrigger trigger = new CronTrigger(config.getName(), config.getGroup(), config.getCron()); JobDetail jobDetail = new JobDetail(config.getName(), config.getGroup(), this.getJobClass(config)); JobDataMap map = new JobDataMap(); map.put(BEAN_ID, bean); map.put(JOB_LOCK_SERVICE, this.jobLockService); map.put("name", trigger.getKey().toString()); jobDetail.setJobDataMap(map); scheduler.scheduleJob(jobDetail, trigger); return new QuartzTaskRegistration(scheduler, config); } catch (ParseException | org.quartz.SchedulerException e) { throw new TaskSchedulerException(e); } }  @Override TaskRegistration scheduleTask(TaskConfiguration config, Object bean); void setScheduler(Scheduler scheduler); void setJobLockService(JobLockService jobLockService); }
QuartzTaskScheduler implements TaskScheduler { @Override public TaskRegistration scheduleTask(TaskConfiguration config, Object bean) throws TaskSchedulerException { if (config == null) { throw new IllegalArgumentException("config is null"); } if (bean == null) { throw new IllegalArgumentException("bean is null"); } if (this.scheduler == null) { throw new IllegalStateException("schedule is null"); } try { if (Task.class.isAssignableFrom(bean.getClass())) { } else if (Job.class.isAssignableFrom(bean.getClass())) { log.warn("[DEPRECATION] '{}' Implementing {} directly is deprecated, please implement {}", bean.getClass().getCanonicalName(), Job.class.getName(), Task.class.getName()); } else { throw new IllegalArgumentException(String.format("argument 'bean' does not implement interface " + Task.class.getName())); } CronTrigger trigger = new CronTrigger(config.getName(), config.getGroup(), config.getCron()); JobDetail jobDetail = new JobDetail(config.getName(), config.getGroup(), this.getJobClass(config)); JobDataMap map = new JobDataMap(); map.put(BEAN_ID, bean); map.put(JOB_LOCK_SERVICE, this.jobLockService); map.put("name", trigger.getKey().toString()); jobDetail.setJobDataMap(map); scheduler.scheduleJob(jobDetail, trigger); return new QuartzTaskRegistration(scheduler, config); } catch (ParseException | org.quartz.SchedulerException e) { throw new TaskSchedulerException(e); } }  @Override TaskRegistration scheduleTask(TaskConfiguration config, Object bean); void setScheduler(Scheduler scheduler); void setJobLockService(JobLockService jobLockService);  }