Example usage for org.springframework.batch.core.step.item ChunkMonitor incrementOffset

List of usage examples for org.springframework.batch.core.step.item ChunkMonitor incrementOffset

Introduction

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

Prototype

public void incrementOffset() 

Source Link

Usage

From source file:org.springframework.batch.core.step.item.FaultTolerantChunkProcessor.java

private void scan(final StepContribution contribution, final Chunk<I> inputs, final Chunk<O> outputs,
        ChunkMonitor chunkMonitor, boolean recovery) throws Exception {

    @SuppressWarnings("unchecked")
    final UserData<O> data = (UserData<O>) inputs.getUserData();

    if (logger.isDebugEnabled()) {
        if (recovery) {
            logger.debug("Scanning for failed item on recovery from write: " + inputs);
        } else {//w  w  w  .j  ava2  s. c  o  m
            logger.debug("Scanning for failed item on write: " + inputs);
        }
    }
    if (outputs.isEmpty() || inputs.isEmpty()) {
        data.scanning(false);
        inputs.setBusy(false);
        chunkMonitor.resetOffset();
        return;
    }

    Chunk<I>.ChunkIterator inputIterator = inputs.iterator();
    Chunk<O>.ChunkIterator outputIterator = outputs.iterator();

    List<O> items = Collections.singletonList(outputIterator.next());
    inputIterator.next();
    try {
        writeItems(items);
        // If successful we are going to return and allow
        // the driver to commit...
        doAfterWrite(items);
        contribution.incrementWriteCount(1);
        inputIterator.remove();
        outputIterator.remove();
    } catch (Exception e) {
        try {
            doOnWriteError(e, items);
        } finally {
            Throwable cause = e;
            if (e instanceof StepListenerFailedException) {
                cause = e.getCause();
            }

            if (!shouldSkip(itemWriteSkipPolicy, cause, -1) && !rollbackClassifier.classify(cause)) {
                inputIterator.remove();
                outputIterator.remove();
            } else {
                checkSkipPolicy(inputIterator, outputIterator, cause, contribution, recovery);
            }
            if (rollbackClassifier.classify(cause)) {
                throw (Exception) cause;
            }
        }
    }
    chunkMonitor.incrementOffset();
    if (outputs.isEmpty()) {
        data.scanning(false);
        inputs.setBusy(false);
        chunkMonitor.resetOffset();
    }
}