View Javadoc

1   /*
2    * Copyright 2006-2013 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  package org.springframework.batch.core;
17  
18  import org.springframework.batch.core.scope.context.ChunkContext;
19  
20  /**
21   * Listener interface for the lifecycle of a chunk.  A chunk
22   * can be through of as a collection of items that will be
23   * committed together.
24   *
25   * @author Lucas Ward
26   * @author Michael Minella
27   *
28   */
29  public interface ChunkListener extends StepListener {
30  
31  	static final String ROLLBACK_EXCEPTION_KEY = "sb_rollback_exception";
32  
33  	/**
34  	 * Callback before the chunk is executed, but inside the transaction.
35  	 *
36  	 * @param context The current {@link ChunkContext}
37  	 */
38  	void beforeChunk(ChunkContext context);
39  
40  	/**
41  	 * Callback after the chunk is executed, outside the transaction.
42  	 *
43  	 * @param context The current {@link ChunkContext}
44  	 */
45  	void afterChunk(ChunkContext context);
46  
47  	/**
48  	 * Callback after a chunk has been marked for rollback.  It is invoked
49  	 * after transaction rollback.  While the rollback will have occurred,
50  	 * transactional resources might still be active and accessible.  Due to
51  	 * this, data access code within this callback will still "participate" in
52  	 * the original transaction unless it declares that it run in its own
53  	 * transaction.  Hence: <em> Use PROPAGATION_REQUIRES_NEW for any
54  	 * transactional operation that is called from here.</em>
55  	 *
56  	 * @param context the chunk context containing the exception that caused
57  	 * the underlying rollback.
58  	 */
59  	void afterChunkError(ChunkContext context);
60  }