001/*
002 * Copyright 2006-2007 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.batch.integration.chunk;
018
019
020/**
021 * Interface for a remote worker in the Remote Chunking pattern. A request comes from a master process containing some
022 * items to be processed. Once the items are done with a response needs to be generated containing a summary of the
023 * result.
024 * 
025 * @author Dave Syer
026 * 
027 * @param <T> the type of the items to be processed (it is recommended to use a Memento like a primary key)
028 */
029public interface ChunkHandler<T> {
030
031        /**
032         * Handle the chunk, processing all the items and returning a response summarising the result. If the result is a
033         * failure then the response should say so. The handler only throws an exception if it needs to roll back a
034         * transaction and knows that the request will be re-delivered (if not to the same handler then to one processing
035         * the same Step).
036         * 
037         * @param chunk a request containing the chunk to process
038         * @return a response summarising the result
039         * 
040         * @throws Exception if the handler needs to roll back a transaction and have the chunk re-delivered
041         */
042        ChunkResponse handleChunk(ChunkRequest<T> chunk) throws Exception;
043
044}