Example usage for org.springframework.batch.core.step.item ChunkProcessor process

List of usage examples for org.springframework.batch.core.step.item ChunkProcessor process

Introduction

In this page you can find the example usage for org.springframework.batch.core.step.item ChunkProcessor process.

Prototype

void process(StepContribution contribution, Chunk<I> chunk) throws Exception;

Source Link

Usage

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

/**
 * @param chunkRequest the current request
 * @param stepContribution the step contribution to update
 * @throws Exception if there is a fatal exception
 *///from w w  w . ja v  a 2  s  .c  om
private Throwable process(MyChunkRequest<S> chunkRequest, StepContribution stepContribution) throws Exception {

    ChunkProcessor<S> chunkProcessor = chunkRequest.getChunkProcessor();
    logger.debug("ChunkProcessor=" + chunkProcessor.getClass());
    Assert.state(chunkProcessor instanceof ChunkProcessor<?>,
            chunkProcessor.getClass() + "must be a ChunkProcessor");

    Chunk<S> chunk = new Chunk<S>(chunkRequest.getItems());
    Throwable failure = null;
    try {
        chunkProcessor.process(stepContribution, chunk);
    } catch (SkipLimitExceededException e) {
        failure = e;
    } catch (NonSkippableReadException e) {
        failure = e;
    } catch (SkipListenerFailedException e) {
        failure = e;
    } catch (RetryException e) {
        failure = e;
    } catch (JobInterruptedException e) {
        failure = e;
    } catch (Exception e) {
        if (chunkProcessor instanceof FaultTolerantChunkProcessor<?, ?>) {
            // try again...
            throw e;
        } else {
            failure = e;
        }
    }

    return failure;

}