Example usage for org.springframework.batch.core StepExecution getReadCount

List of usage examples for org.springframework.batch.core StepExecution getReadCount

Introduction

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

Prototype

public int getReadCount() 

Source Link

Document

Returns the current number of items read for this execution

Usage

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

/** Launch Test. */
@Test/*from  w  w w  .  j  av  a  2s .  c o  m*/
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/file-output/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);
    }
}

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

/** Launch Test. */
@Test//from   w  w w . ja  v  a2s  . co  m
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);
    }
}

From source file:admin.jmx.SimpleStepExecutionMetrics.java

public int getLatestReadCount() {
    StepExecution stepExecution = getLatestStepExecution(stepName);
    return stepExecution == null ? 0 : stepExecution.getReadCount();
}

From source file:org.jasig.ssp.util.importer.job.csv.RawItemCsvWriter.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    logger.info("End Raw Write Step for " + stepExecution.getExecutionContext().getString("fileName")
            + " lines read: " + stepExecution.getReadCount() + " lines skipped: "
            + stepExecution.getReadSkipCount());
    logger.info(stepExecution.getSummary());
    return ExitStatus.COMPLETED;
}

From source file:org.jasig.ssp.util.importer.job.csv.RawItemCsvReader.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    logger.info("End Raw Read Step for " + itemResource.getFilename() + " lines read: "
            + stepExecution.getReadCount() + " lines skipped: " + stepExecution.getReadSkipCount());
    return ExitStatus.COMPLETED;
}

From source file:com.javaetmoi.core.batch.listener.LogStepListener.java

@Override
public ExitStatus afterStep(StepExecution pStepExecution) {
    if (LOG.isInfoEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Step ").append(pStepExecution.getStepName());
        msg.append(" - Read count: ").append(pStepExecution.getReadCount());
        msg.append(" - Write count: ").append(pStepExecution.getWriteCount());
        msg.append(" - Commit count: ").append(pStepExecution.getCommitCount());
        LOG.info(msg.toString());//www .j a v  a  2 s  .c o m
    }
    return super.afterStep(pStepExecution);
}

From source file:de.codecentric.batch.listener.ProtocolListener.java

public void afterJob(JobExecution jobExecution) {
    StringBuilder protocol = new StringBuilder();
    protocol.append("\n");
    protocol.append(createFilledLine('*'));
    protocol.append(createFilledLine('-'));
    protocol.append("Protocol for " + jobExecution.getJobInstance().getJobName() + " \n");
    protocol.append("  Started:      " + jobExecution.getStartTime() + "\n");
    protocol.append("  Finished:     " + jobExecution.getEndTime() + "\n");
    protocol.append("  Exit-Code:    " + jobExecution.getExitStatus().getExitCode() + "\n");
    protocol.append("  Exit-Descr:   " + jobExecution.getExitStatus().getExitDescription() + "\n");
    protocol.append("  Status:       " + jobExecution.getStatus() + "\n");
    protocol.append("  Content of Job-ExecutionContext:\n");
    for (Entry<String, Object> entry : jobExecution.getExecutionContext().entrySet()) {
        protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
    }// w ww .j  a  v a  2  s .  co  m
    protocol.append("  Job-Parameter: \n");
    JobParameters jp = jobExecution.getJobParameters();
    for (Iterator<Entry<String, JobParameter>> iter = jp.getParameters().entrySet().iterator(); iter
            .hasNext();) {
        Entry<String, JobParameter> entry = iter.next();
        protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
    }
    protocol.append(createFilledLine('-'));
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        protocol.append("Step " + stepExecution.getStepName() + " \n");
        protocol.append("  ReadCount:    " + stepExecution.getReadCount() + "\n");
        protocol.append("  WriteCount:   " + stepExecution.getWriteCount() + "\n");
        protocol.append("  Commits:      " + stepExecution.getCommitCount() + "\n");
        protocol.append("  SkipCount:    " + stepExecution.getSkipCount() + "\n");
        protocol.append("  Rollbacks:    " + stepExecution.getRollbackCount() + "\n");
        protocol.append("  Filter:       " + stepExecution.getFilterCount() + "\n");
        protocol.append("  Content of Step-ExecutionContext:\n");
        for (Entry<String, Object> entry : stepExecution.getExecutionContext().entrySet()) {
            protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
        }
        protocol.append(createFilledLine('-'));
    }
    protocol.append(createFilledLine('*'));
    LOGGER.info(protocol.toString());
}

From source file:com.example.listener.CustomJobExecutionListener.java

