org.springframework.batch.core.configuration.support
Class JobRegistryBeanPostProcessor

java.lang.Object
  extended by org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor
All Implemented Interfaces:
BeanFactoryAware, BeanPostProcessor, DisposableBean, InitializingBean

public class JobRegistryBeanPostProcessor
extends Object
implements BeanPostProcessor, BeanFactoryAware, InitializingBean, DisposableBean

A BeanPostProcessor that registers Job beans with a JobRegistry. Include a bean of this type along with your job configuration, and use the same JobRegistry as a JobLocator when you need to locate a Job to launch.

Author:
Dave Syer

Constructor Summary
JobRegistryBeanPostProcessor()
           
 
Method Summary
 void afterPropertiesSet()
          Make sure the registry is set before use.
 void destroy()
          De-register all the Job instances that were regsistered by this post processor.
protected  String getGroupName(BeanDefinition beanDefinition, Job job)
          Determine a group name for the job to be registered.
 Object postProcessAfterInitialization(Object bean, String beanName)
          If the bean is an instance of Job then register it.
 Object postProcessBeforeInitialization(Object bean, String beanName)
          Do nothing.
 void setBeanFactory(BeanFactory beanFactory)
           
 void setGroupName(String groupName)
          The group name for jobs registered by this component.
 void setJobRegistry(JobRegistry jobRegistry)
          Injection setter for JobRegistry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JobRegistryBeanPostProcessor

public JobRegistryBeanPostProcessor()
Method Detail

setGroupName

public void setGroupName(String groupName)
The group name for jobs registered by this component. Optional (defaults to null, which means that jobs are registered with their bean names). Useful where there is a hierarchy of application contexts all contributing to the same JobRegistry: child contexts can then define an instance with a unique group name to avoid clashes between job names.

Parameters:
groupName - the groupName to set

setJobRegistry

public void setJobRegistry(JobRegistry jobRegistry)
Injection setter for JobRegistry.

Parameters:
jobRegistry - the jobConfigurationRegistry to set

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
                    throws BeansException
Specified by:
setBeanFactory in interface BeanFactoryAware
Throws:
BeansException

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Make sure the registry is set before use.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception
See Also:
InitializingBean.afterPropertiesSet()

destroy

public void destroy()
             throws Exception
De-register all the Job instances that were regsistered by this post processor.

Specified by:
destroy in interface DisposableBean
Throws:
Exception
See Also:
DisposableBean.destroy()

postProcessAfterInitialization

public Object postProcessAfterInitialization(Object bean,
                                             String beanName)
                                      throws BeansException
If the bean is an instance of Job then register it.

Specified by:
postProcessAfterInitialization in interface BeanPostProcessor
Throws:
FatalBeanException - if there is a DuplicateJobException.
BeansException
See Also:
BeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)

getGroupName

protected String getGroupName(BeanDefinition beanDefinition,
                              Job job)
Determine a group name for the job to be registered. Default implementation just returns the groupName configured. Provides an extension point for specialised subclasses.

Parameters:
beanDefinition - the bean definition for the job
job - the job
Returns:
a group name for the job (or null if not needed)

postProcessBeforeInitialization

public Object postProcessBeforeInitialization(Object bean,
                                              String beanName)
                                       throws BeansException
Do nothing.

Specified by:
postProcessBeforeInitialization in interface BeanPostProcessor
Throws:
BeansException
See Also:
BeanPostProcessor.postProcessBeforeInitialization(java.lang.Object, java.lang.String)


Copyright © 2013 SpringSource. All Rights Reserved.