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

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

Introduction

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

Prototype

public ReferenceJobFactory(Job job) 

Source Link

Usage

From source file:com.iisigroup.cap.batch.handler.BatchHandler.java

private void jobRegistryLoad(BatchJob job) {
    org.springframework.core.io.Resource resource = batchSrv.getJobResource(job);
    ApplicationContext context = createApplicationContextFactory(CapAppContext.getApplicationContext(),
            resource);// w  w  w  .  j av a 2  s .  c o m
    Job j = context.getBean(job.getJobId(), Job.class);
    jobRegistry.unregister(j.getName());
    try {
        jobRegistry.register(new ReferenceJobFactory(j));
    } catch (DuplicateJobException e) {
        e.getMessage();
    }
}

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

/**
 * Registers the specified {@link Job} defined in the specified {@link ConfigurableApplicationContext}.
 * <br>/*from www. j  a v a 2 s .  co m*/
 * 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));
    }
}

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 v a 2  s .co  m*/
 */
@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;
}

From source file:org.springframework.batch.sample.JobOperatorFunctionalTests.java

@Before
public void setUp() throws Exception {
    if (!jobRegistry.getJobNames().contains(job.getName())) {
        jobRegistry.register(new ReferenceJobFactory(job));
    }//from  w ww  .  ja v  a 2  s . c  o m
}

From source file:org.springframework.data.hadoop.admin.util.HadoopWorkflowUtils.java

/**
 * create and register Spring Batch job/*from   w  ww .j a v a 2 s . c  o  m*/
 * 
 * @param context root application context
 * @param artifacts workflow artifacts which include workflow descriptor and class loader information.
 * @throws Exception
 */
public static void createAndRegisterSpringBatchJob(ApplicationContext context,
        final WorkflowArtifacts artifacts) throws SpringHadoopAdminWorkflowException {
    if (context == null) {
        logger.warn("root applicaton context is null");
        throw new SpringHadoopAdminWorkflowException("root applicaton context is null");
    }
    String workflowDescriptor = getWorkflowDescriptor(artifacts);
    logger.info("create spring batch job:" + workflowDescriptor + ", classloader:"
            + artifacts.getWorkflowClassLoader());

    final FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext();
    ctx.setClassLoader(artifacts.getWorkflowClassLoader());
    ctx.setConfigLocation(HadoopWorkflowUtils.fileURLPrefix + workflowDescriptor);

    try {
        SimpleJob job = new SimpleJob(generateSpringBatchJobName(artifacts));
        TaskletStep step = new TaskletStep(springHadoopTaskName);
        SimpleSpringHadoopTasklet tasklet = new SimpleSpringHadoopTasklet();
        tasklet.setContext(ctx);
        step.setTasklet(tasklet);
        JobRepository jobRepository = context.getBean(JobRepository.class);
        DataSourceTransactionManager transactionManager = context.getBean("transactionManager",
                DataSourceTransactionManager.class);
        step.setTransactionManager(transactionManager);
        step.setJobRepository(jobRepository);
        step.afterPropertiesSet();
        job.addStep(step);
        JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class);
        job.setJobRepository(jobRepository);
        job.afterPropertiesSet();
        JobFactory jobFactory = new ReferenceJobFactory(job);
        jobRegistry.register(jobFactory);
    } catch (Exception e) {
        logger.warn("create and register Spring Batch Job failed");
        throw new SpringHadoopAdminWorkflowException("create and register Spring Batch Job failed", e);
    }
}