Skip to content

Commit fecf8a5

Browse files
parikshitduttafmbenhassine
authored andcommitted
Add default methods in listener interfaces
Resolves #3924
1 parent dacf5bc commit fecf8a5

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/ChunkListener.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525
* @author Lucas Ward
2626
* @author Michael Minella
2727
* @author Mahmoud Ben Hassine
28-
*
28+
* @author Parikshit Dutta
2929
*/
3030
public interface ChunkListener extends StepListener {
3131

@@ -36,14 +36,16 @@ public interface ChunkListener extends StepListener {
3636
*
3737
* @param context The current {@link ChunkContext}
3838
*/
39-
void beforeChunk(ChunkContext context);
39+
default void beforeChunk(ChunkContext context) {
40+
}
4041

4142
/**
4243
* Callback after the chunk is executed, outside the transaction.
4344
*
4445
* @param context The current {@link ChunkContext}
4546
*/
46-
void afterChunk(ChunkContext context);
47+
default void afterChunk(ChunkContext context) {
48+
}
4749

4850
/**
4951
* Callback after a chunk has been marked for rollback. It is invoked
@@ -57,5 +59,6 @@ public interface ChunkListener extends StepListener {
5759
* @param context the chunk context containing the exception that caused
5860
* the underlying rollback.
5961
*/
60-
void afterChunkError(ChunkContext context);
62+
default void afterChunkError(ChunkContext context) {
63+
}
6164
}

spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
* instances themselves are not used by more than one thread.
2323
*
2424
* @author Dave Syer
25-
*
25+
* @author Parikshit Dutta
2626
*/
2727
public interface JobExecutionListener {
2828

@@ -31,7 +31,8 @@ public interface JobExecutionListener {
3131
*
3232
* @param jobExecution the current {@link JobExecution}
3333
*/
34-
void beforeJob(JobExecution jobExecution);
34+
default void beforeJob(JobExecution jobExecution) {
35+
}
3536

3637
/**
3738
* Callback after completion of a job. Called after both both successful and
@@ -40,6 +41,7 @@ public interface JobExecutionListener {
4041
*
4142
* @param jobExecution the current {@link JobExecution}
4243
*/
43-
void afterJob(JobExecution jobExecution);
44+
default void afterJob(JobExecution jobExecution) {
45+
}
4446

4547
}

spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
* @author Lucas Ward
2424
* @author Dave Syer
2525
* @author Mahmoud Ben Hassine
26-
*
26+
* @author Parikshit Dutta
2727
*/
2828
public interface StepExecutionListener extends StepListener {
2929

@@ -33,7 +33,8 @@ public interface StepExecutionListener extends StepListener {
3333
*
3434
* @param stepExecution instance of {@link StepExecution}.
3535
*/
36-
void beforeStep(StepExecution stepExecution);
36+
default void beforeStep(StepExecution stepExecution) {
37+
}
3738

3839
/**
3940
* Give a listener a chance to modify the exit status from a step. The value
@@ -49,5 +50,7 @@ public interface StepExecutionListener extends StepListener {
4950
* {@code null} to leave the old value unchanged.
5051
*/
5152
@Nullable
52-
ExitStatus afterStep(StepExecution stepExecution);
53+
default ExitStatus afterStep(StepExecution stepExecution) {
54+
return null;
55+
}
5356
}

0 commit comments

Comments
 (0)