spring-batch ChunkListener 源码

  • 2022-08-16
  • 浏览 (568)

spring-batch ChunkListener 代码

文件路径:/spring-batch-core/src/main/java/org/springframework/batch/core/ChunkListener.java

/*
 * Copyright 2006-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.batch.core;

import org.springframework.batch.core.scope.context.ChunkContext;

/**
 * Listener interface for the lifecycle of a chunk. A chunk can be thought of as a
 * collection of items that are committed together.
 *
 * @author Lucas Ward
 * @author Michael Minella
 * @author Mahmoud Ben Hassine
 * @author Parikshit Dutta
 */
public interface ChunkListener extends StepListener {

	/**
	 * The key for retrieving the rollback exception.
	 */
	String ROLLBACK_EXCEPTION_KEY = "sb_rollback_exception";

	/**
	 * Callback before the chunk is executed, but inside the transaction.
	 * @param context The current {@link ChunkContext}
	 */
	default void beforeChunk(ChunkContext context) {
	}

	/**
	 * Callback after the chunk is executed, outside the transaction.
	 * @param context The current {@link ChunkContext}
	 */
	default void afterChunk(ChunkContext context) {
	}

	/**
	 * Callback after a chunk has been marked for rollback. It is invoked after
	 * transaction rollback. While the rollback will have occurred, transactional
	 * resources might still be active and accessible. Due to this, data access code
	 * within this callback still "participates" in the original transaction unless it
	 * declares that it runs in its own transaction. <em>As a result, you should use
	 * {@code PROPAGATION_REQUIRES_NEW} for any transactional operation that is called
	 * from here.</em>
	 * @param context the chunk context containing the exception that caused the
	 * underlying rollback.
	 */
	default void afterChunkError(ChunkContext context) {
	}

}

相关信息

spring-batch 源码目录

相关文章

spring-batch BatchStatus 源码

spring-batch DefaultJobKeyGenerator 源码

spring-batch Entity 源码

spring-batch ExitStatus 源码

spring-batch ItemProcessListener 源码

spring-batch ItemReadListener 源码

spring-batch ItemWriteListener 源码

spring-batch Job 源码

spring-batch JobExecution 源码

spring-batch JobExecutionException 源码

0  赞