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

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

Introduction

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

Prototype

public synchronized void apply(StepContribution contribution) 

Source Link

Document

On successful execution just before a chunk commit, this method should be called.

Usage

From source file:es.fcs.batch.integration.chunk.MyChunkMessageChannelItemWriter.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    if (!(stepExecution.getStatus() == BatchStatus.COMPLETED)) {
        return ExitStatus.EXECUTING;
    }//from  w w w.  j  av a2 s  .c  o  m
    long expecting = localState.getExpecting();
    boolean timedOut;
    try {
        logger.debug("Waiting for results in step listener...");
        timedOut = !waitForResults();
        logger.debug("Finished waiting for results in step listener.");
    } catch (RuntimeException e) {
        logger.debug("Detected failure waiting for results in step listener.", e);
        stepExecution.setStatus(BatchStatus.FAILED);
        return ExitStatus.FAILED.addExitDescription(e.getClass().getName() + ": " + e.getMessage());
    } finally {
        for (StepContribution contribution : getStepContributions()) {
            stepExecution.apply(contribution);
        }
    }
    if (timedOut) {
        stepExecution.setStatus(BatchStatus.FAILED);
        throw new ItemStreamException("Timed out waiting for back log at end of step");
    }
    return ExitStatus.COMPLETED.addExitDescription("Waited for " + expecting + " results.");
}

From source file:org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    if (!(stepExecution.getStatus() == BatchStatus.COMPLETED)) {
        return ExitStatus.EXECUTING;
    }//from  www.j ava2  s  . co m
    long expecting = localState.getExpecting();
    boolean timedOut;
    try {
        logger.debug("Waiting for results in step listener...");
        timedOut = !waitForResults();
        logger.debug("Finished waiting for results in step listener.");
    } catch (RuntimeException e) {
        logger.debug("Detected failure waiting for results in step listener.", e);
        stepExecution.setStatus(BatchStatus.FAILED);
        return ExitStatus.FAILED.addExitDescription(e.getClass().getName() + ": " + e.getMessage());
    } finally {

        if (logger.isDebugEnabled()) {
            logger.debug("Finished waiting for results in step listener.  Still expecting: "
                    + localState.getExpecting());
        }

        for (StepContribution contribution : getStepContributions()) {
            stepExecution.apply(contribution);
        }
    }
    if (timedOut) {
        stepExecution.setStatus(BatchStatus.FAILED);
        return ExitStatus.FAILED.addExitDescription(
                "Timed out waiting for " + localState.getExpecting() + " backlog at end of step");
    }
    return ExitStatus.COMPLETED.addExitDescription("Waited for " + expecting + " results.");
}