Skip to content

Commit c4d03e0

Browse files
committed
Pass the current chunk as context in ChunkListener#beforeChunk
1 parent c6e4f0c commit c4d03e0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/main/java/org/springframework/batch/experimental/core/step/item/ChunkListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*
1111
* Notable difference: afterChunk is called inside the transaction, not outside the transaction.
1212
*/
13-
public interface ChunkListener<O> extends StepListener {
13+
public interface ChunkListener<I, O> extends StepListener {
1414

1515
/**
1616
* Callback before the chunk is processed, inside the transaction.
1717
*/
18-
default void beforeChunk() {
18+
default void beforeChunk(Chunk<I> chunk) {
1919
}
2020

2121
/**

src/main/java/org/springframework/batch/experimental/core/step/item/ChunkOrientedStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public boolean rollbackOn(Throwable ex) {
8484
*/
8585
private final int chunkSize;
8686
private final ChunkTracker chunkTracker = new ChunkTracker();
87-
private ChunkListener<O> chunkListener = new ChunkListener<>() {};
87+
private ChunkListener<I, O> chunkListener = new ChunkListener<>() {};
8888

8989
/*
9090
* Step state / interruption parameters
@@ -132,8 +132,8 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
132132
Chunk<I> inputChunk = new Chunk<>();
133133
Chunk<O> processedChunk = new Chunk<>();
134134
try {
135-
chunkListener.beforeChunk();
136135
inputChunk = read(contribution);
136+
chunkListener.beforeChunk(inputChunk);
137137
processedChunk = process(inputChunk, contribution);
138138
write(processedChunk, contribution);
139139
chunkListener.afterChunk(processedChunk);
@@ -243,7 +243,7 @@ public void setItemWriteListener(ItemWriteListener<O> itemWriteListener) {
243243
this.itemWriteListener = itemWriteListener;
244244
}
245245

246-
public void setChunkListener(ChunkListener<O> chunkListener) {
246+
public void setChunkListener(ChunkListener<I, O> chunkListener) {
247247
this.chunkListener = chunkListener;
248248
}
249249

0 commit comments

Comments
 (0)