Example usage for org.springframework.batch.core.step.item Chunk getSkips

List of usage examples for org.springframework.batch.core.step.item Chunk getSkips

Introduction

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

Prototype

public List<SkipWrapper<W>> getSkips() 

Source Link

Usage

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

@Override
protected boolean isComplete(Chunk<I> inputs) {

    /*/*  w  w w. j a v  a2s  . c  o  m*/
     * Need to remember the write skips across transactions, otherwise they
     * keep coming back. Since we register skips with the inputs they will
     * not be processed again but the output skips need to be saved for
     * registration later with the listeners. The inputs are going to be the
     * same for all transactions processing the same chunk, but the outputs
     * are not, so we stash them in user data on the inputs.
     */

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

    return inputs.isEmpty() && previous.getSkips().isEmpty();

}

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

@Override
protected Chunk<O> getAdjustedOutputs(Chunk<I> inputs, Chunk<O> outputs) {

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

    Chunk<O> next = new Chunk<O>(outputs.getItems(), previous.getSkips());
    next.setBusy(previous.isBusy());/* w  ww  .ja  va  2  s . co m*/

    // Remember for next time if there are skips accumulating
    data.setOutputs(next);

    return next;

}

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

private void callSkipListeners(final Chunk<I> inputs, final Chunk<O> outputs) {

    for (SkipWrapper<I> wrapper : inputs.getSkips()) {
        I item = wrapper.getItem();// w w  w  .  j  av a  2s  .com
        if (item == null) {
            continue;
        }
        Throwable e = wrapper.getException();
        callProcessSkipListener(item, e);
    }

    for (SkipWrapper<O> wrapper : outputs.getSkips()) {
        Throwable e = wrapper.getException();
        try {
            getListener().onSkipInWrite(wrapper.getItem(), e);
        } catch (RuntimeException ex) {
            throw new SkipListenerFailedException("Fatal exception in SkipListener.", ex, e);
        }
    }

    // Clear skips if we are possibly going to process this chunk again
    outputs.clearSkips();
    inputs.clearSkips();

}