View Javadoc

1   /*
2    * Copyright 2006-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.repeat.exception;
18  
19  import org.springframework.batch.repeat.CompletionPolicy;
20  import org.springframework.batch.repeat.RepeatContext;
21  
22  /**
23   * Handler to allow strategies for re-throwing exceptions. Normally a
24   * {@link CompletionPolicy} will be used to decide whether to end a batch when
25   * there is no exception, and the {@link ExceptionHandler} is used to signal an
26   * abnormal ending - an abnormal ending would result in an
27   * {@link ExceptionHandler} throwing an exception. The caller will catch and
28   * re-throw it if necessary.
29   * 
30   * @author Dave Syer
31   * @author Robert Kasanicky
32   * 
33   */
34  public interface ExceptionHandler {
35  
36  	/**
37  	 * Deal with a Throwable during a batch - decide whether it should be
38  	 * re-thrown in the first place.
39  	 * 
40  	 * @param context the current {@link RepeatContext}. Can be used to store
41  	 * state (via attributes), for example to count the number of occurrences of
42  	 * a particular exception type and implement a threshold policy.
43  	 * @param throwable an exception.
44  	 * @throws Throwable implementations are free to re-throw the exception
45  	 */
46  	void handleException(RepeatContext context, Throwable throwable) throws Throwable;
47  
48  }