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.repeat; 018 019 020/** 021 * Interface for listeners to the batch process. Implementers can provide 022 * enhance the behaviour of a batch in small cross-cutting modules. The 023 * framework provides callbacks at key points in the processing. 024 * 025 * @author Dave Syer 026 * 027 */ 028public interface RepeatListener { 029 /** 030 * Called by the framework before each batch item. Implementers can halt a 031 * batch by setting the complete flag on the context. 032 * 033 * @param context the current batch context. 034 */ 035 void before(RepeatContext context); 036 037 /** 038 * Called by the framework after each item has been processed, unless the 039 * item processing results in an exception. This method is called as soon as 040 * the result is known. 041 * 042 * @param context the current batch context 043 * @param result the result of the callback 044 */ 045 void after(RepeatContext context, RepeatStatus result); 046 047 /** 048 * Called once at the start of a complete batch, before any items are 049 * processed. Implementers can use this method to acquire any resources that 050 * might be needed during processing. Implementers can halt the current 051 * operation by setting the complete flag on the context. To halt all 052 * enclosing batches (the whole job), the would need to use the parent 053 * context (recursively). 054 * 055 * @param context the current batch context 056 */ 057 void open(RepeatContext context); 058 059 /** 060 * Called when a repeat callback fails by throwing an exception. There will 061 * be one call to this method for each exception thrown during a repeat 062 * operation (e.g. a chunk).<br> 063 * 064 * There is no need to re-throw the exception here - that will be done by 065 * the enclosing framework. 066 * 067 * @param context the current batch context 068 * @param e the error that was encountered in an item callback. 069 */ 070 void onError(RepeatContext context, Throwable e); 071 072 /** 073 * Called once at the end of a complete batch, after normal or abnormal 074 * completion (i.e. even after an exception). Implementers can use this 075 * method to clean up any resources. 076 * 077 * @param context the current batch context. 078 */ 079 void close(RepeatContext context); 080}