public void afterJob(org.springframework.batch.core.JobExecution jobExecution) {
    StringBuilder protocol = new StringBuilder();
    protocol.append("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
    protocol.append("Protocol for " + jobExecution.getJobInstance().getJobName() + " \n");
    protocol.append("  Started     : " + jobExecution.getStartTime() + "\n");
    protocol.append("  Finished    : " + jobExecution.getEndTime() + "\n");
    protocol.append("  Exit-Code   : " + jobExecution.getExitStatus().getExitCode() + "\n");
    protocol.append("  Exit-Descr. : " + jobExecution.getExitStatus().getExitDescription() + "\n");
    protocol.append("  Status      : " + jobExecution.getStatus() + "\n");
    protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");

    protocol.append("Job-Parameter: \n");
    JobParameters jp = jobExecution.getJobParameters();
    for (Iterator<Map.Entry<String, JobParameter>> iter = jp.getParameters().entrySet().iterator(); iter
            .hasNext();) {/*from  w  w  w . ja va 2s  .  c  o  m*/
        Map.Entry<String, JobParameter> entry = iter.next();
        protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
    }
    protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");

    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        protocol.append("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
        protocol.append("Step " + stepExecution.getStepName() + " \n");
        protocol.append("ReadCount " + stepExecution.getReadCount() + " \n");
        protocol.append("WriteCount: " + stepExecution.getWriteCount() + "\n");
        protocol.append("Commits: " + stepExecution.getCommitCount() + "\n");
        protocol.append("SkipCount: " + stepExecution.getSkipCount() + "\n");
        protocol.append("Rollbacks: " + stepExecution.getRollbackCount() + "\n");
        protocol.append("Filter: " + stepExecution.getFilterCount() + "\n");
        protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
    }
    log.info("{}", protocol.toString());
}

From source file:admin.history.StepExecutionHistory.java

public void append(StepExecution stepExecution) {
    if (stepExecution.getEndTime() == null) {
        // ignore unfinished executions
        return;/*from  w  w  w. ja  v  a  2 s.com*/
    }
    Date startTime = stepExecution.getStartTime();
    Date endTime = stepExecution.getEndTime();
    long time = endTime.getTime() - startTime.getTime();
    duration.append(time);
    if (stepExecution.getReadCount() > 0) {
        durationPerRead.append(time / stepExecution.getReadCount());
    }
    count++;
    commitCount.append(stepExecution.getCommitCount());
    rollbackCount.append(stepExecution.getRollbackCount());
    readCount.append(stepExecution.getReadCount());
    writeCount.append(stepExecution.getWriteCount());
    filterCount.append(stepExecution.getFilterCount());
    readSkipCount.append(stepExecution.getReadSkipCount());
    writeSkipCount.append(stepExecution.getWriteSkipCount());
    processSkipCount.append(stepExecution.getProcessSkipCount());
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionDetailsRepresentation.java

/**
 * Constructor that substitutes in null for the execution id.
 *
 * @param stepExecution the step execution
 *//*from  w  w  w.  j  a  v  a  2  s.  co m*/
public StepExecutionDetailsRepresentation(StepExecution stepExecution) {
    Assert.notNull(stepExecution.getId(),
            "The entity Id must be provided to re-hydrate an existing StepExecution");
    this.stepName = stepExecution.getStepName();
    this.commitCount = stepExecution.getCommitCount();
    this.endTime = stepExecution.getEndTime() == null ? "" : timeFormat.format(stepExecution.getEndTime());
    this.executionContext = stepExecution.getExecutionContext();

    this.statusExitCode = stepExecution.getExitStatus() != null ? stepExecution.getExitStatus().getExitCode()
            : "";
    this.statusExitDescription = stepExecution.getExitStatus() != null
            ? stepExecution.getExitStatus().getExitDescription()
            : "";
    this.failureExceptions = stepExecution.getFailureExceptions();
    this.filterCount = stepExecution.getFilterCount();
    this.lastUpdated = stepExecution.getLastUpdated() == null ? ""
            : dateFormat.format(stepExecution.getLastUpdated());
    this.processSkipCount = stepExecution.getProcessSkipCount();
    this.readCount = stepExecution.getReadCount();
    this.readSkipCount = stepExecution.getReadSkipCount();
    this.rollbackCount = stepExecution.getRollbackCount();
    this.startTime = timeFormat.format(stepExecution.getStartTime());
    this.status = stepExecution.getStatus();
    this.stepName = stepExecution.getStepName();
    this.terminateOnly = stepExecution.isTerminateOnly();
    this.writeCount = stepExecution.getWriteCount();
    this.writeSkipCount = stepExecution.getWriteSkipCount();
}