Add default methods in listener interfaces

Resolves #3924
This commit is contained in:
Parikshit Dutta
2021-06-09 09:47:48 +05:30
committed by Mahmoud Ben Hassine
parent dacf5bca3d
commit fecf8a5c44
3 changed files with 21 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
* Copyright 2006-2021 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.
@@ -25,7 +25,7 @@ import org.springframework.batch.core.scope.context.ChunkContext;
* @author Lucas Ward
* @author Michael Minella
* @author Mahmoud Ben Hassine
*
* @author Parikshit Dutta
*/
public interface ChunkListener extends StepListener {
@@ -36,14 +36,16 @@ public interface ChunkListener extends StepListener {
*
* @param context The current {@link ChunkContext}
*/
void beforeChunk(ChunkContext context);
default void beforeChunk(ChunkContext context) {
}
/**
* Callback after the chunk is executed, outside the transaction.
*
* @param context The current {@link ChunkContext}
*/
void afterChunk(ChunkContext context);
default void afterChunk(ChunkContext context) {
}
/**
* Callback after a chunk has been marked for rollback. It is invoked
@@ -57,5 +59,6 @@ public interface ChunkListener extends StepListener {
* @param context the chunk context containing the exception that caused
* the underlying rollback.
*/
void afterChunkError(ChunkContext context);
default void afterChunkError(ChunkContext context) {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013 the original author or authors.
* Copyright 2006-2021 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.
@@ -22,7 +22,7 @@ package org.springframework.batch.core;
* instances themselves are not used by more than one thread.
*
* @author Dave Syer
*
* @author Parikshit Dutta
*/
public interface JobExecutionListener {
@@ -31,7 +31,8 @@ public interface JobExecutionListener {
*
* @param jobExecution the current {@link JobExecution}
*/
void beforeJob(JobExecution jobExecution);
default void beforeJob(JobExecution jobExecution) {
}
/**
* Callback after completion of a job. Called after both both successful and
@@ -40,6 +41,7 @@ public interface JobExecutionListener {
*
* @param jobExecution the current {@link JobExecution}
*/
void afterJob(JobExecution jobExecution);
default void afterJob(JobExecution jobExecution) {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
* Copyright 2006-2021 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.
@@ -23,7 +23,7 @@ import org.springframework.lang.Nullable;
* @author Lucas Ward
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
* @author Parikshit Dutta
*/
public interface StepExecutionListener extends StepListener {
@@ -33,7 +33,8 @@ public interface StepExecutionListener extends StepListener {
*
* @param stepExecution instance of {@link StepExecution}.
*/
void beforeStep(StepExecution stepExecution);
default void beforeStep(StepExecution stepExecution) {
}
/**
* Give a listener a chance to modify the exit status from a step. The value
@@ -49,5 +50,7 @@ public interface StepExecutionListener extends StepListener {
* {@code null} to leave the old value unchanged.
*/
@Nullable
ExitStatus afterStep(StepExecution stepExecution);
default ExitStatus afterStep(StepExecution stepExecution) {
return null;
}
}