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;
18
19
20 /**
21 * Interface for listeners to the batch process. Implementers can provide
22 * enhance the behaviour of a batch in small cross-cutting modules. The
23 * framework provides callbacks at key points in the processing.
24 *
25 * @author Dave Syer
26 *
27 */
28 public interface RepeatListener {
29 /**
30 * Called by the framework before each batch item. Implementers can halt a
31 * batch by setting the complete flag on the context.
32 *
33 * @param context the current batch context.
34 */
35 void before(RepeatContext context);
36
37 /**
38 * Called by the framework after each item has been processed, unless the
39 * item processing results in an exception. This method is called as soon as
40 * the result is known.
41 *
42 * @param context the current batch context
43 * @param result the result of the callback
44 */
45 void after(RepeatContext context, RepeatStatus result);
46
47 /**
48 * Called once at the start of a complete batch, before any items are
49 * processed. Implementers can use this method to acquire any resources that
50 * might be needed during processing. Implementers can halt the current
51 * operation by setting the complete flag on the context. To halt all
52 * enclosing batches (the whole job), the would need to use the parent
53 * context (recursively).
54 *
55 * @param context the current batch context
56 */
57 void open(RepeatContext context);
58
59 /**
60 * Called when a repeat callback fails by throwing an exception. There will
61 * be one call to this method for each exception thrown during a repeat
62 * operation (e.g. a chunk).<br/>
63 *
64 * There is no need to re-throw the exception here - that will be done by
65 * the enclosing framework.
66 *
67 * @param context the current batch context
68 * @param e the error that was encountered in an item callback.
69 */
70 void onError(RepeatContext context, Throwable e);
71
72 /**
73 * Called once at the end of a complete batch, after normal or abnormal
74 * completion (i.e. even after an exception). Implementers can use this
75 * method to clean up any resources.
76 *
77 * @param context the current batch context.
78 */
79 void close(RepeatContext context);
80 }