Example usage for org.springframework.batch.core JobParameters JobParameters

List of usage examples for org.springframework.batch.core JobParameters JobParameters

Introduction

In this page you can find the example usage for org.springframework.batch.core JobParameters JobParameters.

Prototype

public JobParameters(Map<String, JobParameter> parameters) 

Source Link

Usage

From source file:org.seedstack.spring.batch.fixtures.FlatFileBatchDemo.java

public static void main(String[] argv) throws Exception {
    String jobFile = argv[0];/*w w  w  .j av  a  2 s .co m*/

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            new String[] { "simple-job-launcher-context.xml", jobFile });

    Job job = applicationContext.getBean(Job.class);

    Map<String, JobParameter> jobParametersMap = new HashMap<>();

    jobParametersMap.put("file", new JobParameter(argv[1]));

    JobParameters jobParameters = new JobParameters(jobParametersMap);

    JobLauncher jobLauncher = applicationContext.getBean(JobLauncher.class);

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);

    printStatistics(jobExecution);
}

From source file:org.my.spring.batch.java.config.demo.Main.java

private static JobParameters parseJobParameters(String[] args) {
    Map<String, JobParameter> parameters = new HashMap<>();
    parameters.put("inputFile", new JobParameter("/var/opt/data/sample-data.csv"));
    parameters.put("k1", new JobParameter(new Date()));
    return new JobParameters(parameters);
}

From source file:com.enterra.batch.admin.sample.TrivialJobParametersIncrementer.java

public JobParameters getNext(JobParameters parameters) {
    Map<String, JobParameter> map = new HashMap<String, JobParameter>(parameters.getParameters());
    map.put("run.id", new JobParameter(UUID.randomUUID().getLeastSignificantBits()));
    return new JobParameters(map);
}

From source file:org.obiba.onyx.core.service.impl.DefaultJobExecutionServiceImpl.java

public JobExecution launchJob(Job job, Map<String, JobParameter> parameters) {

    try {/*from w w w.  ja  va  2 s . c o  m*/
        JobExecution jobExecution = jobLauncher.run(job, new JobParameters(parameters));
        return jobExecution;
    } catch (JobExecutionAlreadyRunningException e) {
        throw new RuntimeException("This job is currently running", e);
    } catch (JobInstanceAlreadyCompleteException e) {
        throw new RuntimeException("This was already run.  Maybe you need to change the input parameters?");
    } catch (JobRestartException e) {
        throw new RuntimeException("Unspecified restart exception", e);
    }
}

From source file:org.sbq.batch.scheduled.CalculateOnlineMetricsScheduledJob.java

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    JobRegistry jobRegistry = getJobRegistry();
    JobLauncher jobLauncher = getJobLauncher();
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("scheduledFireTime", new JobParameter(context.getScheduledFireTime()));
    try {/*  www.j ava 2 s. c  o m*/
        jobLauncher.run(jobRegistry.getJob("calculateOnlineMetricsJob"), new JobParameters(parameters));
    } catch (Exception e) {
        throw new JobExecutionException(e);
    }
}

From source file:org.examproject.batch.core.WorkerFacade.java

public void work() {
    LOG.debug("called.");
    try {/* w  w w.  j a  va 2  s  .c  om*/
        LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run a job begin.");

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        // create the jobparameter.
        JobParameter parameter = new JobParameter(new Date());

        Map<String, JobParameter> map = new HashMap<String, JobParameter>();
        map.put("date", parameter);

        // run the job.
        jobLauncher.run(job, new JobParameters(map));

        stopWatch.stop();
        LOG.info("execute time: " + stopWatch.getTime() + " msec");

        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< run a job end.");

    } catch (Exception e) {
        LOG.fatal("fatal: " + e.getMessage());
    }
}

From source file:prototypes.batches.chunks.jobs.BatchJobIT.java

private void launchTest(Job job, BatchStatus expectedStatus) {
    // Prepare parameters for the job
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("currentDate", new JobParameter(Calendar.getInstance().getTime()));

    // Launch the job
    try {/*from   w w w . j a v a 2  s .c o m*/
        JobParameters jobParameters = new JobParameters(parameters);
        LOGGER.info("Launch Batch chunksJob for test");

        JobExecution jobExecution = jobLauncher.run(job, jobParameters);

        Assert.assertTrue("Job execution status " + jobExecution.getStatus() + "  should be " + expectedStatus,
                expectedStatus.equals(jobExecution.getStatus()));

    } catch (JobExecutionAlreadyRunningException e) {
        LOGGER.error("Job Already Running", e);
    } catch (JobRestartException e) {
        LOGGER.error("Job Restart", e);
    } catch (JobInstanceAlreadyCompleteException e) {
        LOGGER.error("Job Already Complete", e);
    } catch (JobParametersInvalidException e) {
        LOGGER.error("Job Invalid Parameters", e);
    }
}

From source file:org.sbq.batch.scheduled.CalculateEventMetricsScheduledJob.java

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    JobRegistry jobRegistry = getJobRegistry();
    JobLauncher jobLauncher = getJobLauncher();
    long finishedAt = context.getMergedJobDataMap().getLong("finishedAt");
    Date startingFrom = new Date(finishedAt);
    Date endingAt = new Date();
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("startingFrom", new JobParameter(startingFrom));
    parameters.put("endingAt", new JobParameter(endingAt));
    try {//  w ww .  j  ava 2  s .c  o  m
        jobLauncher.run(jobRegistry.getJob("calculateEventMetricsJob"), new JobParameters(parameters));
        context.getMergedJobDataMap().putAsString("finishedAt", endingAt.getTime());
    } catch (Exception e) {
        throw new JobExecutionException(e);
    }
}

From source file:de.langmi.spring.batch.templates.inmemory.SimpleJobConfigurationTest.java

/** Launch Test. */
@Test/*from   ww  w. j  ava 2s .c om*/
public void launchJob() throws Exception {
    // Job parameters
    Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>();
    jobParametersMap.put("time", new JobParameter(System.currentTimeMillis()));
    jobParametersMap.put("input.file", new JobParameter("file:src/test/resources/input/input.txt"));
    jobParametersMap.put("output.file", new JobParameter("file:target/test-outputs/simple/output.txt"));

    // launch the job
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap));

    // assert job run status
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
}

From source file:de.langmi.spring.batch.examples.listeners.SimpleJobConfigurationTest.java

/** Launch Test. */
@Test//  w  w  w.  j  a  va 2s.  c om
public void launchJob() throws Exception {
    // Job parameters
    Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>();
    jobParametersMap.put("time", new JobParameter(System.currentTimeMillis()));
    jobParametersMap.put("output.file", new JobParameter("file:target/test-outputs/simple/output.txt"));

    // launch the job
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap));

    // assert job run status
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    // output step summaries
    for (StepExecution step : jobExecution.getStepExecutions()) {
        LOG.debug(step.getSummary());
        assertTrue("Read Count mismatch.", step.getReadCount() == TestDataFactoryBean.COUNT);
    }
}