@Override protected Tasklet createTasklet() { Assert.state(reader != null, "ItemReader must be provided"); Assert.state(writer != null, "ItemWriter must be provided"); RepeatOperations repeatOperations = createChunkOperations(); SimpleChunkProvider<I> chunkProvider = new SimpleChunkProvider<>(getReader(), repeatOperations); SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<>(getProcessor(), getWriter()); chunkProvider.setListeners(new ArrayList<>(itemListeners)); chunkProcessor.setListeners(new ArrayList<>(itemListeners)); ChunkOrientedTasklet<I> tasklet = new ChunkOrientedTasklet<>(chunkProvider, chunkProcessor); tasklet.setBuffering(!readerTransactionalQueue); return tasklet; }
/** * Register some {@link StepListener}s with the handler. Each will get the * callbacks in the order specified at the correct stage. * * @param listeners list of {@link StepListener}s. */ public void setListeners(List<? extends StepListener> listeners) { for (StepListener listener : listeners) { registerListener(listener); } }
/** * Delegates to {@link #doRead()}. Subclasses can add additional behaviour * (e.g. exception handling). * * @param contribution the current step execution contribution * @param chunk the current chunk * @return a new item for processing or {@code null} if the data source is exhausted * * @throws SkipOverflowException if specifically the chunk is accumulating * too much data (e.g. skips) and it wants to force a commit. * * @throws Exception if there is a generic issue */ @Nullable protected I read(StepContribution contribution, Chunk<I> chunk) throws SkipOverflowException, Exception { return doRead(); }
@Test public void testProvide() throws Exception { provider = new SimpleChunkProvider<>(new ListItemReader<>(Arrays.asList("foo", "bar")), new RepeatTemplate()); Chunk<String> chunk = provider.provide(contribution); assertNotNull(chunk); assertEquals(2, chunk.getItems().size()); }
chunkProvider.setListeners(BatchListenerFactoryHelper.<ItemReadListener<T>> getListeners(listeners, ItemReadListener.class)); chunkProvider.setListeners(BatchListenerFactoryHelper.<SkipListener<T, S>> getListeners(listeners, SkipListener.class)); StepListener listener = StepListenerFactoryBean.getListener(itemHandler); if (listener instanceof SkipListener<?,?>) { chunkProvider.registerListener(listener); chunkProcessor.registerListener(listener); chunkProvider.registerListener(listener);
@Override public RepeatStatus doInIteration(final RepeatContext context) throws Exception { I item = null; try { item = read(contribution, inputs); } catch (SkipOverflowException e) { // read() tells us about an excess of skips by throwing an // exception return RepeatStatus.FINISHED; } if (item == null) { inputs.setEnd(); return RepeatStatus.FINISHED; } inputs.add(item); contribution.incrementReadCount(); return RepeatStatus.CONTINUABLE; }
/** * Creates a {@link PassThroughItemProcessor} and uses it to create an * instance of {@link Tasklet}. */ public TestingChunkOrientedTasklet(ItemReader<T> itemReader, ItemProcessor<T, T> itemProcessor, ItemWriter<T> itemWriter, RepeatOperations repeatOperations) { super(new SimpleChunkProvider<>(itemReader, repeatOperations), new SimpleChunkProcessor<>( itemProcessor, itemWriter)); }
public RepeatStatus doInIteration(final RepeatContext context) throws Exception { I item = null; try { item = read(contribution, inputs); } catch (SkipOverflowException e) { // read() tells us about an excess of skips by throwing an // exception return RepeatStatus.FINISHED; } if (item == null) { inputs.setEnd(); return RepeatStatus.FINISHED; } inputs.add(item); contribution.incrementReadCount(); return RepeatStatus.CONTINUABLE; }
@Test public void testProvideWithOverflow() throws Exception { provider = new SimpleChunkProvider<String>(new ListItemReader<>(Arrays.asList("foo", "bar")), new RepeatTemplate()) { @Override protected String read(StepContribution contribution, Chunk<String> chunk) throws SkipOverflowException, Exception { chunk.skip(new RuntimeException("Planned")); throw new SkipOverflowException("Overflow"); } }; Chunk<String> chunk = null; chunk = provider.provide(contribution); assertNotNull(chunk); assertEquals(0, chunk.getItems().size()); assertEquals(1, chunk.getErrors().size()); }
/** * Extension point for creating appropriate {@link ChunkProvider}. Return * value must subclass {@link SimpleChunkProvider} due to listener * registration. */ protected SimpleChunkProvider<T> configureChunkProvider() { return new SimpleChunkProvider<T>(itemReader, chunkOperations); }
@Override protected Tasklet createTasklet() { Assert.state(reader != null, "ItemReader must be provided"); Assert.state(processor != null || writer != null, "ItemWriter or ItemProcessor must be provided"); RepeatOperations repeatOperations = createChunkOperations(); SimpleChunkProvider<I> chunkProvider = new SimpleChunkProvider<I>(reader, repeatOperations); SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<I, O>(processor, writer); chunkProvider.setListeners(new ArrayList<StepListener>(itemListeners)); chunkProcessor.setListeners(new ArrayList<StepListener>(itemListeners)); ChunkOrientedTasklet<I> tasklet = new ChunkOrientedTasklet<I>(chunkProvider, chunkProcessor); tasklet.setBuffering(!readerTransactionalQueue); return tasklet; }
/** * Register some {@link StepListener}s with the handler. Each will get the * callbacks in the order specified at the correct stage. * * @param listeners */ public void setListeners(List<? extends StepListener> listeners) { for (StepListener listener : listeners) { registerListener(listener); } }
/** * Delegates to {@link #doRead()}. Subclasses can add additional behaviour * (e.g. exception handling). * * @param contribution the current step execution contribution * @param chunk the current chunk * @return a new item for processing * * @throws SkipOverflowException if specifically the chunk is accumulating * too much data (e.g. skips) and it wants to force a commit. * * @throws Exception if there is a generic issue */ protected I read(StepContribution contribution, Chunk<I> chunk) throws SkipOverflowException, Exception { return doRead(); }
@Override public RepeatStatus doInIteration(final RepeatContext context) throws Exception { I item = null; try { item = read(contribution, inputs); } catch (SkipOverflowException e) { // read() tells us about an excess of skips by throwing an // exception return RepeatStatus.FINISHED; } if (item == null) { inputs.setEnd(); return RepeatStatus.FINISHED; } inputs.add(item); contribution.incrementReadCount(); return RepeatStatus.CONTINUABLE; }
@Override protected Tasklet createTasklet() { Assert.state(reader != null, "ItemReader must be provided"); Assert.state(writer != null, "ItemWriter must be provided"); RepeatOperations repeatOperations = createChunkOperations(); SimpleChunkProvider<I> chunkProvider = new SimpleChunkProvider<>(getReader(), repeatOperations); SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<>(getProcessor(), getWriter()); chunkProvider.setListeners(new ArrayList<>(itemListeners)); chunkProcessor.setListeners(new ArrayList<>(itemListeners)); ChunkOrientedTasklet<I> tasklet = new ChunkOrientedTasklet<>(chunkProvider, chunkProcessor); tasklet.setBuffering(!readerTransactionalQueue); return tasklet; }
/** * Register some {@link StepListener}s with the handler. Each will get the * callbacks in the order specified at the correct stage. * * @param listeners */ public void setListeners(List<? extends StepListener> listeners) { for (StepListener listener : listeners) { registerListener(listener); } }
/** * Delegates to {@link #doRead()}. Subclasses can add additional behaviour * (e.g. exception handling). * * @param contribution the current step execution contribution * @param chunk the current chunk * @return a new item for processing * * @throws SkipOverflowException if specifically the chunk is accumulating * too much data (e.g. skips) and it wants to force a commit. * * @throws Exception if there is a generic issue */ protected I read(StepContribution contribution, Chunk<I> chunk) throws SkipOverflowException, Exception { return doRead(); }
@Override public RepeatStatus doInIteration(final RepeatContext context) throws Exception { I item = null; try { item = read(contribution, inputs); } catch (SkipOverflowException e) { // read() tells us about an excess of skips by throwing an // exception return RepeatStatus.FINISHED; } if (item == null) { inputs.setEnd(); return RepeatStatus.FINISHED; } inputs.add(item); contribution.incrementReadCount(); return RepeatStatus.CONTINUABLE; }
@Override protected Tasklet createTasklet() { Assert.state(reader != null, "ItemReader must be provided"); Assert.state(writer != null, "ItemWriter must be provided"); RepeatOperations repeatOperations = createChunkOperations(); SimpleChunkProvider<I> chunkProvider = new SimpleChunkProvider<>(getReader(), repeatOperations); SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<>(getProcessor(), getWriter()); chunkProvider.setListeners(new ArrayList<>(itemListeners)); chunkProcessor.setListeners(new ArrayList<>(itemListeners)); ChunkOrientedTasklet<I> tasklet = new ChunkOrientedTasklet<>(chunkProvider, chunkProcessor); tasklet.setBuffering(!readerTransactionalQueue); return tasklet; }
/** * Register some {@link StepListener}s with the handler. Each will get the * callbacks in the order specified at the correct stage. * * @param listeners list of {@link StepListener}s. */ public void setListeners(List<? extends StepListener> listeners) { for (StepListener listener : listeners) { registerListener(listener); } }