ReferenceJobFactory jobFactory = new ReferenceJobFactory(job); String name = jobFactory.getJobName(); if (logger.isDebugEnabled()) { logger.debug("Registering job: " + name);
/** * Registers the specified {@link Job} defined in the specified {@link ConfigurableApplicationContext}. * <br> * Makes sure to update the {@link StepRegistry} if it is available. * * @param context the context in which the job is defined * @param job the job to register * @throws DuplicateJobException if that job is already registered */ private void doRegister(ConfigurableApplicationContext context, Job job) throws DuplicateJobException { final JobFactory jobFactory = new ReferenceJobFactory(job); jobRegistry.register(jobFactory); if (stepRegistry != null) { if (!(job instanceof StepLocator)) { throw new UnsupportedOperationException("Cannot locate steps from a Job that is not a StepLocator: job=" + job.getName() + " does not implement StepLocator"); } stepRegistry.register(job.getName(), getSteps((StepLocator) job, context)); } }
@Before public void setUp() throws Exception { if (!jobRegistry.getJobNames().contains(job.getName())) { jobRegistry.register(new ReferenceJobFactory(job)); } }
@Test public void testGroupName() throws Exception { ReferenceJobFactory factory = new ReferenceJobFactory(new JobSupport("foo")); assertEquals("foo", factory.getJobName()); }
/** * Test method for {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJobNames()}. * @throws Exception */ public void testGetJobConfigurations() throws Exception { JobFactory jobFactory = new ReferenceJobFactory(new JobSupport("foo")); registry.register(jobFactory); registry.register(new ReferenceJobFactory(new JobSupport("bar"))); Collection<String> configurations = registry.getJobNames(); assertEquals(2, configurations.size()); assertTrue(configurations.contains(jobFactory.getJobName())); }
/** * If the bean is an instance of {@link Job} then register it. * @throws FatalBeanException if there is a {@link DuplicateJobException}. * * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, * java.lang.String) */ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof Job) { Job job = (Job) bean; try { String groupName = this.groupName; if (beanFactory != null && beanFactory.containsBean(beanName)) { groupName = getGroupName(beanFactory.getBeanDefinition(beanName), job); } job = groupName==null ? job : new GroupAwareJob(groupName, job); ReferenceJobFactory jobFactory = new ReferenceJobFactory(job); String name = jobFactory.getJobName(); logger.debug("Registering job: " + name); jobRegistry.register(jobFactory); jobNames.add(name); } catch (DuplicateJobException e) { throw new FatalBeanException("Cannot register job configuration", e); } return job; } return bean; }
/** * Test method for {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJob(java.lang.String)}. */ public void testReplaceDuplicateConfiguration() throws Exception { registry.register(new ReferenceJobFactory(new JobSupport("foo"))); try { registry.register(new ReferenceJobFactory(new JobSupport("foo"))); fail("Expected DuplicateJobConfigurationException"); } catch (DuplicateJobException e) { // unexpected: even if the job is different we want a DuplicateJobException assertTrue(e.getMessage().indexOf("foo")>=0); } }
ReferenceJobFactory jobFactory = new ReferenceJobFactory(job); String name = jobFactory.getJobName(); if (logger.isDebugEnabled()) { logger.debug("Registering job: " + name);
/** * Test method for {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJob(java.lang.String)}. */ public void testRealDuplicateConfiguration() throws Exception { JobFactory jobFactory = new ReferenceJobFactory(new JobSupport("foo")); registry.register(jobFactory); try { registry.register(jobFactory); fail("Unexpected DuplicateJobConfigurationException"); } catch (DuplicateJobException e) { // expected assertTrue(e.getMessage().indexOf("foo")>=0); } }
ReferenceJobFactory jobFactory = new ReferenceJobFactory(job); String name = jobFactory.getJobName(); if (logger.isDebugEnabled()) { logger.debug("Registering job: " + name);
/** * Test method for {@link org.springframework.batch.core.configuration.support.MapJobRegistry#unregister(String)}. * @throws Exception */ public void testUnregister() throws Exception { registry.register(new ReferenceJobFactory(new JobSupport("foo"))); assertNotNull(registry.getJob("foo")); registry.unregister("foo"); try { assertNull(registry.getJob("foo")); fail("Expected NoSuchJobConfigurationException"); } catch (NoSuchJobException e) { // expected assertTrue(e.getMessage().indexOf("foo")>=0); } }
/** * If the bean is an instance of {@link Job} then register it. * @throws FatalBeanException if there is a {@link DuplicateJobException}. * * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, * java.lang.String) */ @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof Job) { Job job = (Job) bean; try { String groupName = this.groupName; if (beanFactory != null && beanFactory.containsBean(beanName)) { groupName = getGroupName(beanFactory.getBeanDefinition(beanName), job); } job = groupName==null ? job : new GroupAwareJob(groupName, job); ReferenceJobFactory jobFactory = new ReferenceJobFactory(job); String name = jobFactory.getJobName(); logger.debug("Registering job: " + name); jobRegistry.register(jobFactory); jobNames.add(name); } catch (DuplicateJobException e) { throw new FatalBeanException("Cannot register job configuration", e); } return job; } return bean; }
JobFactory jobFactory = new ReferenceJobFactory(job); jobRegistry.register(jobFactory); jobsRegistered.add(jobName);
/** * Registers the specified {@link Job} defined in the specified {@link ConfigurableApplicationContext}. * <br> * Makes sure to update the {@link StepRegistry} if it is available. * * @param context the context in which the job is defined * @param job the job to register * @throws DuplicateJobException if that job is already registered */ private void doRegister(ConfigurableApplicationContext context, Job job) throws DuplicateJobException { final JobFactory jobFactory = new ReferenceJobFactory(job); jobRegistry.register(jobFactory); if (stepRegistry != null) { if (!(job instanceof StepLocator)) { throw new UnsupportedOperationException("Cannot locate steps from a Job that is not a StepLocator: job=" + job.getName() + " does not implement StepLocator"); } stepRegistry.register(job.getName(), getSteps((StepLocator) job, context)); } }
/** * Registers the specified {@link Job} defined in the specified {@link ConfigurableApplicationContext}. * <br> * Makes sure to update the {@link StepRegistry} if it is available. * * @param context the context in which the job is defined * @param job the job to register * @throws DuplicateJobException if that job is already registered */ private void doRegister(ConfigurableApplicationContext context, Job job) throws DuplicateJobException { final JobFactory jobFactory = new ReferenceJobFactory(job); jobRegistry.register(jobFactory); if (stepRegistry != null) { if (!(job instanceof StepLocator)) { throw new UnsupportedOperationException("Cannot locate steps from a Job that is not a StepLocator: job=" + job.getName() + " does not implement StepLocator"); } stepRegistry.register(job.getName(), getSteps((StepLocator) job, context)); } }
/** * Registers the specified {@link Job} defined in the specified {@link ConfigurableApplicationContext}. * <br> * Makes sure to update the {@link StepRegistry} if it is available. * * @param context the context in which the job is defined * @param job the job to register * @throws DuplicateJobException if that job is already registered */ private void doRegister(ConfigurableApplicationContext context, Job job) throws DuplicateJobException { final JobFactory jobFactory = new ReferenceJobFactory(job); jobRegistry.register(jobFactory); if (stepRegistry != null) { if (!(job instanceof StepLocator)) { throw new UnsupportedOperationException("Cannot locate steps from a Job that is not a StepLocator: job=" + job.getName() + " does not implement StepLocator"); } stepRegistry.register(job.getName(), getSteps((StepLocator) job, context)); } }