@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); }
@Test(expected = IllegalArgumentException.class) @SuppressWarnings({ "unchecked", "rawtypes" }) public void jobDetailWithRunnableInsteadOfJob() { JobDetailImpl jobDetail = new JobDetailImpl(); jobDetail.setJobClass((Class) DummyRunnable.class); }
@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; }
@VisibleForTesting static JobDetailImpl createJobDetail(RollupTask task, KairosDatastore dataStore, String hostName, FilterEventBus eventBus, RollupTaskStatusStore statusStore) { JobDetailImpl jobDetail = new JobDetailImpl(); jobDetail.setJobClass(RollUpJob.class); jobDetail.setKey(getJobKey(task.getId())); JobDataMap map = new JobDataMap(); map.put("task", task); map.put("datastore", dataStore); map.put("hostName", hostName); map.put("eventBus", eventBus); map.put("statusStore", statusStore); jobDetail.setJobDataMap(map); return jobDetail; }
/** * @param cData * @return JobDetail */ public static JobDetail newJobDetail(CompositeData cData) throws ClassNotFoundException { JobDetailImpl jobDetail = new JobDetailImpl(); int i = 0; jobDetail.setName((String) cData.get(ITEM_NAMES[i++])); jobDetail.setGroup((String) cData.get(ITEM_NAMES[i++])); jobDetail.setDescription((String) cData.get(ITEM_NAMES[i++])); Class<?> jobClass = Class.forName((String) cData.get(ITEM_NAMES[i++])); @SuppressWarnings("unchecked") Class<? extends Job> jobClassTyped = (Class<? extends Job>)jobClass; jobDetail.setJobClass(jobClassTyped); jobDetail.setJobDataMap(JobDataMapSupport.newJobDataMap((TabularData) cData.get(ITEM_NAMES[i++]))); jobDetail.setDurability((Boolean) cData.get(ITEM_NAMES[i++])); jobDetail.setRequestsRecovery((Boolean) cData.get(ITEM_NAMES[i++])); return jobDetail; }
throws ClassNotFoundException JobDetailImpl jobDetail = new JobDetailImpl();
@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); }
/** * Test method for * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. */ @Test public void testExecuteWithJobName() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO"); JobExecutionContext context = createContext(jobDetail); details.executeInternal(context); assertEquals(2, list.size()); assertEquals("FOO", list.get(0)); }
/** * Test method for * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. */ @Test public void testExecuteWithJobNameAndParameters() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO"); jobDetail.getJobDataMap().put("foo", "bar"); JobExecutionContext context = createContext(jobDetail); details.executeInternal(context); assertEquals(2, list.size()); assertEquals("FOO", list.get(0)); JobParameters parameters = (JobParameters) list.get(1); assertEquals(1, parameters.getParameters().size()); }
/** * Test method for * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. */ @Test public void testExecuteWithSomeJobParameters() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put("foo", "bar"); JobExecutionContext context = createContext(jobDetail); details.executeInternal(context); assertEquals(2, list.size()); JobParameters parameters = (JobParameters) list.get(1); assertEquals(1, parameters.getParameters().size()); }
/** * Test method for * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. */ @Test public void testExecuteWithJobNameAndComplexParameters() { JobDetail jobDetail = new JobDetailImpl(); jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO"); jobDetail.getJobDataMap().put("foo", this); JobExecutionContext context = createContext(jobDetail); details.executeInternal(context); assertEquals(2, list.size()); assertEquals("FOO", list.get(0)); JobParameters parameters = (JobParameters) list.get(1); // Silently ignore parameters that are not simple types assertEquals(0, parameters.getParameters().size()); }
/** * Test method for * {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}. */ @Test public void testExecuteWithNoJobParameters() { JobDetail jobDetail = new JobDetailImpl(); JobExecutionContext context = createContext(jobDetail); details.executeInternal(context); assertEquals(2, list.size()); JobParameters parameters = (JobParameters) list.get(1); assertEquals(0, parameters.getParameters().size()); }
/** * Produce the <code>JobDetail</code> instance defined by this * <code>JobBuilder</code>. * * @return the defined JobDetail. */ public JobDetail build() { JobDetailImpl job = new JobDetailImpl(); job.setJobClass(jobClass); job.setDescription(description); if(key == null) key = new JobKey(Key.createUniqueName(null), null); job.setKey(key); job.setDurability(durability); job.setRequestsRecovery(shouldRecover); if(!jobDataMap.isEmpty()) job.setJobDataMap(jobDataMap); return job; }
/** * Produce the <code>JobDetail</code> instance defined by this * <code>JobBuilder</code>. * * @return the defined JobDetail. */ public JobDetail build() { JobDetailImpl job = new JobDetailImpl(); job.setJobClass(jobClass); job.setDescription(description); if(key == null) key = new JobKey(Key.createUniqueName(null), null); job.setKey(key); job.setDurability(durability); job.setRequestsRecovery(shouldRecover); if(!jobDataMap.isEmpty()) job.setJobDataMap(jobDataMap); return job; }
@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(); }
@Test public void schedulerWithTaskExecutor() throws Exception { Assume.group(TestGroup.PERFORMANCE); CountingTaskExecutor taskExecutor = new CountingTaskExecutor(); DummyJob.count = 0; JobDetailImpl jobDetail = new JobDetailImpl(); jobDetail.setDurability(true); jobDetail.setJobClass(DummyJob.class); jobDetail.setName("myJob"); 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.setTaskExecutor(taskExecutor); bean.setTriggers(trigger.getObject()); bean.setJobDetails(jobDetail); bean.afterPropertiesSet(); bean.start(); Thread.sleep(500); assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0); assertEquals(DummyJob.count, taskExecutor.count); bean.destroy(); }