Example usage for org.springframework.batch.core.configuration.support GroupAwareJob GroupAwareJob

List of usage examples for org.springframework.batch.core.configuration.support GroupAwareJob GroupAwareJob

Introduction

In this page you can find the example usage for org.springframework.batch.core.configuration.support GroupAwareJob GroupAwareJob.

Prototype

public GroupAwareJob(@Nullable String groupName, Job delegate) 

Source Link

Document

Create a new Job with the given group name and delegate.

Usage

From source file:org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor.java

/**
 * 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)/*from   w ww. j a  va 2  s  .  com*/
 */
@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();
            if (logger.isDebugEnabled()) {
                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;
}