diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/Chunker.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/Chunker.java new file mode 100644 index 000000000..b9b555826 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/Chunker.java @@ -0,0 +1,50 @@ +/* + * Copyright 2006-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.domain; + +import org.springframework.batch.io.exception.ReadFailureException; + + +/** + * Interface defining the contract for reading a chunk. This is most useful when + * implementing a 'chunk-oriented' approach to processing. Implementors of this + * class are expected to aggregate the output of an ItemReader into 'chunks'. + * + * @author Ben Hale + * @author Lucas Ward + */ +public interface Chunker { + + /** + * Read in a chunk, given the provided chunk size for the given StepExecution. + * + * @param chunkSize the number of items that should be read for this chunk. + * @param StepExecution the stepExecution the current chunk is being processed within. + * @return the {@link Chunk} that has been read. + * @throws IllegalArgumentException if chunkSize is less than zero. + */ + public ChunkingResult chunk(int chunkSize, StepExecution stepExecution) throws ReadFailureException; + + /** + * Flush any chunks that may be buffered. Because it may be advantageous to buffer chunks in case of + * failures, calling this method should flush any that are stored, however, it is not a requirement + * of the interface that it be implementated. + * + * @param stepExecution + */ + public void flush(StepExecution stepExecution); + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemFailureLog.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/SkippedItemHandler.java similarity index 55% rename from spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemFailureLog.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/domain/SkippedItemHandler.java index bf6381a45..9c5547843 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemFailureLog.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/SkippedItemHandler.java @@ -17,15 +17,28 @@ package org.springframework.batch.core.domain; import java.util.List; +import org.springframework.batch.io.exception.WriteFailureException; + /** * Interface for defining the contract to log out read and write - * failures encountered during batch processing. + * failures encountered during batch processing. It is expected + * that any failures encountered while writing will be + * represented as {@link WriteFailureException}s, which contain + * the items which caused the exception. * * @author Lucas Ward * */ -public interface ItemFailureLog { +public interface SkippedItemHandler { - void log(List exceptions); + /** + * Handler the list of exceptions. This will usually be done + * by logging out the details of the exception to either a + * file or database table. It is expected that any implementors of this + * of this method will not throw an exception. + * + * @param exceptions + */ + void handle(List exceptions); }