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;
18  
19  import org.springframework.core.AttributeAccessor;
20  
21  /**
22   * Base interface for context which controls the state and completion /
23   * termination of a batch step. A new context is created for each call to the
24   * {@link RepeatOperations}. Within a batch callback code can communicate via
25   * the {@link AttributeAccessor} interface.
26   * 
27   * @author Dave Syer
28   * 
29   * @see RepeatOperations#iterate(RepeatCallback)
30   * 
31   */
32  public interface RepeatContext extends AttributeAccessor {
33  
34  	/**
35  	 * If batches are nested, then the inner batch will be created with the
36  	 * outer one as a parent. This is an accessor for the parent if it exists.
37  	 * 
38  	 * @return the parent context or null if there is none
39  	 */
40  	RepeatContext getParent();
41  
42  	/**
43  	 * Public access to a counter for the number of operations attempted.
44  	 * 
45  	 * @return the number of batch operations started.
46  	 */
47  	int getStartedCount();
48  
49  	/**
50  	 * Signal to the framework that the current batch should complete normally,
51  	 * independent of the current {@link CompletionPolicy}.
52  	 */
53  	void setCompleteOnly();
54  
55  	/**
56  	 * Public accessor for the complete flag.
57  	 */
58  	boolean isCompleteOnly();
59  
60  	/**
61  	 * Signal to the framework that the current batch should complete
62  	 * abnormally, independent of the current {@link CompletionPolicy}.
63  	 */
64  	void setTerminateOnly();
65  
66  	/**
67  	 * Public accessor for the termination flag. If this flag is set then the
68  	 * complete flag will also be.
69  	 */
70  	boolean isTerminateOnly();
71  
72  	/**
73  	 * Register a callback to be executed on close, associated with the
74  	 * attribute having the given name. The {@link Runnable} callback should not
75  	 * throw any exceptions.
76  	 * 
77  	 * @param name the name of the attribute to associated this callback with.
78  	 * If this attribute is removed the callback should never be called.
79  	 * @param callback a {@link Runnable} to execute when the context is closed.
80  	 */
81  	void registerDestructionCallback(String name, Runnable callback);
82  
83  	/**
84  	 * Allow resources to be cleared, especially in destruction callbacks.
85  	 * Implementations should ensure that any registered destruction callbacks
86  	 * are executed here, as long as the corresponding attribute is still
87  	 * available.
88  	 */
89  	void close();
90  
91  }