001/* 002 * Copyright 2006-2018 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 */ 016package org.springframework.batch.core; 017 018import org.springframework.batch.item.ItemProcessor; 019import org.springframework.lang.Nullable; 020 021/** 022 * Listener interface for the processing of an item. Implementations 023 * of this interface will be notified before and after an item is 024 * passed to the {@link ItemProcessor} and in the event of any 025 * exceptions thrown by the processor. 026 * 027 * @author Dave Syer 028 * @author Mahmoud Ben Hassine 029 * 030 */ 031public interface ItemProcessListener<T, S> extends StepListener { 032 033 /** 034 * Called before {@link ItemProcessor#process(Object)}. 035 * 036 * @param item to be processed. 037 */ 038 void beforeProcess(T item); 039 040 /** 041 * Called after {@link ItemProcessor#process(Object)} returns. If the 042 * processor returns {@code null}, this method will still be called, with 043 * a {code null} result, allowing for notification of 'filtered' items. 044 * 045 * @param item to be processed 046 * @param result of processing 047 */ 048 void afterProcess(T item, @Nullable S result); 049 050 /** 051 * Called if an exception was thrown from {@link ItemProcessor#process(Object)}. 052 * 053 * @param item attempted to be processed 054 * @param e - exception thrown during processing. 055 */ 056 void onProcessError(T item, Exception e); 057}