From f85a662ebf69b12f61bf033edb13bcfeb7d92ed4 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Fri, 10 Sep 2021 21:46:42 +0200 Subject: [PATCH] Refine contribution #3934 * Add default methods in all listener interfaces * Remove usage of newly deprecated support classes Issue #3924 --- .../batch/core/ItemProcessListener.java | 11 +- .../batch/core/ItemReadListener.java | 9 +- .../batch/core/ItemWriteListener.java | 12 +- .../batch/core/SkipListener.java | 12 +- .../ExecutionContextPromotionListener.java | 6 +- .../core/listener/ItemListenerSupport.java | 85 +----------- ...ParameterExecutionContextCopyListener.java | 4 +- .../core/listener/SkipListenerSupport.java | 6 +- .../core/listener/StepListenerSupport.java | 124 +----------------- .../StepExecutionSimpleCompletionPolicy.java | 8 +- .../NoWorkFoundStepExecutionListener.java | 7 +- .../step/tasklet/SystemCommandTasklet.java | 7 +- .../xml/DefaultUnknownJobParserTests.java | 7 +- .../configuration/xml/DummyChunkListener.java | 24 ++++ .../xml/DummyJobExecutionListener.java | 24 ++++ .../xml/DummyStepExecutionListener.java | 24 ++++ .../xml/JobParserParentAttributeTests.java | 9 +- .../configuration/xml/NameStoringTasklet.java | 7 +- .../NextAttributeUnknownJobParserTests.java | 7 +- .../xml/StepListenerInStepParserTests.java | 16 +-- .../xml/StepListenerParserTests.java | 8 +- .../xml/StepParserStepFactoryBeanTests.java | 19 +-- .../configuration/xml/StepParserTests.java | 11 +- .../batch/core/job/SimpleJobTests.java | 4 +- .../CompositeJobExecutionListenerTests.java | 10 +- .../CompositeStepExecutionListenerTests.java | 11 +- .../MulticasterBatchListenerTests.java | 18 ++- ...aultTolerantStepFactoryBeanRetryTests.java | 5 +- .../FaultTolerantStepFactoryBeanTests.java | 6 +- .../step/item/TaskletStepExceptionTests.java | 12 +- .../core/step/tasklet/TaskletStepTests.java | 11 +- .../JobParserParentAttributeTests-context.xml | 6 +- .../StepListenerInStepParserTests-context.xml | 10 +- .../xml/StepListenerParserTests-context.xml | 4 +- ...StepParserParentAttributeTests-context.xml | 4 +- .../batch/repeat/RepeatListener.java | 18 ++- .../listener/RepeatListenerSupport.java | 7 +- .../CompositeRepeatListenerTests.java | 13 +- .../repeat/listener/RepeatListenerTests.java | 34 ++--- .../support/SimpleRepeatTemplateTests.java | 5 +- .../chunk/ChunkMessageChannelItemWriter.java | 4 +- .../sample/common/InfiniteLoopWriter.java | 5 +- .../CompositeCustomerUpdateLineTokenizer.java | 7 +- .../GeneratingTradeResettingListener.java | 7 +- .../sample/support/SummaryFooterCallback.java | 6 +- .../batch/test/StepRunner.java | 4 +- 46 files changed, 286 insertions(+), 372 deletions(-) create mode 100644 spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyChunkListener.java create mode 100644 spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobExecutionListener.java create mode 100644 spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyStepExecutionListener.java diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemProcessListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemProcessListener.java index 8000ef17e..4f44d8166 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemProcessListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemProcessListener.java @@ -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. @@ -35,7 +35,8 @@ public interface ItemProcessListener extends StepListener { * * @param item to be processed. */ - void beforeProcess(T item); + default void beforeProcess(T item) { + } /** * Called after {@link ItemProcessor#process(Object)} returns. If the @@ -45,7 +46,8 @@ public interface ItemProcessListener extends StepListener { * @param item to be processed * @param result of processing */ - void afterProcess(T item, @Nullable S result); + default void afterProcess(T item, @Nullable S result) { + } /** * Called if an exception was thrown from {@link ItemProcessor#process(Object)}. @@ -53,5 +55,6 @@ public interface ItemProcessListener extends StepListener { * @param item attempted to be processed * @param e - exception thrown during processing. */ - void onProcessError(T item, Exception e); + default void onProcessError(T item, Exception e) { + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java index 9a71bbed9..d4f31fc25 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java @@ -30,7 +30,8 @@ public interface ItemReadListener extends StepListener { /** * Called before {@link ItemReader#read()} */ - void beforeRead(); + default void beforeRead() { + } /** * Called after {@link ItemReader#read()}. @@ -39,12 +40,14 @@ public interface ItemReadListener extends StepListener { * * @param item returned from read() */ - void afterRead(T item); + default void afterRead(T item) { + } /** * Called if an error occurs while trying to read. * * @param ex thrown from {@link ItemReader} */ - void onReadError(Exception ex); + default void onReadError(Exception ex) { + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemWriteListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemWriteListener.java index 7fda29adc..b69faa9f5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemWriteListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemWriteListener.java @@ -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. @@ -38,6 +38,7 @@ import org.springframework.batch.item.ItemWriter; *

