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 batch completion policies, to enable batch operations to
22 * strategise normal completion conditions. Stateful implementations of batch
23 * iterators should <em>only</em> update state using the update method. If you
24 * need custom behaviour consider extending an existing implementation or using
25 * the composite provided.
26 *
27 * @author Dave Syer
28 *
29 */
30 public interface CompletionPolicy {
31
32 /**
33 * Determine whether a batch is complete given the latest result from the
34 * callback. If this method returns true then
35 * {@link #isComplete(RepeatContext)} should also (but not necessarily vice
36 * versa, since the answer here depends on the result).
37 *
38 * @param context the current batch context.
39 * @param result the result of the latest batch item processing.
40 *
41 * @return true if the batch should terminate.
42 *
43 * @see #isComplete(RepeatContext)
44 */
45 boolean isComplete(RepeatContext context, RepeatStatus result);
46
47 /**
48 * Allow policy to signal completion according to internal state, without
49 * having to wait for the callback to complete.
50 *
51 * @param context the current batch context.
52 *
53 * @return true if the batch should terminate.
54 */
55 boolean isComplete(RepeatContext context);
56
57 /**
58 * Create a new context for the execution of a batch. N.B. implementations
59 * should <em>not</em> return the parent from this method - they must
60 * create a new context to meet the specific needs of the policy. The best
61 * way to do this might be to override an existing implementation and use
62 * the {@link RepeatContext} to store state in its attributes.
63 *
64 * @param parent the current context if one is already in progress.
65 * @return a context object that can be used by the implementation to store
66 * internal state for a batch.
67 */
68 RepeatContext start(RepeatContext parent);
69
70 /**
71 * Give implementations the opportunity to update the state of the current
72 * batch. Will be called <em>once</em> per callback, after it has been
73 * launched, but not necessarily after it completes (if the batch is
74 * asynchronous).
75 *
76 * @param context the value returned by start.
77 */
78 void update(RepeatContext context);
79
80 }