/** * Add the given key-value pair to the Trigger's {@link JobDataMap}. * * @return the updated TriggerBuilder * @see Trigger#getJobDataMap() */ public TriggerBuilder<T> usingJobData(String dataKey, Integer value) { jobDataMap.put(dataKey, value); return this; }
/** * Add the given key-value pair to the Trigger's {@link JobDataMap}. * * @return the updated TriggerBuilder * @see Trigger#getJobDataMap() */ public TriggerBuilder<T> usingJobData(String dataKey, Float value) { jobDataMap.put(dataKey, value); return this; }
/** * Add the given key-value pair to the Trigger's {@link JobDataMap}. * * @return the updated TriggerBuilder * @see Trigger#getJobDataMap() */ public TriggerBuilder<T> usingJobData(String dataKey, String value) { jobDataMap.put(dataKey, value); return this; }
/** * Add the given key-value pair to the Trigger's {@link JobDataMap}. * * @return the updated TriggerBuilder * @see Trigger#getJobDataMap() */ public TriggerBuilder<T> usingJobData(String dataKey, Boolean value) { jobDataMap.put(dataKey, value); return this; }
/** * Add the given key-value pair to the JobDetail's {@link JobDataMap}. * * @return the updated JobBuilder * @see JobDetail#getJobDataMap() */ public JobBuilder usingJobData(String dataKey, Long value) { jobDataMap.put(dataKey, value); return this; }
/** * Add the given key-value pair to the JobDetail's {@link JobDataMap}. * * @return the updated JobBuilder * @see JobDetail#getJobDataMap() */ public JobBuilder usingJobData(String dataKey, Double value) { jobDataMap.put(dataKey, value); return this; }
/** * Add the given key-value pair to the Trigger's {@link JobDataMap}. * * @return the updated TriggerBuilder * @see Trigger#getJobDataMap() */ public TriggerBuilder<T> usingJobData(String dataKey, Double value) { jobDataMap.put(dataKey, value); return this; }
/** * Add the given key-value pair to the JobDetail's {@link JobDataMap}. * * @return the updated JobBuilder * @see JobDetail#getJobDataMap() */ public JobBuilder usingJobData(String dataKey, Double value) { jobDataMap.put(dataKey, value); return this; }
private JobDetail createJobDetail(final String jobClass) { JobDetail result = JobBuilder.newJob(LiteJob.class).withIdentity(liteJobConfig.getJobName()).build(); result.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade); Optional<ElasticJob> elasticJobInstance = createElasticJobInstance(); if (elasticJobInstance.isPresent()) { result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJobInstance.get()); } else if (!jobClass.equals(ScriptJob.class.getCanonicalName())) { try { result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, Class.forName(jobClass).newInstance()); } catch (final ReflectiveOperationException ex) { throw new JobConfigurationException("Elastic-Job: Job class '%s' can not initialize.", jobClass); } } return result; }
public static JobDataMap newJobDataMap(Map<String, Object> map) { JobDataMap jobDataMap = new JobDataMap(); if(map != null) { for (final Iterator<String> pos = map.keySet().iterator(); pos.hasNext();) { String key = pos.next(); jobDataMap.put(key, map.get(key)); } } return jobDataMap; }
protected JobDataMap createJobDataMap(String parameters) { JobDataMap map = new JobDataMap(); if (!StringUtils.isEmpty(parameters)) { JSONArray jsonArray = JSON.parseArray(parameters); for (int i = 0; i < jsonArray.size(); i++) { JSONObject o = jsonArray.getJSONObject(i); map.put(o.getString("key"), o.get("value")); } } return map; }
@Override public void afterPropertiesSet() { Assert.notNull(this.jobClass, "Property 'jobClass' is required"); if (this.name == null) { this.name = this.beanName; } if (this.group == null) { this.group = Scheduler.DEFAULT_GROUP; } if (this.applicationContextJobDataKey != null) { if (this.applicationContext == null) { throw new IllegalStateException( "JobDetailBean needs to be set up in an ApplicationContext " + "to be able to handle an 'applicationContextJobDataKey'"); } getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext); } JobDetailImpl jdi = new JobDetailImpl(); jdi.setName(this.name != null ? this.name : toString()); jdi.setGroup(this.group); jdi.setJobClass(this.jobClass); jdi.setJobDataMap(this.jobDataMap); jdi.setDurability(this.durability); jdi.setRequestsRecovery(this.requestsRecovery); jdi.setDescription(this.description); this.jobDetail = jdi; }
@Override @SuppressWarnings("unchecked") public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException { prepare(); // Use specific name if given, else fall back to bean name. String name = (this.name != null ? this.name : this.beanName); // Consider the concurrent flag to choose between stateful and stateless job. Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class); // Build JobDetail instance. JobDetailImpl jdi = new JobDetailImpl(); jdi.setName(name != null ? name : toString()); jdi.setGroup(this.group); jdi.setJobClass((Class) jobClass); jdi.setDurability(true); jdi.getJobDataMap().put("methodInvoker", this); this.jobDetail = jdi; postProcessJobDetail(this.jobDetail); }
this.jobDataMap.put("jobDetail", this.jobDetail);
@Override public void afterPropertiesSet() { if (this.name == null) { this.name = this.beanName; } if (this.group == null) { this.group = Scheduler.DEFAULT_GROUP; } if (this.jobDetail != null) { this.jobDataMap.put("jobDetail", this.jobDetail); } if (this.startDelay > 0 || this.startTime == null) { this.startTime = new Date(System.currentTimeMillis() + this.startDelay); } SimpleTriggerImpl sti = new SimpleTriggerImpl(); sti.setName(this.name != null ? this.name : toString()); sti.setGroup(this.group); if (this.jobDetail != null) { sti.setJobKey(this.jobDetail.getKey()); } sti.setJobDataMap(this.jobDataMap); sti.setStartTime(this.startTime); sti.setRepeatInterval(this.repeatInterval); sti.setRepeatCount(this.repeatCount); sti.setPriority(this.priority); sti.setMisfireInstruction(this.misfireInstruction); sti.setDescription(this.description); this.simpleTrigger = sti; }
@Test public void schedulerWithSpringBeanJobFactory() throws Exception { Assume.group(TestGroup.PERFORMANCE); DummyJob.param = 0; DummyJob.count = 0; JobDetailImpl jobDetail = new JobDetailImpl(); jobDetail.setDurability(true); jobDetail.setJobClass(DummyJob.class); jobDetail.setName("myJob"); jobDetail.getJobDataMap().put("param", "10"); jobDetail.getJobDataMap().put("ignoredParam", "10"); SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean(); trigger.setName("myTrigger"); trigger.setJobDetail(jobDetail); trigger.setStartDelay(1); trigger.setRepeatInterval(500); trigger.setRepeatCount(1); trigger.afterPropertiesSet(); SchedulerFactoryBean bean = new SchedulerFactoryBean(); bean.setJobFactory(new SpringBeanJobFactory()); bean.setTriggers(trigger.getObject()); bean.setJobDetails(jobDetail); bean.afterPropertiesSet(); bean.start(); Thread.sleep(500); assertEquals(10, DummyJob.param); assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0); bean.destroy(); }
@Test public void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception { Assume.group(TestGroup.PERFORMANCE); DummyJob.param = 0; DummyJob.count = 0; JobDetailImpl jobDetail = new JobDetailImpl(); jobDetail.setDurability(true); jobDetail.setJobClass(DummyJob.class); jobDetail.setName("myJob"); jobDetail.getJobDataMap().put("para", "10"); jobDetail.getJobDataMap().put("ignoredParam", "10"); SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean(); trigger.setName("myTrigger"); trigger.setJobDetail(jobDetail); trigger.setStartDelay(1); trigger.setRepeatInterval(500); trigger.setRepeatCount(1); trigger.afterPropertiesSet(); SchedulerFactoryBean bean = new SchedulerFactoryBean(); SpringBeanJobFactory jobFactory = new SpringBeanJobFactory(); jobFactory.setIgnoredUnknownProperties("ignoredParam"); bean.setJobFactory(jobFactory); bean.setTriggers(trigger.getObject()); bean.setJobDetails(jobDetail); bean.afterPropertiesSet(); Thread.sleep(500); assertEquals(0, DummyJob.param); assertTrue(DummyJob.count == 0); bean.destroy(); }
@Test public void schedulerWithQuartzJobBean() throws Exception { Assume.group(TestGroup.PERFORMANCE); DummyJob.param = 0; DummyJob.count = 0; JobDetailImpl jobDetail = new JobDetailImpl(); jobDetail.setDurability(true); jobDetail.setJobClass(DummyJobBean.class); jobDetail.setName("myJob"); jobDetail.getJobDataMap().put("param", "10"); SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean(); trigger.setName("myTrigger"); trigger.setJobDetail(jobDetail); trigger.setStartDelay(1); trigger.setRepeatInterval(500); trigger.setRepeatCount(1); trigger.afterPropertiesSet(); SchedulerFactoryBean bean = new SchedulerFactoryBean(); bean.setTriggers(trigger.getObject()); bean.setJobDetails(jobDetail); bean.afterPropertiesSet(); bean.start(); Thread.sleep(500); assertEquals(10, DummyJobBean.param); assertTrue(DummyJobBean.count > 0); bean.destroy(); }
@Test public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception { Assume.group(TestGroup.PERFORMANCE); DummyJobBean.param = 0; DummyJobBean.count = 0; JobDetailImpl jobDetail = new JobDetailImpl(); jobDetail.setDurability(true); jobDetail.setJobClass(DummyJobBean.class); jobDetail.setName("myJob"); jobDetail.getJobDataMap().put("param", "10"); SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean(); trigger.setName("myTrigger"); trigger.setJobDetail(jobDetail); trigger.setStartDelay(1); trigger.setRepeatInterval(500); trigger.setRepeatCount(1); trigger.afterPropertiesSet(); SchedulerFactoryBean bean = new SchedulerFactoryBean(); bean.setJobFactory(new SpringBeanJobFactory()); bean.setTriggers(trigger.getObject()); bean.setJobDetails(jobDetail); bean.afterPropertiesSet(); bean.start(); Thread.sleep(500); assertEquals(10, DummyJobBean.param); assertTrue(DummyJobBean.count > 0); bean.destroy(); }