* * @author Lucas Ward + * @author Mahmoud Ben Hassine * */ public interface ItemWriteListener extends StepListener { @@ -47,7 +48,8 @@ public interface ItemWriteListener extends StepListener { * * @param items to be written */ - void beforeWrite(List items); + default void beforeWrite(List items) { + } /** * Called after {@link ItemWriter#write(java.util.List)} This will be @@ -56,7 +58,8 @@ public interface ItemWriteListener extends StepListener { * * @param items written items */ - void afterWrite(List items); + default void afterWrite(List items) { + } /** * Called if an error occurs while trying to write. Will be called inside a @@ -67,5 +70,6 @@ public interface ItemWriteListener extends StepListener { * @param exception thrown from {@link ItemWriter} * @param items attempted to be written. */ - void onWriteError(Exception exception, List items); + default void onWriteError(Exception exception, List items) { + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/SkipListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/SkipListener.java index a3e7afd08..e76315df0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/SkipListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/SkipListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 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,6 +25,7 @@ package org.springframework.batch.core; * * @author Dave Syer * @author Robert Kasanicky + * @author Mahmoud Ben Hassine * */ public interface SkipListener extends StepListener { @@ -37,7 +38,8 @@ public interface SkipListener extends StepListener { * * @param t cause of the failure */ - void onSkipInRead(Throwable t); + default void onSkipInRead(Throwable t) { + } /** * This item failed on write with the given exception, and a skip was called @@ -46,7 +48,8 @@ public interface SkipListener extends StepListener { * @param item the failed item * @param t the cause of the failure */ - void onSkipInWrite(S item, Throwable t); + default void onSkipInWrite(S item, Throwable t) { + } /** * This item failed on processing with the given exception, and a skip was called @@ -55,6 +58,7 @@ public interface SkipListener extends StepListener { * @param item the failed item * @param t the cause of the failure */ - void onSkipInProcess(T item, Throwable t); + default void onSkipInProcess(T item, Throwable t) { + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java index da6af4529..d0950adab 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -19,6 +19,7 @@ import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.support.PatternMatcher; import org.springframework.beans.factory.InitializingBean; @@ -37,9 +38,10 @@ import org.springframework.util.Assert; * promotion will only occur for steps with an exit code of "COMPLETED". * * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ -public class ExecutionContextPromotionListener extends StepExecutionListenerSupport implements InitializingBean { +public class ExecutionContextPromotionListener implements StepExecutionListener, InitializingBean { private String[] keys = null; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ItemListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ItemListenerSupport.java index 556e224be..420973ce6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ItemListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ItemListenerSupport.java @@ -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. @@ -34,87 +34,4 @@ import org.springframework.lang.Nullable; */ public class ItemListenerSupport implements ItemReadListener, ItemProcessListener, ItemWriteListener { - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.domain.ItemReadListener#afterRead(java.lang.Object) - */ - @Override - public void afterRead(I item) { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.domain.ItemReadListener#beforeRead() - */ - @Override - public void beforeRead() { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.domain.ItemReadListener#onReadError(java.lang.Exception) - */ - @Override - public void onReadError(Exception ex) { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.ItemProcessListener#afterProcess(java.lang.Object, - * java.lang.Object) - */ - @Override - public void afterProcess(I item, @Nullable O result) { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.ItemProcessListener#beforeProcess(java.lang.Object) - */ - @Override - public void beforeProcess(I item) { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.ItemProcessListener#onProcessError(java.lang.Object, - * java.lang.Exception) - */ - @Override - public void onProcessError(I item, Exception e) { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.domain.ItemWriteListener#afterWrite() - */ - @Override - public void afterWrite(List item) { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.domain.ItemWriteListener#beforeWrite(java.lang.Object) - */ - @Override - public void beforeWrite(List item) { - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.domain.ItemWriteListener#onWriteError(java.lang.Exception, - * java.lang.Object) - */ - @Override - public void onWriteError(Exception ex, List item) { - } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobParameterExecutionContextCopyListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobParameterExecutionContextCopyListener.java index 80d0112b4..640d15ee3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobParameterExecutionContextCopyListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobParameterExecutionContextCopyListener.java @@ -21,6 +21,7 @@ import java.util.Collection; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ExecutionContext; /** @@ -30,9 +31,10 @@ import org.springframework.batch.item.ExecutionContext; * {@link ExecutionContext} that should be copied. * * @author Dave Syer + * @author Mahmoud Ben Hassine * @since 2.0 */ -public class JobParameterExecutionContextCopyListener extends StepExecutionListenerSupport { +public class JobParameterExecutionContextCopyListener implements StepExecutionListener { private Collection keys = null; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/SkipListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/SkipListenerSupport.java index 69d54856d..437206747 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/SkipListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/SkipListenerSupport.java @@ -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. @@ -21,8 +21,12 @@ import org.springframework.batch.core.SkipListener; * Basic no-op implementations of all {@link SkipListener} implementations. * * @author Dave Syer + * @author Mahmoud Ben Hassine + * + * @deprecated as of v5.0 in favor of the default methods in {@link SkipListener}. * */ +@Deprecated public class SkipListenerSupport implements SkipListener { /* (non-Javadoc) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java index 9482c9b7f..6fc03fb03 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -36,125 +36,7 @@ import org.springframework.lang.Nullable; * @author Robert Kasanicky * @author Mahmoud Ben Hassine */ -public class StepListenerSupport implements StepExecutionListener, ChunkListener, -ItemReadListener, ItemProcessListener, ItemWriteListener, SkipListener { - - /* (non-Javadoc) - * @see org.springframework.batch.core.StepExecutionListener#afterStep(org.springframework.batch.core.StepExecution) - */ - @Nullable - @Override - public ExitStatus afterStep(StepExecution stepExecution) { - return null; - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.StepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) - */ - @Override - public void beforeStep(StepExecution stepExecution) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ChunkListener#afterChunk(ChunkContext context) - */ - @Override - public void afterChunk(ChunkContext context) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ChunkListener#beforeChunk(ChunkContext context) - */ - @Override - public void beforeChunk(ChunkContext context) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemReadListener#afterRead(java.lang.Object) - */ - @Override - public void afterRead(T item) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemReadListener#beforeRead() - */ - @Override - public void beforeRead() { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemReadListener#onReadError(java.lang.Exception) - */ - @Override - public void onReadError(Exception ex) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.ItemWriteListener#afterWrite(java.util.List) - */ - @Override - public void afterWrite(List items) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.ItemWriteListener#beforeWrite(java.util.List) - */ - @Override - public void beforeWrite(List items) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.ItemWriteListener#onWriteError(java.lang.Exception, java.util.List) - */ - @Override - public void onWriteError(Exception exception, List items) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.ItemProcessListener#afterProcess(java.lang.Object, java.lang.Object) - */ - @Override - public void afterProcess(T item, @Nullable S result) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.ItemProcessListener#beforeProcess(java.lang.Object) - */ - @Override - public void beforeProcess(T item) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.ItemProcessListener#onProcessError(java.lang.Object, java.lang.Exception) - */ - @Override - public void onProcessError(T item, Exception e) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.SkipListener#onSkipInProcess(java.lang.Object, java.lang.Throwable) - */ - @Override - public void onSkipInProcess(T item, Throwable t) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.SkipListener#onSkipInRead(java.lang.Throwable) - */ - @Override - public void onSkipInRead(Throwable t) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.SkipListener#onSkipInWrite(java.lang.Object, java.lang.Throwable) - */ - @Override - public void onSkipInWrite(S item, Throwable t) { - } - - @Override - public void afterChunkError(ChunkContext context) { - } +public class StepListenerSupport extends ItemListenerSupport + implements StepExecutionListener, ChunkListener, SkipListener { } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java index ccbdb833d..cd82bb1cd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java @@ -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. @@ -19,7 +19,6 @@ package org.springframework.batch.core.resource; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatStatus; @@ -44,10 +43,11 @@ import org.springframework.util.Assert; *

* * @author Dave Syer + * @author Mahmoud Ben Hassine * * @see CompletionPolicy */ -public class StepExecutionSimpleCompletionPolicy extends StepExecutionListenerSupport implements CompletionPolicy { +public class StepExecutionSimpleCompletionPolicy implements StepExecutionListener, CompletionPolicy { private CompletionPolicy delegate; @@ -69,7 +69,7 @@ public class StepExecutionSimpleCompletionPolicy extends StepExecutionListenerSu * key name, the intValue of this parameter is used. If not an exception * will be thrown. * - * @see org.springframework.batch.core.listener.StepExecutionListenerSupport#beforeStep(org.springframework.batch.core.StepExecution) + * @see org.springframework.batch.core.listener.StepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) */ @Override public void beforeStep(StepExecution stepExecution) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java index ad1e94184..e30e9bd42 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -18,15 +18,16 @@ package org.springframework.batch.core.step; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.lang.Nullable; /** * Fails the step if no items have been processed ( item count is 0). * * @author Robert Kasanicky + * @author Mahmoud Ben Hassine */ -public class NoWorkFoundStepExecutionListener extends StepExecutionListenerSupport { +public class NoWorkFoundStepExecutionListener implements StepExecutionListener { @Nullable @Override diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java index a1be7bcf6..86dd1127a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -28,8 +28,8 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.InitializingBean; @@ -59,8 +59,9 @@ import org.springframework.util.Assert; * * @author Robert Kasanicky * @author Will Schipp + * @author Mahmoud Ben Hassine */ -public class SystemCommandTasklet extends StepExecutionListenerSupport implements StoppableTasklet, InitializingBean { +public class SystemCommandTasklet implements StepExecutionListener, StoppableTasklet, InitializingBean { protected static final Log logger = LogFactory.getLog(SystemCommandTasklet.class); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.java index 04f6b8a40..505bb5a62 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DefaultUnknownJobParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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,13 +23,14 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ @ContextConfiguration @@ -57,7 +58,7 @@ public class DefaultUnknownJobParserTests extends AbstractJobParserTests { } - public static class UnknownListener extends StepExecutionListenerSupport { + public static class UnknownListener implements StepExecutionListener { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyChunkListener.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyChunkListener.java new file mode 100644 index 000000000..90000e5d3 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyChunkListener.java @@ -0,0 +1,24 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.configuration.xml; + +import org.springframework.batch.core.ChunkListener; + +/** + * @author Mahmoud Ben Hassine + */ +public class DummyChunkListener implements ChunkListener { +} \ No newline at end of file diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobExecutionListener.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobExecutionListener.java new file mode 100644 index 000000000..95cc024ef --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobExecutionListener.java @@ -0,0 +1,24 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.configuration.xml; + +import org.springframework.batch.core.JobExecutionListener; + +/** + * @author Mahmoud Ben Hassine + */ +public class DummyJobExecutionListener implements JobExecutionListener { +} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyStepExecutionListener.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyStepExecutionListener.java new file mode 100644 index 000000000..e543f78c5 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyStepExecutionListener.java @@ -0,0 +1,24 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.configuration.xml; + +import org.springframework.batch.core.StepExecutionListener; + +/** + * @author Mahmoud Ben Hassine + */ +public class DummyStepExecutionListener implements StepExecutionListener { +} \ No newline at end of file diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.java index 938c05eb8..9b60b028b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009 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. @@ -39,6 +39,7 @@ import org.springframework.test.util.ReflectionTestUtils; /** * @author Dan Garrette * @author Dave Syer + * @author Mahmoud Ben Hassine * @since 2.0 */ @ContextConfiguration @@ -80,7 +81,7 @@ public class JobParserParentAttributeTests { if (l instanceof DummyAnnotationJobExecutionListener) { a = true; } - else if (l instanceof JobExecutionListenerSupport) { + else if (l instanceof DummyJobExecutionListener) { b = true; } } @@ -94,7 +95,7 @@ public class JobParserParentAttributeTests { assertEquals(1, job2Listeners.size()); boolean c = false; for (Object l : job2Listeners) { - if (l instanceof JobExecutionListenerSupport) { + if (l instanceof DummyJobExecutionListener) { c = true; } } @@ -111,7 +112,7 @@ public class JobParserParentAttributeTests { if (l instanceof DummyAnnotationJobExecutionListener) { a = true; } - else if (l instanceof JobExecutionListenerSupport) { + else if (l instanceof DummyJobExecutionListener) { b = true; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NameStoringTasklet.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NameStoringTasklet.java index bdb00fb61..a36de68ef 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NameStoringTasklet.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NameStoringTasklet.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -19,7 +19,7 @@ import java.util.List; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; @@ -29,9 +29,10 @@ import org.springframework.lang.Nullable; * This class will store the step name when it is executed. * * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ -public class NameStoringTasklet extends StepExecutionListenerSupport implements Tasklet { +public class NameStoringTasklet implements StepExecutionListener, Tasklet { private String stepName = null; private List stepNamesList = null; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.java index 52cce6596..ebe596fd4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NextAttributeUnknownJobParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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,13 +23,14 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * @since 2.1.9 */ @ContextConfiguration @@ -57,7 +58,7 @@ public class NextAttributeUnknownJobParserTests extends AbstractJobParserTests { } - public static class UnknownListener extends StepExecutionListenerSupport { + public static class UnknownListener implements StepExecutionListener { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java index c25948d85..2dc5412f5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-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,10 +25,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; import org.springframework.batch.core.Step; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.StepListener; -import org.springframework.batch.core.listener.ChunkListenerSupport; import org.springframework.batch.core.listener.ItemListenerSupport; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +37,7 @@ import org.springframework.test.util.ReflectionTestUtils; /** * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ @ContextConfiguration @@ -52,7 +52,7 @@ public class StepListenerInStepParserTests { Step step = (Step) beanFactory.getBean("s1"); List list = getListeners(step); assertEquals(1, list.size()); - assertTrue(list.get(0) instanceof StepExecutionListenerSupport); + assertTrue(list.get(0) instanceof DummyStepExecutionListener ); } @Test @@ -61,7 +61,7 @@ public class StepListenerInStepParserTests { Step step = (Step) beanFactory.getBean("s2"); List list = getListeners(step); assertEquals(1, list.size()); - assertTrue(list.get(0) instanceof ChunkListenerSupport); + assertTrue(list.get(0) instanceof DummyChunkListener); } @Test @@ -69,8 +69,8 @@ public class StepListenerInStepParserTests { Step step = (Step) beanFactory.getBean("s3"); List list = getListeners(step); assertEquals(2, list.size()); - assertTrue(list.get(0) instanceof StepExecutionListenerSupport); - assertTrue(list.get(1) instanceof ChunkListenerSupport); + assertTrue(list.get(0) instanceof DummyStepExecutionListener); + assertTrue(list.get(1) instanceof DummyChunkListener); } @Test @@ -78,7 +78,7 @@ public class StepListenerInStepParserTests { Step step = (Step) beanFactory.getBean("s4"); List list = getListeners(step); assertEquals(2, list.size()); - assertTrue(list.get(0) instanceof StepExecutionListenerSupport); + assertTrue(list.get(0) instanceof DummyStepExecutionListener); assertTrue(list.get(1) instanceof ItemListenerSupport); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java index 7fa7fcbb0..06331860b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepListenerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-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. @@ -28,7 +28,6 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepListener; import org.springframework.batch.core.listener.CompositeStepExecutionListener; import org.springframework.batch.core.listener.ItemListenerSupport; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -38,6 +37,7 @@ import org.springframework.test.util.ReflectionTestUtils; /** * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ @ContextConfiguration @@ -69,7 +69,7 @@ public class StepListenerParserTests { if (listener instanceof DummyAnnotationStepExecutionListener) { a = true; } - else if (listener instanceof StepExecutionListenerSupport) { + else if (listener instanceof DummyStepExecutionListener) { b = true; } else if (listener instanceof CompositeStepExecutionListener) { @@ -93,7 +93,7 @@ public class StepListenerParserTests { if (listener instanceof DummyAnnotationStepExecutionListener) { a = true; } - else if (listener instanceof StepExecutionListenerSupport) { + else if (listener instanceof DummyStepExecutionListener) { b = true; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java index 76e0d9641..76c7aff4e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java @@ -23,10 +23,10 @@ import org.junit.Test; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.StepListener; import org.springframework.batch.core.job.flow.FlowStep; import org.springframework.batch.core.job.flow.support.SimpleFlow; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.partition.PartitionHandler; import org.springframework.batch.core.partition.support.PartitionStep; import org.springframework.batch.core.partition.support.SimplePartitioner; @@ -54,6 +54,7 @@ import static org.junit.Assert.assertTrue; /** * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ public class StepParserStepFactoryBeanTests { @@ -108,7 +109,7 @@ public class StepParserStepFactoryBeanTests { fb.setStartLimit(5); fb.setTasklet(new DummyTasklet()); fb.setTransactionManager(new ResourcelessTransactionManager()); - fb.setListeners(new StepExecutionListenerSupport[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepExecutionListener[] { new StepExecutionListener() {} }); fb.setIsolation(Isolation.DEFAULT); fb.setTransactionTimeout(-1); fb.setPropagation(Propagation.REQUIRED); @@ -140,7 +141,7 @@ public class StepParserStepFactoryBeanTests { fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); fb.setTransactionManager(new ResourcelessTransactionManager()); - fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepListener[] { new StepExecutionListener() {} }); fb.setIsolation(Isolation.DEFAULT); fb.setTransactionTimeout(-1); fb.setPropagation(Propagation.REQUIRED); @@ -166,7 +167,7 @@ public class StepParserStepFactoryBeanTests { fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); fb.setTransactionManager(new ResourcelessTransactionManager()); - fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepListener[] { new StepExecutionListener() {} }); fb.setIsolation(Isolation.DEFAULT); fb.setTransactionTimeout(-1); fb.setPropagation(Propagation.REQUIRED); @@ -200,7 +201,7 @@ public class StepParserStepFactoryBeanTests { fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); fb.setTransactionManager(new ResourcelessTransactionManager()); - fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepListener[] { new StepExecutionListener() {} }); fb.setIsolation(Isolation.DEFAULT); fb.setTransactionTimeout(-1); fb.setPropagation(Propagation.REQUIRED); @@ -226,7 +227,7 @@ public class StepParserStepFactoryBeanTests { fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); fb.setTransactionManager(new ResourcelessTransactionManager()); - fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepListener[] { new StepExecutionListener(){} }); fb.setChunkCompletionPolicy(new DummyCompletionPolicy()); fb.setTaskExecutor(new SyncTaskExecutor()); fb.setItemReader(new DummyItemReader()); @@ -264,7 +265,7 @@ public class StepParserStepFactoryBeanTests { fb.setAllowStartIfComplete(true); fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); - fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepListener[] { new StepExecutionListener(){} }); fb.setTaskExecutor(new SyncTaskExecutor()); SimplePartitioner partitioner = new SimplePartitioner(); @@ -284,7 +285,7 @@ public class StepParserStepFactoryBeanTests { fb.setAllowStartIfComplete(true); fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); - fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepListener[] { new StepExecutionListener(){} }); fb.setTaskExecutor(new SyncTaskExecutor()); SimplePartitioner partitioner = new SimplePartitioner(); @@ -307,7 +308,7 @@ public class StepParserStepFactoryBeanTests { fb.setAllowStartIfComplete(true); fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); - fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); + fb.setListeners(new StepListener[] { new StepExecutionListener(){} }); fb.setTaskExecutor(new SyncTaskExecutor()); fb.setFlow(new SimpleFlow("foo")); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java index f1b7d770f..8e6160be3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java @@ -34,7 +34,6 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.job.AbstractJob; import org.springframework.batch.core.listener.CompositeStepExecutionListener; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.step.AbstractStep; @@ -170,16 +169,16 @@ public class StepParserTests { ApplicationContext ctx = stepParserParentAttributeTestsCtx; // Inline Step - assertTrue(getListener("s1", ctx) instanceof StepExecutionListenerSupport); + assertTrue(getListener("s1", ctx) instanceof DummyStepExecutionListener); // Standalone Step - assertTrue(getListener("s2", ctx) instanceof StepExecutionListenerSupport); + assertTrue(getListener("s2", ctx) instanceof DummyStepExecutionListener); // Inline With Tasklet Attribute Step - assertTrue(getListener("s3", ctx) instanceof StepExecutionListenerSupport); + assertTrue(getListener("s3", ctx) instanceof DummyStepExecutionListener); // Standalone With Tasklet Attribute Step - assertTrue(getListener("s4", ctx) instanceof StepExecutionListenerSupport); + assertTrue(getListener("s4", ctx) instanceof DummyStepExecutionListener); } @Test @@ -442,7 +441,7 @@ public class StepParserTests { List> streams = Arrays.asList(CompositeItemStream.class, TestReader.class); List> retryListeners = Arrays.asList(RetryListenerSupport.class, DummyRetryListener.class); - List> stepListeners = Arrays.asList(StepExecutionListenerSupport.class, + List> stepListeners = Arrays.asList(DummyStepExecutionListener.class, CompositeStepExecutionListener.class); List> noRollback = Arrays.asList(FatalRuntimeException.class, SkippableRuntimeException.class); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java index fc9eb5a51..b87df3efd 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java @@ -230,7 +230,7 @@ public class SimpleJobTests { @Test public void testRunNormallyWithListener() throws Exception { - job.setJobExecutionListeners(new JobExecutionListenerSupport[] { new JobExecutionListenerSupport() { + job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListener() { @Override public void beforeJob(JobExecution jobExecution) { list.add("before"); @@ -310,7 +310,7 @@ public class SimpleJobTests { @Test public void testFailedWithListener() throws Exception { - job.setJobExecutionListeners(new JobExecutionListenerSupport[] { new JobExecutionListenerSupport() { + job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListener() { @Override public void afterJob(JobExecution jobExecution) { list.add("afterJob"); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobExecutionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobExecutionListenerTests.java index 8288d58f9..b9d499982 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobExecutionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobExecutionListenerTests.java @@ -22,10 +22,12 @@ import java.util.List; import junit.framework.TestCase; import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobExecutionListener; import org.springframework.batch.core.JobInstance; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class CompositeJobExecutionListenerTests extends TestCase { @@ -39,12 +41,12 @@ public class CompositeJobExecutionListenerTests extends TestCase { * {@link org.springframework.batch.core.listener.CompositeJobExecutionListener#setListeners(List)} */ public void testSetListeners() { - listener.setListeners(Arrays.asList(new JobExecutionListenerSupport() { + listener.setListeners(Arrays.asList(new JobExecutionListener() { @Override public void afterJob(JobExecution jobExecution) { list.add("fail"); } - }, new JobExecutionListenerSupport() { + }, new JobExecutionListener() { @Override public void afterJob(JobExecution jobExecution) { list.add("continue"); @@ -60,7 +62,7 @@ public class CompositeJobExecutionListenerTests extends TestCase { * . */ public void testSetListener() { - listener.register(new JobExecutionListenerSupport() { + listener.register(new JobExecutionListener() { @Override public void afterJob(JobExecution jobExecution) { list.add("fail"); @@ -76,7 +78,7 @@ public class CompositeJobExecutionListenerTests extends TestCase { * . */ public void testOpen() { - listener.register(new JobExecutionListenerSupport() { + listener.register(new JobExecutionListener() { @Override public void beforeJob(JobExecution stepExecution) { list.add("foo"); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java index 7aad3ea6e..33408c19b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -28,6 +28,7 @@ import org.springframework.lang.Nullable; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class CompositeStepExecutionListenerTests extends TestCase { @@ -44,7 +45,7 @@ public class CompositeStepExecutionListenerTests extends TestCase { public void testSetListeners() { JobExecution jobExecution = new JobExecution(1L); StepExecution stepExecution = new StepExecution("s1", jobExecution); - listener.setListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() { + listener.setListeners(new StepExecutionListener[] { new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -52,7 +53,7 @@ public class CompositeStepExecutionListenerTests extends TestCase { list.add("fail"); return ExitStatus.FAILED; } - }, new StepExecutionListenerSupport() { + }, new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -72,7 +73,7 @@ public class CompositeStepExecutionListenerTests extends TestCase { public void testSetListener() { JobExecution jobExecution = new JobExecution(1L); StepExecution stepExecution = new StepExecution("s1", jobExecution); - listener.register(new StepExecutionListenerSupport() { + listener.register(new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -90,7 +91,7 @@ public class CompositeStepExecutionListenerTests extends TestCase { * . */ public void testOpen() { - listener.register(new StepExecutionListenerSupport() { + listener.register(new StepExecutionListener() { @Override public void beforeStep(StepExecution stepExecution) { list.add("foo"); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java index 2996d17da..dada2f44a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -26,6 +26,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.SkipListener; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepListener; import org.springframework.batch.core.annotation.AfterChunk; @@ -401,11 +402,10 @@ public class MulticasterBatchListenerTests { */ @Test public void testOnSkipInRead() { - multicast.register(new SkipListenerSupport() { + multicast.register(new SkipListener() { @Override public void onSkipInRead(Throwable t) { count++; - super.onSkipInRead(t); } }); multicast.onSkipInRead(new RuntimeException("foo")); @@ -419,7 +419,7 @@ public class MulticasterBatchListenerTests { */ @Test public void testOnSkipInReadFails() { - multicast.register(new SkipListenerSupport() { + multicast.register(new SkipListener() { @Override public void onSkipInRead(Throwable t) { count++; @@ -445,11 +445,10 @@ public class MulticasterBatchListenerTests { */ @Test public void testOnSkipInWrite() { - multicast.register(new SkipListenerSupport() { + multicast.register(new SkipListener() { @Override public void onSkipInWrite(Object item, Throwable t) { count++; - super.onSkipInWrite(item, t); } }); multicast.onSkipInWrite(null, new RuntimeException("foo")); @@ -463,7 +462,7 @@ public class MulticasterBatchListenerTests { */ @Test public void testOnSkipInWriteFails() { - multicast.register(new SkipListenerSupport() { + multicast.register(new SkipListener() { @Override public void onSkipInWrite(Object item, Throwable t) { count++; @@ -489,11 +488,10 @@ public class MulticasterBatchListenerTests { */ @Test public void testOnSkipInProcess() { - multicast.register(new SkipListenerSupport() { + multicast.register(new SkipListener() { @Override public void onSkipInProcess(Object item, Throwable t) { count++; - super.onSkipInWrite(item, t); } }); multicast.onSkipInProcess(null, new RuntimeException("foo")); @@ -507,7 +505,7 @@ public class MulticasterBatchListenerTests { */ @Test public void testOnSkipInProcessFails() { - multicast.register(new SkipListenerSupport() { + multicast.register(new SkipListener() { @Override public void onSkipInProcess(Object item, Throwable t) { count++; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java index 8a2a4bdd9..064ed34de 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java @@ -33,6 +33,7 @@ import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; +import org.springframework.batch.core.SkipListener; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepListener; @@ -452,7 +453,7 @@ public class FaultTolerantStepFactoryBeanRetryTests { @Test public void testSkipAndRetryWithWriteFailure() throws Exception { - factory.setListeners(new StepListener[] { new SkipListenerSupport() { + factory.setListeners(new StepListener[] { new SkipListener() { @Override public void onSkipInWrite(String item, Throwable t) { recovered.add(item); @@ -517,7 +518,7 @@ public class FaultTolerantStepFactoryBeanRetryTests { throws Exception { factory.setCommitInterval(3); - factory.setListeners(new StepListener[] { new SkipListenerSupport() { + factory.setListeners(new StepListener[] { new SkipListener() { @Override public void onSkipInWrite(String item, Throwable t) { recovered.add(item); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java index 96865bebf..c537c3e67 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java @@ -543,7 +543,7 @@ public class FaultTolerantStepFactoryBeanTests { final List listenerCalls = new ArrayList<>(); - factory.setListeners(new StepListener[] { new SkipListenerSupport() { + factory.setListeners(new StepListener[] { new SkipListener() { @Override public void onSkipInRead(Throwable t) { listenerCalls.add(t); @@ -578,7 +578,7 @@ public class FaultTolerantStepFactoryBeanTests { writer.setFailures("4"); factory.setSkipLimit(3); - factory.setListeners(new StepListener[] { new SkipListenerSupport() { + factory.setListeners(new StepListener[] { new SkipListener() { @Override public void onSkipInRead(Throwable t) { throw new RuntimeException("oops"); @@ -613,7 +613,7 @@ public class FaultTolerantStepFactoryBeanTests { writer.setFailures("4"); factory.setSkipLimit(3); - factory.setListeners(new StepListener[] { new SkipListenerSupport() { + factory.setListeners(new StepListener[] { new SkipListener() { @Override public void onSkipInWrite(String item, Throwable t) { throw new RuntimeException("oops"); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java index 96f0e29ce..4a22fd629 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 the original author or authors. + * Copyright 2008-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. @@ -26,7 +26,6 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; @@ -62,6 +61,7 @@ import static org.springframework.batch.core.BatchStatus.UNKNOWN; * @author Lucas Ward * @author Dave Syer * @author David Turanski + * @author Mahmoud Ben Hassine * */ public class TaskletStepExceptionTests { @@ -139,7 +139,7 @@ public class TaskletStepExceptionTests { public void testBeforeStepFailure() throws Exception { final RuntimeException exception = new RuntimeException(); - taskletStep.setStepExecutionListeners(new StepExecutionListenerSupport[] { new StepExecutionListenerSupport() { + taskletStep.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListener() { @Override public void beforeStep(StepExecution stepExecution) { throw exception; @@ -155,7 +155,7 @@ public class TaskletStepExceptionTests { public void testAfterStepFailureWhenTaskletSucceeds() throws Exception { final RuntimeException exception = new RuntimeException(); - taskletStep.setStepExecutionListeners(new StepExecutionListenerSupport[] { new StepExecutionListenerSupport() { + taskletStep.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -184,7 +184,7 @@ public class TaskletStepExceptionTests { public void testAfterStepFailureWhenTaskletFails() throws Exception { final RuntimeException exception = new RuntimeException(); - taskletStep.setStepExecutionListeners(new StepExecutionListenerSupport[] { new StepExecutionListenerSupport() { + taskletStep.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -480,7 +480,7 @@ public class TaskletStepExceptionTests { } } - private static class InterruptionListener extends StepExecutionListenerSupport { + private static class InterruptionListener implements StepExecutionListener { @Override public void beforeStep(StepExecution stepExecution) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java index fb61cbe2f..9b1f2b5bd 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java @@ -39,7 +39,6 @@ import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.job.JobSupport; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao; @@ -326,7 +325,7 @@ public class TaskletStepTests { }; step.setTasklet(new TestingChunkOrientedTasklet<>(itemReader, itemWriter)); - step.registerStepExecutionListener(new StepExecutionListenerSupport() { + step.registerStepExecutionListener(new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -497,7 +496,7 @@ public class TaskletStepTests { @Test public void testDirectlyInjectedListener() throws Exception { - step.registerStepExecutionListener(new StepExecutionListenerSupport() { + step.registerStepExecutionListener(new StepExecutionListener() { @Override public void beforeStep(StepExecution stepExecution) { list.add("foo"); @@ -542,7 +541,7 @@ public class TaskletStepTests { final ExitStatus customStatus = new ExitStatus("COMPLETED_CUSTOM"); - step.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() { + step.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -566,7 +565,7 @@ public class TaskletStepTests { @Test public void testDirectlyInjectedListenerOnError() throws Exception { - step.registerStepExecutionListener(new StepExecutionListenerSupport() { + step.registerStepExecutionListener(new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { @@ -877,7 +876,7 @@ public class TaskletStepTests { */ @Test public void testStepFailureInAfterStepCallback() throws JobInterruptedException { - StepExecutionListener listener = new StepExecutionListenerSupport() { + StepExecutionListener listener = new StepExecutionListener() { @Nullable @Override public ExitStatus afterStep(StepExecution stepExecution) { diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests-context.xml index b50e1f111..33867998c 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests-context.xml @@ -14,7 +14,7 @@ + class="org.springframework.batch.core.configuration.xml.DummyJobExecutionListener" /> @@ -27,7 +27,7 @@ + class="org.springframework.batch.core.configuration.xml.DummyJobExecutionListener" /> @@ -88,7 +88,7 @@ + class="org.springframework.batch.core.configuration.xml.DummyJobExecutionListener" /> diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests-context.xml index cf2189ef5..629832f6d 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerInStepParserTests-context.xml @@ -11,7 +11,7 @@ - + @@ -19,7 +19,7 @@ - + @@ -27,13 +27,13 @@ - + - + @@ -49,7 +49,7 @@ - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerParserTests-context.xml index 023d6e375..2d6a3d957 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepListenerParserTests-context.xml @@ -22,7 +22,7 @@ - + @@ -49,7 +49,7 @@ - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml index d424cef90..ebab24a99 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml @@ -86,7 +86,7 @@ - + @@ -168,7 +168,7 @@ - + diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java index 18ace5916..a5555f148 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 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,6 +23,7 @@ package org.springframework.batch.repeat; * framework provides callbacks at key points in the processing. * * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public interface RepeatListener { @@ -32,7 +33,8 @@ public interface RepeatListener { * * @param context the current batch context. */ - void before(RepeatContext context); + default void before(RepeatContext context) { + } /** * Called by the framework after each item has been processed, unless the @@ -42,7 +44,8 @@ public interface RepeatListener { * @param context the current batch context * @param result the result of the callback */ - void after(RepeatContext context, RepeatStatus result); + default void after(RepeatContext context, RepeatStatus result) { + } /** * Called once at the start of a complete batch, before any items are @@ -54,7 +57,8 @@ public interface RepeatListener { * * @param context the current batch context */ - void open(RepeatContext context); + default void open(RepeatContext context) { + } /** * Called when a repeat callback fails by throwing an exception. There will @@ -67,7 +71,8 @@ public interface RepeatListener { * @param context the current batch context * @param e the error that was encountered in an item callback. */ - void onError(RepeatContext context, Throwable e); + default void onError(RepeatContext context, Throwable e) { + } /** * Called once at the end of a complete batch, after normal or abnormal @@ -76,5 +81,6 @@ public interface RepeatListener { * * @param context the current batch context. */ - void close(RepeatContext context); + default void close(RepeatContext context) { + } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java index ce1ffffc7..d97e818c2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 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. @@ -24,8 +24,11 @@ import org.springframework.batch.repeat.RepeatListener; * Empty method implementation of {@link RepeatListener}. * * @author Dave Syer - * + * @author Mahmoud Ben Hassine + * + * @deprecated as of v5.0 in favor of the default methods in {@link RepeatListener}. */ +@Deprecated public class RepeatListenerSupport implements RepeatListener { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java index 1fe21997b..c93b6c171 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 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. @@ -26,6 +26,7 @@ import org.springframework.batch.repeat.context.RepeatContextSupport; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class CompositeRepeatListenerTests extends TestCase { @@ -39,12 +40,12 @@ public class CompositeRepeatListenerTests extends TestCase { * Test method for {@link CompositeRepeatListener#setListeners(RepeatListener[])}. */ public void testSetListeners() { - listener.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + listener.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void open(RepeatContext context) { list.add("fail"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void open(RepeatContext context) { list.add("continue"); @@ -59,7 +60,7 @@ public class CompositeRepeatListenerTests extends TestCase { * {@link CompositeRepeatListener#register(RepeatListener)}. */ public void testSetListener() { - listener.register(new RepeatListenerSupport() { + listener.register(new RepeatListener() { @Override public void before(RepeatContext context) { list.add("fail"); @@ -70,7 +71,7 @@ public class CompositeRepeatListenerTests extends TestCase { } public void testClose() { - listener.register(new RepeatListenerSupport() { + listener.register(new RepeatListener() { @Override public void close(RepeatContext context) { list.add("foo"); @@ -81,7 +82,7 @@ public class CompositeRepeatListenerTests extends TestCase { } public void testOnError() { - listener.register(new RepeatListenerSupport() { + listener.register(new RepeatListener() { @Override public void onError(RepeatContext context, Throwable e) { list.add(e); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java index 1e7979978..e61a3c6b4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 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. @@ -36,12 +36,12 @@ public class RepeatListenerTests extends TestCase { public void testBeforeInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + template.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void before(RepeatContext context) { calls.add("1"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void before(RepeatContext context) { calls.add("2"); @@ -65,7 +65,7 @@ public class RepeatListenerTests extends TestCase { public void testBeforeInterceptorCanVeto() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.registerListener(new RepeatListenerSupport() { + template.registerListener(new RepeatListener() { @Override public void before(RepeatContext context) { calls.add("1"); @@ -87,12 +87,12 @@ public class RepeatListenerTests extends TestCase { public void testAfterInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + template.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void after(RepeatContext context, RepeatStatus result) { calls.add("1"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void after(RepeatContext context, RepeatStatus result) { calls.add("2"); @@ -114,12 +114,12 @@ public class RepeatListenerTests extends TestCase { public void testOpenInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + template.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void open(RepeatContext context) { calls.add("1"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void open(RepeatContext context) { calls.add("2"); @@ -140,7 +140,7 @@ public class RepeatListenerTests extends TestCase { public void testSingleOpenInterceptor() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.registerListener(new RepeatListenerSupport() { + template.registerListener(new RepeatListener() { @Override public void open(RepeatContext context) { calls.add("1"); @@ -161,12 +161,12 @@ public class RepeatListenerTests extends TestCase { public void testCloseInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + template.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void close(RepeatContext context) { calls.add("1"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void close(RepeatContext context) { calls.add("2"); @@ -189,12 +189,12 @@ public class RepeatListenerTests extends TestCase { public void testOnErrorInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + template.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void onError(RepeatContext context, Throwable t) { calls.add("1"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void onError(RepeatContext context, Throwable t) { calls.add("2"); @@ -219,12 +219,12 @@ public class RepeatListenerTests extends TestCase { public void testOnErrorInterceptorsPrecedence() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); - template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + template.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void after(RepeatContext context, RepeatStatus result) { calls.add("1"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void onError(RepeatContext context, Throwable t) { calls.add("2"); @@ -252,12 +252,12 @@ public class RepeatListenerTests extends TestCase { template.setTaskExecutor(new SimpleAsyncTaskExecutor()); final List calls = new ArrayList<>(); final List fails = new ArrayList<>(); - template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { + template.setListeners(new RepeatListener[] { new RepeatListener() { @Override public void after(RepeatContext context, RepeatStatus result) { calls.add("1"); } - }, new RepeatListenerSupport() { + }, new RepeatListener() { @Override public void onError(RepeatContext context, Throwable t) { calls.add("2"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java index 53c8765ba..020cc0952 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 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. @@ -42,6 +42,7 @@ import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; /** * @author Dave Syer + * @author Mahmoud Ben Hassine */ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { @@ -458,7 +459,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { } ExceptionHandlerStub exHandler = new ExceptionHandlerStub(); - class RepeatListenerStub extends RepeatListenerSupport { + class RepeatListenerStub implements RepeatListener { boolean called = false; @Override diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java index 705a296ed..cb5e8c685 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java @@ -29,7 +29,7 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemStreamException; @@ -41,7 +41,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.util.Assert; -public class ChunkMessageChannelItemWriter extends StepExecutionListenerSupport implements ItemWriter, +public class ChunkMessageChannelItemWriter implements StepExecutionListener, ItemWriter, ItemStream, StepContributionSource { private static final Log logger = LogFactory.getLog(ChunkMessageChannelItemWriter.class); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java index b34a1a613..e29c8790e 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java @@ -21,7 +21,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ItemWriter; /** @@ -30,9 +30,10 @@ import org.springframework.batch.item.ItemWriter; * jobs. * * @author Lucas Ward + * @author Mahmoud Ben Hassine * */ -public class InfiniteLoopWriter extends StepExecutionListenerSupport implements ItemWriter { +public class InfiniteLoopWriter implements StepExecutionListener, ItemWriter { private static final Log LOG = LogFactory.getLog(InfiniteLoopWriter.class); private StepExecution stepExecution; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizer.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizer.java index d124d7f44..fed1bbfe3 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizer.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CompositeCustomerUpdateLineTokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -17,7 +17,7 @@ package org.springframework.batch.sample.domain.trade; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.batch.item.file.transform.LineTokenizer; import org.springframework.lang.Nullable; @@ -29,9 +29,10 @@ import org.springframework.lang.Nullable; * will delegate accordingly. * * @author Lucas Ward + * @author Mahmoud Ben Hassine * @since 2.0 */ -public class CompositeCustomerUpdateLineTokenizer extends StepExecutionListenerSupport implements LineTokenizer { +public class CompositeCustomerUpdateLineTokenizer implements StepExecutionListener, LineTokenizer { private LineTokenizer customerTokenizer; private LineTokenizer footerTokenizer; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java index cd8d827b2..6db174887 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 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. @@ -17,7 +17,7 @@ package org.springframework.batch.sample.loop; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.sample.domain.trade.internal.GeneratingTradeItemReader; import org.springframework.beans.factory.InitializingBean; import org.springframework.lang.Nullable; @@ -28,9 +28,10 @@ import org.springframework.util.Assert; * step. * * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ -public class GeneratingTradeResettingListener extends StepExecutionListenerSupport implements InitializingBean { +public class GeneratingTradeResettingListener implements StepExecutionListener, InitializingBean { private GeneratingTradeItemReader reader; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/SummaryFooterCallback.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/SummaryFooterCallback.java index 046ac7fc8..f97f8c8df 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/SummaryFooterCallback.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/SummaryFooterCallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 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. @@ -20,13 +20,13 @@ import java.io.IOException; import java.io.Writer; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepExecutionListenerSupport; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.file.FlatFileFooterCallback; /** * Writes summary info in the footer of a file. */ -public class SummaryFooterCallback extends StepExecutionListenerSupport implements FlatFileFooterCallback{ +public class SummaryFooterCallback implements StepExecutionListener, FlatFileFooterCallback{ private StepExecution stepExecution; diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java b/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java index 745254376..cac5595d2 100755 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java @@ -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. @@ -144,7 +144,7 @@ public class StepRunner { // Dump the given Job ExecutionContext using a listener // if (jobExecutionContext != null && !jobExecutionContext.isEmpty()) { - job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() { + job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListener() { @Override public void beforeJob(JobExecution jobExecution) { ExecutionContext jobContext = jobExecution.getExecutionContext();