Skip to content

Commit

Permalink
Pass the current chunk as context in ChunkListener#beforeChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbenhassine committed Oct 10, 2024
1 parent c6e4f0c commit c4d03e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*
* Notable difference: afterChunk is called inside the transaction, not outside the transaction.
*/
public interface ChunkListener<O> extends StepListener {
public interface ChunkListener<I, O> extends StepListener {

/**
* Callback before the chunk is processed, inside the transaction.
*/
default void beforeChunk() {
default void beforeChunk(Chunk<I> chunk) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean rollbackOn(Throwable ex) {
*/
private final int chunkSize;
private final ChunkTracker chunkTracker = new ChunkTracker();
private ChunkListener<O> chunkListener = new ChunkListener<>() {};
private ChunkListener<I, O> chunkListener = new ChunkListener<>() {};

/*
* Step state / interruption parameters
Expand Down Expand Up @@ -132,8 +132,8 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
Chunk<I> inputChunk = new Chunk<>();
Chunk<O> processedChunk = new Chunk<>();
try {
chunkListener.beforeChunk();
inputChunk = read(contribution);
chunkListener.beforeChunk(inputChunk);
processedChunk = process(inputChunk, contribution);
write(processedChunk, contribution);
chunkListener.afterChunk(processedChunk);
Expand Down Expand Up @@ -243,7 +243,7 @@ public void setItemWriteListener(ItemWriteListener<O> itemWriteListener) {
this.itemWriteListener = itemWriteListener;
}

public void setChunkListener(ChunkListener<O> chunkListener) {
public void setChunkListener(ChunkListener<I, O> chunkListener) {
this.chunkListener = chunkListener;
}

Expand Down

0 comments on commit c4d03e0

Please sign in to comment.