Skip to content

Commit f85a662

Browse files
committed
Refine contribution #3934
* Add default methods in all listener interfaces * Remove usage of newly deprecated support classes Issue #3924
1 parent ba09001 commit f85a662

File tree

46 files changed

+286
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+286
-372
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/ItemProcessListener.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.
@@ -35,7 +35,8 @@ public interface ItemProcessListener<T, S> extends StepListener {
3535
*
3636
* @param item to be processed.
3737
*/
38-
void beforeProcess(T item);
38+
default void beforeProcess(T item) {
39+
}
3940

4041
/**
4142
* Called after {@link ItemProcessor#process(Object)} returns. If the
@@ -45,13 +46,15 @@ public interface ItemProcessListener<T, S> extends StepListener {
4546
* @param item to be processed
4647
* @param result of processing
4748
*/
48-
void afterProcess(T item, @Nullable S result);
49+
default void afterProcess(T item, @Nullable S result) {
50+
}
4951

5052
/**
5153
* Called if an exception was thrown from {@link ItemProcessor#process(Object)}.
5254
*
5355
* @param item attempted to be processed
5456
* @param e - exception thrown during processing.
5557
*/
56-
void onProcessError(T item, Exception e);
58+
default void onProcessError(T item, Exception e) {
59+
}
5760
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public interface ItemReadListener<T> extends StepListener {
3030
/**
3131
* Called before {@link ItemReader#read()}
3232
*/
33-
void beforeRead();
33+
default void beforeRead() {
34+
}
3435

3536
/**
3637
* Called after {@link ItemReader#read()}.
@@ -39,12 +40,14 @@ public interface ItemReadListener<T> extends StepListener {
3940
*
4041
* @param item returned from read()
4142
*/
42-
void afterRead(T item);
43+
default void afterRead(T item) {
44+
}
4345

4446
/**
4547
* Called if an error occurs while trying to read.
4648
*
4749
* @param ex thrown from {@link ItemReader}
4850
*/
49-
void onReadError(Exception ex);
51+
default void onReadError(Exception ex) {
52+
}
5053
}

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

Lines changed: 8 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.
@@ -38,6 +38,7 @@
3838
*</p>
3939
*
4040
* @author Lucas Ward
41+
* @author Mahmoud Ben Hassine
4142
*
4243
*/
4344
public interface ItemWriteListener<S> extends StepListener {
@@ -47,7 +48,8 @@ public interface ItemWriteListener<S> extends StepListener {
4748
*
4849
* @param items to be written
4950
*/
50-
void beforeWrite(List<? extends S> items);
51+
default void beforeWrite(List<? extends S> items) {
52+
}
5153

5254
/**
5355
* Called after {@link ItemWriter#write(java.util.List)} This will be
@@ -56,7 +58,8 @@ public interface ItemWriteListener<S> extends StepListener {
5658
*
5759
* @param items written items
5860
*/
59-
void afterWrite(List<? extends S> items);
61+
default void afterWrite(List<? extends S> items) {
62+
}
6063

6164
/**
6265
* Called if an error occurs while trying to write. Will be called inside a
@@ -67,5 +70,6 @@ public interface ItemWriteListener<S> extends StepListener {
6770
* @param exception thrown from {@link ItemWriter}
6871
* @param items attempted to be written.
6972
*/
70-
void onWriteError(Exception exception, List<? extends S> items);
73+
default void onWriteError(Exception exception, List<? extends S> items) {
74+
}
7175
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 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,6 +25,7 @@
2525
*
2626
* @author Dave Syer
2727
* @author Robert Kasanicky
28+
* @author Mahmoud Ben Hassine
2829
*
2930
*/
3031
public interface SkipListener<T,S> extends StepListener {
@@ -37,7 +38,8 @@ public interface SkipListener<T,S> extends StepListener {
3738
*
3839
* @param t cause of the failure
3940
*/
40-
void onSkipInRead(Throwable t);
41+
default void onSkipInRead(Throwable t) {
42+
}
4143

4244
/**
4345
* This item failed on write with the given exception, and a skip was called
@@ -46,7 +48,8 @@ public interface SkipListener<T,S> extends StepListener {
4648
* @param item the failed item
4749
* @param t the cause of the failure
4850
*/
49-
void onSkipInWrite(S item, Throwable t);
51+
default void onSkipInWrite(S item, Throwable t) {
52+
}
5053

5154
/**
5255
* This item failed on processing with the given exception, and a skip was called
@@ -55,6 +58,7 @@ public interface SkipListener<T,S> extends StepListener {
5558
* @param item the failed item
5659
* @param t the cause of the failure
5760
*/
58-
void onSkipInProcess(T item, Throwable t);
61+
default void onSkipInProcess(T item, Throwable t) {
62+
}
5963

6064
}

spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 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.
@@ -19,6 +19,7 @@
1919
import org.springframework.batch.core.Job;
2020
import org.springframework.batch.core.Step;
2121
import org.springframework.batch.core.StepExecution;
22+
import org.springframework.batch.core.StepExecutionListener;
2223
import org.springframework.batch.item.ExecutionContext;
2324
import org.springframework.batch.support.PatternMatcher;
2425
import org.springframework.beans.factory.InitializingBean;
@@ -37,9 +38,10 @@
3738
* promotion will only occur for steps with an exit code of "COMPLETED".
3839
*
3940
* @author Dan Garrette
41+
* @author Mahmoud Ben Hassine
4042
* @since 2.0
4143
*/
42-
public class ExecutionContextPromotionListener extends StepExecutionListenerSupport implements InitializingBean {
44+
public class ExecutionContextPromotionListener implements StepExecutionListener, InitializingBean {
4345

4446
private String[] keys = null;
4547

Lines changed: 1 addition & 84 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.
@@ -34,87 +34,4 @@
3434
*/
3535
public class ItemListenerSupport<I, O> implements ItemReadListener<I>, ItemProcessListener<I, O>, ItemWriteListener<O> {
3636

37-
/*
38-
* (non-Javadoc)
39-
*
40-
* @see org.springframework.batch.core.domain.ItemReadListener#afterRead(java.lang.Object)
41-
*/
42-
@Override
43-
public void afterRead(I item) {
44-
}
45-
46-
/*
47-
* (non-Javadoc)
48-
*
49-
* @see org.springframework.batch.core.domain.ItemReadListener#beforeRead()
50-
*/
51-
@Override
52-
public void beforeRead() {
53-
}
54-
55-
/*
56-
* (non-Javadoc)
57-
*
58-
* @see org.springframework.batch.core.domain.ItemReadListener#onReadError(java.lang.Exception)
59-
*/
60-
@Override
61-
public void onReadError(Exception ex) {
62-
}
63-
64-
/*
65-
* (non-Javadoc)
66-
*
67-
* @see org.springframework.batch.core.ItemProcessListener#afterProcess(java.lang.Object,
68-
* java.lang.Object)
69-
*/
70-
@Override
71-
public void afterProcess(I item, @Nullable O result) {
72-
}
73-
74-
/*
75-
* (non-Javadoc)
76-
*
77-
* @see org.springframework.batch.core.ItemProcessListener#beforeProcess(java.lang.Object)
78-
*/
79-
@Override
80-
public void beforeProcess(I item) {
81-
}
82-
83-
/*
84-
* (non-Javadoc)
85-
*
86-
* @see org.springframework.batch.core.ItemProcessListener#onProcessError(java.lang.Object,
87-
* java.lang.Exception)
88-
*/
89-
@Override
90-
public void onProcessError(I item, Exception e) {
91-
}
92-
93-
/*
94-
* (non-Javadoc)
95-
*
96-
* @see org.springframework.batch.core.domain.ItemWriteListener#afterWrite()
97-
*/
98-
@Override
99-
public void afterWrite(List<? extends O> item) {
100-
}
101-
102-
/*
103-
* (non-Javadoc)
104-
*
105-
* @see org.springframework.batch.core.domain.ItemWriteListener#beforeWrite(java.lang.Object)
106-
*/
107-
@Override
108-
public void beforeWrite(List<? extends O> item) {
109-
}
110-
111-
/*
112-
* (non-Javadoc)
113-
*
114-
* @see org.springframework.batch.core.domain.ItemWriteListener#onWriteError(java.lang.Exception,
115-
* java.lang.Object)
116-
*/
117-
@Override
118-
public void onWriteError(Exception ex, List<? extends O> item) {
119-
}
12037
}

spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobParameterExecutionContextCopyListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.batch.core.JobParameters;
2222
import org.springframework.batch.core.Step;
2323
import org.springframework.batch.core.StepExecution;
24+
import org.springframework.batch.core.StepExecutionListener;
2425
import org.springframework.batch.item.ExecutionContext;
2526

2627
/**
@@ -30,9 +31,10 @@
3031
* {@link ExecutionContext} that should be copied.
3132
*
3233
* @author Dave Syer
34+
* @author Mahmoud Ben Hassine
3335
* @since 2.0
3436
*/
35-
public class JobParameterExecutionContextCopyListener extends StepExecutionListenerSupport {
37+
public class JobParameterExecutionContextCopyListener implements StepExecutionListener {
3638

3739
private Collection<String> keys = null;
3840

spring-batch-core/src/main/java/org/springframework/batch/core/listener/SkipListenerSupport.java

Lines changed: 5 additions & 1 deletion
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.
@@ -21,8 +21,12 @@
2121
* Basic no-op implementations of all {@link SkipListener} implementations.
2222
*
2323
* @author Dave Syer
24+
* @author Mahmoud Ben Hassine
25+
*
26+
* @deprecated as of v5.0 in favor of the default methods in {@link SkipListener}.
2427
*
2528
*/
29+
@Deprecated
2630
public class SkipListenerSupport<T,S> implements SkipListener<T,S> {
2731

2832
/* (non-Javadoc)

0 commit comments

Comments
 (0)