diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/BatchListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/BatchListener.java deleted file mode 100644 index 6f54b66f8..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/BatchListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2006-2008 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 - * - * http://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; - -/** - * Marker interface that acts as a parent to all Batch - * domain listeners, such as: {@link StepListener}, - * {@link ChunkListener}, {@link ItemReadListener} and - * {@link ItemWriteListener} - * - * @author Lucas Ward - * - */ -public interface BatchListener { - -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/ChunkListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/ChunkListener.java index 2ba574e5a..c4cdbff4e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/ChunkListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/ChunkListener.java @@ -23,7 +23,7 @@ package org.springframework.batch.core; * @author Lucas Ward * */ -public interface ChunkListener extends BatchListener { +public interface ChunkListener extends StepListener { /** * Callback before the chunk is executed, but inside the transaction. 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 dfc3ba147..c2614001f 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 @@ -24,7 +24,7 @@ import org.springframework.batch.item.ItemWriter; * @author Lucas Ward * */ -public interface ItemReadListener extends BatchListener { +public interface ItemReadListener extends StepListener { /** * Called before {@link ItemReader#read()} 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 54c542f32..951961f2a 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 @@ -23,7 +23,7 @@ import org.springframework.batch.item.ItemWriter; * @author Lucas Ward * */ -public interface ItemWriteListener extends BatchListener { +public interface ItemWriteListener extends StepListener { /** * Called before {@link ItemWriter#write(Object)} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java similarity index 97% rename from spring-batch-core/src/main/java/org/springframework/batch/core/JobListener.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java index 26fa87cb1..41c083184 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java @@ -24,7 +24,7 @@ package org.springframework.batch.core; * @author Dave Syer * */ -public interface JobListener { +public interface JobExecutionListener { /** * Initialise the state of the listener with the {@link JobExecution} from diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java new file mode 100644 index 000000000..a542f9925 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java @@ -0,0 +1,55 @@ +/* + * Copyright 2006-2008 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 + * + * http://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; + +import org.springframework.batch.repeat.ExitStatus; + +/** + * Listener interface for the lifecycle of a {@link Step}. + * + * @author Lucas Ward + * @author Dave Syer + * + */ +public interface StepExecutionListener extends StepListener { + + /** + * Initialise the state of the listener with the {@link StepExecution} from + * the current scope. + * @param stepExecution + */ + void beforeStep(StepExecution stepExecution); + + /** + * The value returned will be combined with the normal exit status using + * {@link ExitStatus#and(ExitStatus)}. + * + * @param e an exception thrown by the step execution + * + * @return an exit status to be combined with the normal one, or null + */ + ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e); + + /** + * Give a listener a chance to modify the exit status from a step. The value + * returned will be combined with the normal exit status using + * {@link ExitStatus#and(ExitStatus)}. + * + * @return an {@link ExitStatus} to combine with the normal value. Return + * null to leave the old value unchanged. + */ + ExitStatus afterStep(StepExecution stepExecution); +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepListener.java index 7cc85fbfc..0d970a784 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepListener.java @@ -15,41 +15,16 @@ */ package org.springframework.batch.core; -import org.springframework.batch.repeat.ExitStatus; - /** - * Listener interface for the lifecycle of a {@link Step}. + * Marker interface that acts as a parent to all step + * domain listeners, such as: {@link StepExecutionListener}, + * {@link ChunkListener}, {@link ItemReadListener} and + * {@link ItemWriteListener} * * @author Lucas Ward * @author Dave Syer - * + * */ -public interface StepListener extends BatchListener { +public interface StepListener { - /** - * Initialise the state of the listener with the {@link StepExecution} from - * the current scope. - * @param stepExecution - */ - void beforeStep(StepExecution stepExecution); - - /** - * The value returned will be combined with the normal exit status using - * {@link ExitStatus#and(ExitStatus)}. - * - * @param e an exception thrown by the step execution - * - * @return an exit status to be combined with the normal one, or null - */ - ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e); - - /** - * Give a listener a chance to modify the exit status from a step. The value - * returned will be combined with the normal exit status using - * {@link ExitStatus#and(ExitStatus)}. - * - * @return an {@link ExitStatus} to combine with the normal value. Return - * null to leave the old value unchanged. - */ - ExitStatus afterStep(StepExecution stepExecution); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java index e024357cf..f98d2e73d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java @@ -27,10 +27,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecutionException; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobInterruptedException; -import org.springframework.batch.core.JobListener; +import org.springframework.batch.core.JobExecutionListener; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.CompositeJobListener; +import org.springframework.batch.core.listener.CompositeExecutionJobListener; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.ExitStatus; @@ -47,26 +47,26 @@ public class SimpleJob extends AbstractJob { private JobRepository jobRepository; - private CompositeJobListener listener = new CompositeJobListener(); + private CompositeExecutionJobListener listener = new CompositeExecutionJobListener(); /** - * Public setter for injecting {@link JobListener}s. They will all be given - * the {@link JobListener} callbacks at the appropriate point in the job. + * Public setter for injecting {@link JobExecutionListener}s. They will all be given + * the {@link JobExecutionListener} callbacks at the appropriate point in the job. * * @param listeners the listeners to set. */ - public void setJobListeners(JobListener[] listeners) { + public void setJobListeners(JobExecutionListener[] listeners) { for (int i = 0; i < listeners.length; i++) { this.listener.register(listeners[i]); } } /** - * Register a single listener for the {@link JobListener} callbacks. + * Register a single listener for the {@link JobExecutionListener} callbacks. * - * @param listener a {@link JobListener} + * @param listener a {@link JobExecutionListener} */ - public void registerListener(JobListener listener) { + public void registerListener(JobExecutionListener listener) { this.listener.register(listener); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/BatchListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/BatchListenerSupport.java deleted file mode 100644 index 7c9f0840d..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/BatchListenerSupport.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2006-2008 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 - * - * http://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.listener; - -import org.springframework.batch.core.BatchListener; -import org.springframework.batch.core.ChunkListener; -import org.springframework.batch.core.ItemReadListener; -import org.springframework.batch.core.ItemWriteListener; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; -import org.springframework.batch.repeat.ExitStatus; - -/** - * Basic no-op implementations of all {@link BatchListener} implementations. - * - * @author Lucas Ward - * - */ -public class BatchListenerSupport implements StepListener, ChunkListener, - ItemReadListener, ItemWriteListener { - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution stepExecution) - */ - public ExitStatus afterStep(StepExecution stepExecution) { - return null; - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution) - */ - public void beforeStep(StepExecution stepExecution) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable) - */ - public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { - return null; - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ChunkListener#afterChunk() - */ - public void afterChunk() { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ChunkListener#beforeChunk() - */ - public void beforeChunk() { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemReadListener#afterRead(java.lang.Object) - */ - public void afterRead(Object item) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemReadListener#beforeRead() - */ - public void beforeRead() { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemReadListener#onReadError(java.lang.Exception) - */ - public void onReadError(Exception ex) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemWriteListener#afterWrite() - */ - public void afterWrite(Object item) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemWriteListener#beforeWrite(java.lang.Object) - */ - public void beforeWrite(Object item) { - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ItemWriteListener#onWriteError(java.lang.Exception, java.lang.Object) - */ - public void onWriteError(Exception ex, Object item) { - } - -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeJobListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeExecutionJobListener.java similarity index 72% rename from spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeJobListener.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeExecutionJobListener.java index c537ab24c..a31cd9feb 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeJobListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeExecutionJobListener.java @@ -21,13 +21,13 @@ import java.util.Iterator; import java.util.List; import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobListener; +import org.springframework.batch.core.JobExecutionListener; /** * @author Dave Syer * */ -public class CompositeJobListener implements JobListener { +public class CompositeExecutionJobListener implements JobExecutionListener { private List listeners = new ArrayList(); @@ -36,38 +36,38 @@ public class CompositeJobListener implements JobListener { * * @param listeners */ - public void setListeners(JobListener[] listeners) { + public void setListeners(JobExecutionListener[] listeners) { this.listeners = Arrays.asList(listeners); } /** * Register additional listener. * - * @param jobListener + * @param jobExecutionListener */ - public void register(JobListener jobListener) { - if (!listeners.contains(jobListener)) { - listeners.add(jobListener); + public void register(JobExecutionListener jobExecutionListener) { + if (!listeners.contains(jobExecutionListener)) { + listeners.add(jobExecutionListener); } } public void afterJob(JobExecution jobExecution) { for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) { - JobListener listener = (JobListener) iterator.next(); + JobExecutionListener listener = (JobExecutionListener) iterator.next(); listener.afterJob(jobExecution); } } public void beforeJob(JobExecution jobExecution) { for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) { - JobListener listener = (JobListener) iterator.next(); + JobExecutionListener listener = (JobExecutionListener) iterator.next(); listener.beforeJob(jobExecution); } } public void onError(JobExecution jobExecution, Throwable e) { for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) { - JobListener listener = (JobListener) iterator.next(); + JobExecutionListener listener = (JobExecutionListener) iterator.next(); listener.onError(jobExecution, e); } @@ -75,7 +75,7 @@ public class CompositeJobListener implements JobListener { public void onInterrupt(JobExecution jobExecution) { for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) { - JobListener listener = (JobListener) iterator.next(); + JobExecutionListener listener = (JobExecutionListener) iterator.next(); listener.onInterrupt(jobExecution); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepExecutionListener.java similarity index 77% rename from spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepListener.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepExecutionListener.java index f697bf976..6ab1067c0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepExecutionListener.java @@ -21,14 +21,15 @@ import java.util.Iterator; import java.util.List; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.repeat.ExitStatus; /** * @author Lucas Ward + * @author Dave Syer * */ -public class CompositeStepListener implements StepListener { +public class CompositeStepExecutionListener implements StepExecutionListener { private List listeners = new ArrayList(); @@ -37,18 +38,18 @@ public class CompositeStepListener implements StepListener { * * @param listeners */ - public void setListeners(StepListener[] listeners) { + public void setListeners(StepExecutionListener[] listeners) { this.listeners = Arrays.asList(listeners); } /** * Register additional listener. * - * @param stepListener + * @param stepExecutionListener */ - public void register(StepListener stepListener) { - if (!listeners.contains(stepListener)) { - listeners.add(stepListener); + public void register(StepExecutionListener stepExecutionListener) { + if (!listeners.contains(stepExecutionListener)) { + listeners.add(stepExecutionListener); } } @@ -58,7 +59,7 @@ public class CompositeStepListener implements StepListener { public ExitStatus afterStep(StepExecution stepExecution) { ExitStatus status = null; for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - StepListener listener = (StepListener) iterator.next(); + StepExecutionListener listener = (StepExecutionListener) iterator.next(); ExitStatus close = listener.afterStep(stepExecution); status = status!=null ? status.and(close): close; } @@ -70,7 +71,7 @@ public class CompositeStepListener implements StepListener { */ public void beforeStep(StepExecution stepExecution) { for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - StepListener listener = (StepListener) iterator.next(); + StepExecutionListener listener = (StepExecutionListener) iterator.next(); listener.beforeStep(stepExecution); } } @@ -81,7 +82,7 @@ public class CompositeStepListener implements StepListener { public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { ExitStatus status = null; for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - StepListener listener = (StepListener) iterator.next(); + StepExecutionListener listener = (StepExecutionListener) iterator.next(); ExitStatus close = listener.onErrorInStep(stepExecution, e); status = status!=null ? status.and(close): close; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobExecutionListenerSupport.java similarity index 91% rename from spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobListenerSupport.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobExecutionListenerSupport.java index f6b1fa241..91d872185 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobExecutionListenerSupport.java @@ -16,13 +16,13 @@ package org.springframework.batch.core.listener; import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobListener; +import org.springframework.batch.core.JobExecutionListener; /** * @author Dave Syer * */ -public class JobListenerSupport implements JobListener { +public class JobExecutionListenerSupport implements JobExecutionListener { /* (non-Javadoc) * @see org.springframework.batch.core.domain.JobListener#afterJob() diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java index 5cbe9ef67..01c60929f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java @@ -15,12 +15,12 @@ */ package org.springframework.batch.core.listener; -import org.springframework.batch.core.BatchListener; +import org.springframework.batch.core.StepListener; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.ItemReadListener; import org.springframework.batch.core.ItemWriteListener; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ItemStream; import org.springframework.batch.repeat.ExitStatus; @@ -28,10 +28,10 @@ import org.springframework.batch.repeat.ExitStatus; * @author Dave Syer * */ -public class MulticasterBatchListener implements StepListener, ChunkListener, ItemReadListener, +public class MulticasterBatchListener implements StepExecutionListener, ChunkListener, ItemReadListener, ItemWriteListener { - private CompositeStepListener stepListener = new CompositeStepListener(); + private CompositeStepExecutionListener stepListener = new CompositeStepExecutionListener(); private CompositeChunkListener chunkListener = new CompositeChunkListener(); @@ -53,7 +53,7 @@ public class MulticasterBatchListener implements StepListener, ChunkListener, It * @param listeners an array of listener objects of types known to the * multicaster. */ - public void setListeners(BatchListener[] listeners) { + public void setListeners(StepListener[] listeners) { for (int i = 0; i < listeners.length; i++) { register(listeners[i]); } @@ -61,12 +61,12 @@ public class MulticasterBatchListener implements StepListener, ChunkListener, It /** * Register the listener for callbacks on the appropriate interfaces - * implemented. Any {@link BatchListener} can be provided, or an + * implemented. Any {@link StepListener} can be provided, or an * {@link ItemStream}. Other types will be ignored. */ - public void register(BatchListener listener) { - if (listener instanceof StepListener) { - this.stepListener.register((StepListener) listener); + public void register(StepListener listener) { + if (listener instanceof StepExecutionListener) { + this.stepListener.register((StepExecutionListener) listener); } if (listener instanceof ChunkListener) { this.chunkListener.register((ChunkListener) listener); @@ -81,7 +81,7 @@ public class MulticasterBatchListener implements StepListener, ChunkListener, It /** * @return - * @see org.springframework.batch.core.listener.CompositeStepListener#afterStep() + * @see org.springframework.batch.core.listener.CompositeStepExecutionListener#afterStep() */ public ExitStatus afterStep(StepExecution stepExecution) { return stepListener.afterStep(stepExecution); @@ -89,7 +89,7 @@ public class MulticasterBatchListener implements StepListener, ChunkListener, It /** * @param stepExecution - * @see org.springframework.batch.core.listener.CompositeStepListener#beforeStep(org.springframework.batch.core.StepExecution) + * @see org.springframework.batch.core.listener.CompositeStepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) */ public void beforeStep(StepExecution stepExecution) { stepListener.beforeStep(stepExecution); @@ -98,7 +98,7 @@ public class MulticasterBatchListener implements StepListener, ChunkListener, It /** * @param e * @return - * @see org.springframework.batch.core.listener.CompositeStepListener#onErrorInStep(java.lang.Throwable) + * @see org.springframework.batch.core.listener.CompositeStepExecutionListener#onErrorInStep(java.lang.Throwable) */ public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { return stepListener.onErrorInStep(stepExecution, e); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepExecutionListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepExecutionListenerSupport.java new file mode 100644 index 000000000..b89cff776 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepExecutionListenerSupport.java @@ -0,0 +1,47 @@ +/* + * Copyright 2006-2007 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 + * + * http://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.listener; + +import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.StepExecutionListener; +import org.springframework.batch.repeat.ExitStatus; + +/** + * @author Dave Syer + * + */ +public class StepExecutionListenerSupport implements StepExecutionListener { + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution stepExecution) + */ + public ExitStatus afterStep(StepExecution stepExecution) { + return null; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.item.ExecutionContext) + */ + public void beforeStep(StepExecution stepExecution) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.StepListener#onError(java.lang.Throwable) + */ + public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { + return null; + } +} 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 8488050dc..6cb7781e8 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-2007 the original author or authors. + * Copyright 2006-2008 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. @@ -15,15 +15,22 @@ */ package org.springframework.batch.core.listener; -import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.ChunkListener; +import org.springframework.batch.core.ItemReadListener; +import org.springframework.batch.core.ItemWriteListener; +import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.repeat.ExitStatus; /** - * @author Dave Syer + * Basic no-op implementations of all {@link StepListener} implementations. + * + * @author Lucas Ward * */ -public class StepListenerSupport implements StepListener { +public class StepListenerSupport implements StepExecutionListener, ChunkListener, + ItemReadListener, ItemWriteListener { /* (non-Javadoc) * @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution stepExecution) @@ -33,15 +40,64 @@ public class StepListenerSupport implements StepListener { } /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.item.ExecutionContext) + * @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution) */ public void beforeStep(StepExecution stepExecution) { } /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#onError(java.lang.Throwable) + * @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable) */ public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { return null; } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ChunkListener#afterChunk() + */ + public void afterChunk() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ChunkListener#beforeChunk() + */ + public void beforeChunk() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#afterRead(java.lang.Object) + */ + public void afterRead(Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#beforeRead() + */ + public void beforeRead() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#onReadError(java.lang.Exception) + */ + public void onReadError(Exception ex) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#afterWrite() + */ + public void afterWrite(Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#beforeWrite(java.lang.Object) + */ + public void beforeWrite(Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#onWriteError(java.lang.Exception, java.lang.Object) + */ + public void onWriteError(Exception ex, Object item) { + } + } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetter.java index 704460f2b..8182e4c1a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetter.java @@ -22,8 +22,8 @@ import java.util.Map; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; -import org.springframework.batch.core.listener.StepListenerSupport; +import org.springframework.batch.core.StepExecutionListener; +import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.SqlTypeValue; @@ -32,13 +32,13 @@ import org.springframework.util.Assert; /** * Implementation of the {@link PreparedStatementSetter} interface that also implements - * {@link StepListener} and uses {@link JobParameters} to set the parameters on a + * {@link StepExecutionListener} and uses {@link JobParameters} to set the parameters on a * PreparedStatement. * * @author Lucas Ward * */ -public class JobParametersPreparedStatementSetter extends StepListenerSupport implements +public class JobParametersPreparedStatementSetter extends StepExecutionListenerSupport implements PreparedStatementSetter, InitializingBean { private List parameterKeys; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java index 6b40fa4e8..e56a86537 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java @@ -27,10 +27,10 @@ import java.util.Map.Entry; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverter; -import org.springframework.batch.core.listener.StepListenerSupport; +import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.FileSystemResourceLoader; import org.springframework.core.io.Resource; @@ -67,7 +67,7 @@ import org.springframework.util.StringUtils; * To use this resource it must be initialised with a {@link StepExecution}. * The best way to do that is to register it as a listener in the step that is * going to need it. For this reason the resource implements - * {@link StepListener}. + * {@link StepExecutionListener}. * * @author Tomas Slanina * @author Lucas Ward @@ -75,8 +75,8 @@ import org.springframework.util.StringUtils; * * @see Resource */ -public class StepExecutionResourceProxy extends StepListenerSupport implements Resource, ResourceLoaderAware, - StepListener { +public class StepExecutionResourceProxy extends StepExecutionListenerSupport implements Resource, ResourceLoaderAware, + StepExecutionListener { private static final String JOB_NAME_PATTERN = "%JOB_NAME%"; @@ -277,7 +277,7 @@ public class StepExecutionResourceProxy extends StepListenerSupport implements R * Collect the properties of the enclosing {@link StepExecution} that will * be needed to create a file name. * - * @see org.springframework.batch.core.StepListener#beforeStep(org.springframework.batch.core.StepExecution) + * @see org.springframework.batch.core.StepExecutionListener#beforeStep(org.springframework.batch.core.StepExecution) */ public void beforeStep(StepExecution execution) { String stepName = execution.getStepName(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java index 26307f14e..b8d261077 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java @@ -18,11 +18,11 @@ package org.springframework.batch.core.step.item; import java.util.ArrayList; import java.util.List; -import org.springframework.batch.core.BatchListener; +import org.springframework.batch.core.StepListener; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.ItemReadListener; import org.springframework.batch.core.ItemWriteListener; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.listener.CompositeChunkListener; import org.springframework.batch.core.listener.CompositeItemReadListener; import org.springframework.batch.core.listener.CompositeItemWriteListener; @@ -49,12 +49,12 @@ class BatchListenerFactoryHelper { * @param listeners * @return */ - public ItemReader getItemReader(ItemReader itemReader, BatchListener[] listeners) { + public ItemReader getItemReader(ItemReader itemReader, StepListener[] listeners) { final CompositeItemReadListener multicaster = new CompositeItemReadListener(); for (int i = 0; i < listeners.length; i++) { - BatchListener listener = listeners[i]; + StepListener listener = listeners[i]; if (listener instanceof ItemReadListener) { multicaster.register((ItemReadListener) listener); } @@ -83,11 +83,11 @@ class BatchListenerFactoryHelper { * @param listeners * @return */ - public ItemWriter getItemWriter(ItemWriter itemWriter, BatchListener[] listeners) { + public ItemWriter getItemWriter(ItemWriter itemWriter, StepListener[] listeners) { final CompositeItemWriteListener multicaster = new CompositeItemWriteListener(); for (int i = 0; i < listeners.length; i++) { - BatchListener listener = listeners[i]; + StepListener listener = listeners[i]; if (listener instanceof ItemWriteListener) { multicaster.register((ItemWriteListener) listener); } @@ -116,14 +116,14 @@ class BatchListenerFactoryHelper { * @param listeners * @return */ - public RepeatOperations addChunkListeners(RepeatOperations chunkOperations, BatchListener[] listeners) { + public RepeatOperations addChunkListeners(RepeatOperations chunkOperations, StepListener[] listeners) { final CompositeChunkListener multicaster = new CompositeChunkListener(); boolean hasChunkListener = false; for (int i = 0; i < listeners.length; i++) { - BatchListener listener = listeners[i]; + StepListener listener = listeners[i]; if (listener instanceof ChunkListener) { hasChunkListener = true; } @@ -158,15 +158,15 @@ class BatchListenerFactoryHelper { * @param listeners * @return */ - public StepListener[] getStepListeners(BatchListener[] listeners) { + public StepExecutionListener[] getStepListeners(StepListener[] listeners) { List list = new ArrayList(); for (int i = 0; i < listeners.length; i++) { - BatchListener listener = listeners[i]; - if (listener instanceof StepListener) { + StepListener listener = listeners[i]; + if (listener instanceof StepExecutionListener) { list.add(listener); } } - return (StepListener[]) list.toArray(new StepListener[list.size()]); + return (StepExecutionListener[]) list.toArray(new StepExecutionListener[list.size()]); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java index 02bb53e91..03265caed 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java @@ -25,10 +25,10 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.launch.support.ExitCodeMapper; -import org.springframework.batch.core.listener.CompositeStepListener; +import org.springframework.batch.core.listener.CompositeStepExecutionListener; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.NoSuchJobException; import org.springframework.batch.core.step.AbstractStep; @@ -87,7 +87,7 @@ public class ItemOrientedStep extends AbstractStep { private CompositeItemStream stream = new CompositeItemStream(); - private CompositeStepListener listener = new CompositeStepListener(); + private CompositeStepExecutionListener listener = new CompositeStepExecutionListener(); private JobRepository jobRepository; @@ -168,7 +168,7 @@ public class ItemOrientedStep extends AbstractStep { * * @param listeners an array of listener objects of known types. */ - public void setStepListeners(StepListener[] listeners) { + public void setStepListeners(StepExecutionListener[] listeners) { for (int i = 0; i < listeners.length; i++) { registerStepListener(listeners[i]); } @@ -178,9 +178,9 @@ public class ItemOrientedStep extends AbstractStep { * Register a step listener for callbacks at the appropriate stages in a * step execution. * - * @param listener a {@link StepListener} + * @param listener a {@link StepExecutionListener} */ - public void registerStepListener(StepListener listener) { + public void registerStepListener(StepExecutionListener listener) { this.listener.register(listener); } @@ -446,7 +446,7 @@ public class ItemOrientedStep extends AbstractStep { /** * Default mapping from throwable to {@link ExitStatus}. Clients can modify - * the exit code using a {@link StepListener}. + * the exit code using a {@link StepExecutionListener}. * * @param throwable the cause of teh failure * @return an {@link ExitStatus} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBean.java index 949fe5897..a31293de0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBean.java @@ -15,9 +15,9 @@ */ package org.springframework.batch.core.step.item; -import org.springframework.batch.core.BatchListener; -import org.springframework.batch.core.Step; import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; @@ -36,7 +36,7 @@ public class RepeatOperationsStepFactoryBean extends AbstractStepFactoryBean { private ItemStream[] streams = new ItemStream[0]; - private BatchListener[] listeners = new BatchListener[0]; + private StepListener[] listeners = new StepListener[0]; private RepeatOperations chunkOperations = new RepeatTemplate(); @@ -55,12 +55,12 @@ public class RepeatOperationsStepFactoryBean extends AbstractStepFactoryBean { /** * The listeners to inject into the {@link Step}. Any instance of - * {@link BatchListener} can be used, and will then receive callbacks at the + * {@link StepListener} can be used, and will then receive callbacks at the * appropriate stage in the step. * * @param listeners an array of listeners */ - public void setListeners(BatchListener[] listeners) { + public void setListeners(StepListener[] listeners) { this.listeners = listeners; } @@ -107,19 +107,19 @@ public class RepeatOperationsStepFactoryBean extends AbstractStepFactoryBean { if (itemReader instanceof ItemStream) { step.registerStream((ItemStream) itemReader); } - if (itemReader instanceof StepListener) { - step.registerStepListener((StepListener) itemReader); + if (itemReader instanceof StepExecutionListener) { + step.registerStepListener((StepExecutionListener) itemReader); } if (itemWriter instanceof ItemStream) { step.registerStream((ItemStream) itemWriter); } - if (itemWriter instanceof StepListener) { - step.registerStepListener((StepListener) itemWriter); + if (itemWriter instanceof StepExecutionListener) { + step.registerStepListener((StepExecutionListener) itemWriter); } BatchListenerFactoryHelper helper = new BatchListenerFactoryHelper(); - StepListener[] stepListeners = helper.getStepListeners(listeners); + StepExecutionListener[] stepListeners = helper.getStepListeners(listeners); itemReader = helper.getItemReader(itemReader, listeners); itemWriter = helper.getItemWriter(itemWriter, listeners); RepeatOperations stepOperations = helper.addChunkListeners(this.stepOperations, listeners); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java index 2bb4af35f..45ee32414 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java @@ -15,9 +15,9 @@ */ package org.springframework.batch.core.step.item; -import org.springframework.batch.core.BatchListener; -import org.springframework.batch.core.Step; import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.listener.MulticasterBatchListener; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; @@ -47,7 +47,7 @@ public class SimpleStepFactoryBean extends AbstractStepFactoryBean { private ItemStream[] streams = new ItemStream[0]; - private BatchListener[] listeners = new BatchListener[0]; + private StepListener[] listeners = new StepListener[0]; private MulticasterBatchListener listener = new MulticasterBatchListener(); @@ -81,12 +81,12 @@ public class SimpleStepFactoryBean extends AbstractStepFactoryBean { /** * The listeners to inject into the {@link Step}. Any instance of - * {@link BatchListener} can be used, and will then receive callbacks at the + * {@link StepListener} can be used, and will then receive callbacks at the * appropriate stage in the step. * * @param listeners an array of listeners */ - public void setListeners(BatchListener[] listeners) { + public void setListeners(StepListener[] listeners) { this.listeners = listeners; } @@ -152,9 +152,9 @@ public class SimpleStepFactoryBean extends AbstractStepFactoryBean { step.setStreams(streams); for (int i = 0; i < listeners.length; i++) { - BatchListener listener = listeners[i]; - if (listener instanceof StepListener) { - step.registerStepListener((StepListener) listener); + StepListener listener = listeners[i]; + if (listener instanceof StepExecutionListener) { + step.registerStepListener((StepExecutionListener) listener); } else { this.listener.register(listener); @@ -170,14 +170,14 @@ public class SimpleStepFactoryBean extends AbstractStepFactoryBean { if (itemReader instanceof ItemStream) { step.registerStream((ItemStream) itemReader); } - if (itemReader instanceof StepListener) { - step.registerStepListener((StepListener) itemReader); + if (itemReader instanceof StepExecutionListener) { + step.registerStepListener((StepExecutionListener) itemReader); } if (itemWriter instanceof ItemStream) { step.registerStream((ItemStream) itemWriter); } - if (itemWriter instanceof StepListener) { - step.registerStepListener((StepListener) itemWriter); + if (itemWriter instanceof StepExecutionListener) { + step.registerStepListener((StepExecutionListener) itemWriter); } BatchListenerFactoryHelper helper = new BatchListenerFactoryHelper(); @@ -189,7 +189,7 @@ public class SimpleStepFactoryBean extends AbstractStepFactoryBean { step.setChunkOperations(chunkOperations); } - StepListener[] stepListeners = helper.getStepListeners(listeners); + StepExecutionListener[] stepListeners = helper.getStepListeners(listeners); itemReader = helper.getItemReader(itemReader, listeners); itemWriter = helper.getItemWriter(itemWriter, listeners); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java index 87dba452a..d42f552dc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java @@ -18,7 +18,7 @@ package org.springframework.batch.core.step.tasklet; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.repeat.ExitStatus; @@ -29,7 +29,7 @@ import org.springframework.batch.repeat.ExitStatus; * stored procedure.
* * Since the batch framework has no visibility inside the {@link #execute()} - * method, developers should consider implementing {@link StepListener} and + * method, developers should consider implementing {@link StepExecutionListener} and * check the {@link StepExecution#isTerminateOnly()} value for long lasting * processes to enable prompt termination of processing on user request.
* diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java index c725bc0af..f426622e2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java @@ -24,8 +24,8 @@ import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; -import org.springframework.batch.core.listener.CompositeStepListener; +import org.springframework.batch.core.StepExecutionListener; +import org.springframework.batch.core.listener.CompositeStepExecutionListener; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.AbstractStep; import org.springframework.batch.repeat.ExitStatus; @@ -48,7 +48,7 @@ public class TaskletStep extends AbstractStep implements Step, InitializingBean, private JobRepository jobRepository; - private CompositeStepListener listener = new CompositeStepListener(); + private CompositeStepExecutionListener listener = new CompositeStepExecutionListener(); /** * Set the name property if it is not already set. Because of the order of @@ -73,7 +73,7 @@ public class TaskletStep extends AbstractStep implements Step, InitializingBean, * * @param listeners an array of listener objects of known types. */ - public void setStepListeners(StepListener[] listeners) { + public void setStepListeners(StepExecutionListener[] listeners) { for (int i = 0; i < listeners.length; i++) { this.listener.register(listeners[i]); } @@ -86,8 +86,8 @@ public class TaskletStep extends AbstractStep implements Step, InitializingBean, public void afterPropertiesSet() throws Exception { Assert.notNull(jobRepository, "JobRepository is mandatory for TaskletStep"); Assert.notNull(tasklet, "Tasklet is mandatory for TaskletStep"); - if (tasklet instanceof StepListener) { - listener.register((StepListener) tasklet); + if (tasklet instanceof StepExecutionListener) { + listener.register((StepExecutionListener) tasklet); } } 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 6441a228a..18f1d6375 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 @@ -32,7 +32,7 @@ import org.springframework.batch.core.StartLimitExceededException; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; -import org.springframework.batch.core.listener.JobListenerSupport; +import org.springframework.batch.core.listener.JobExecutionListenerSupport; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.dao.JobExecutionDao; import org.springframework.batch.core.repository.dao.JobInstanceDao; @@ -173,7 +173,7 @@ public class SimpleJobTests extends TestCase { } public void testRunNormallyWithListener() throws Exception { - job.setJobListeners(new JobListenerSupport[] { new JobListenerSupport() { + job.setJobListeners(new JobExecutionListenerSupport[] { new JobExecutionListenerSupport() { public void beforeJob(JobExecution jobExecution) { list.add("before"); } @@ -251,7 +251,7 @@ public class SimpleJobTests extends TestCase { } public void testFailedWithListener() throws Exception { - job.setJobListeners(new JobListenerSupport[] { new JobListenerSupport() { + job.setJobListeners(new JobExecutionListenerSupport[] { new JobExecutionListenerSupport() { public void onError(JobExecution jobExecution, Throwable t) { list.add(t); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobExecutionListenerTests.java similarity index 63% rename from spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobListenerTests.java rename to spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobExecutionListenerTests.java index fef028518..b48a34ae9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeJobExecutionListenerTests.java @@ -22,31 +22,31 @@ import junit.framework.TestCase; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobListener; +import org.springframework.batch.core.JobExecutionListener; import org.springframework.batch.core.job.JobSupport; -import org.springframework.batch.core.listener.CompositeJobListener; -import org.springframework.batch.core.listener.JobListenerSupport; +import org.springframework.batch.core.listener.CompositeExecutionJobListener; +import org.springframework.batch.core.listener.JobExecutionListenerSupport; /** * @author Dave Syer * */ -public class CompositeJobListenerTests extends TestCase { +public class CompositeJobExecutionListenerTests extends TestCase { - private CompositeJobListener listener = new CompositeJobListener(); + private CompositeExecutionJobListener listener = new CompositeExecutionJobListener(); private List list = new ArrayList(); /** * Test method for - * {@link org.springframework.batch.core.listener.CompositeJobListener#setListeners(org.springframework.batch.core.JobListener[])}. + * {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#setListeners(org.springframework.batch.core.JobExecutionListener[])}. */ public void testSetListeners() { - listener.setListeners(new JobListener[] { new JobListenerSupport() { + listener.setListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() { public void afterJob(JobExecution jobExecution) { list.add("fail"); } - }, new JobListenerSupport() { + }, new JobExecutionListenerSupport() { public void afterJob(JobExecution jobExecution) { list.add("continue"); } @@ -57,10 +57,10 @@ public class CompositeJobListenerTests extends TestCase { /** * Test method for - * {@link org.springframework.batch.core.listener.CompositeJobListener#registerListener(org.springframework.batch.core.JobListener)}. + * {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#registerListener(org.springframework.batch.core.JobExecutionListener)}. */ public void testSetListener() { - listener.register(new JobListenerSupport() { + listener.register(new JobExecutionListenerSupport() { public void afterJob(JobExecution jobExecution) { list.add("fail"); } @@ -71,10 +71,10 @@ public class CompositeJobListenerTests extends TestCase { /** * Test method for - * {@link org.springframework.batch.core.listener.CompositeJobListener#beforeJob(JobExecution)}. + * {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#beforeJob(JobExecution)}. */ public void testOpen() { - listener.register(new JobListenerSupport() { + listener.register(new JobExecutionListenerSupport() { public void beforeJob(JobExecution stepExecution) { list.add("foo"); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java similarity index 72% rename from spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepListenerTests.java rename to spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java index 50b3dae61..efa6ed491 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java @@ -21,9 +21,9 @@ import java.util.List; import junit.framework.TestCase; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; -import org.springframework.batch.core.listener.CompositeStepListener; -import org.springframework.batch.core.listener.StepListenerSupport; +import org.springframework.batch.core.StepExecutionListener; +import org.springframework.batch.core.listener.CompositeStepExecutionListener; +import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.step.StepSupport; import org.springframework.batch.repeat.ExitStatus; @@ -31,23 +31,23 @@ import org.springframework.batch.repeat.ExitStatus; * @author Dave Syer * */ -public class CompositeStepListenerTests extends TestCase { +public class CompositeStepExecutionListenerTests extends TestCase { - private CompositeStepListener listener = new CompositeStepListener(); + private CompositeStepExecutionListener listener = new CompositeStepExecutionListener(); private List list = new ArrayList(); /** * Test method for - * {@link org.springframework.batch.core.listener.CompositeStepListener#setListeners(org.springframework.batch.core.StepListener[])}. + * {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#setListeners(org.springframework.batch.core.StepExecutionListener[])}. */ public void testSetListeners() { - listener.setListeners(new StepListener[] { new StepListenerSupport() { + listener.setListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() { public ExitStatus afterStep(StepExecution stepExecution) { list.add("fail"); return ExitStatus.FAILED; } - }, new StepListenerSupport() { + }, new StepExecutionListenerSupport() { public ExitStatus afterStep(StepExecution stepExecution) { list.add("continue"); return ExitStatus.CONTINUABLE; @@ -59,10 +59,10 @@ public class CompositeStepListenerTests extends TestCase { /** * Test method for - * {@link org.springframework.batch.core.listener.CompositeStepListener#registerListener(org.springframework.batch.core.StepListener)}. + * {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#registerListener(org.springframework.batch.core.StepExecutionListener)}. */ public void testSetListener() { - listener.register(new StepListenerSupport() { + listener.register(new StepExecutionListenerSupport() { public ExitStatus afterStep(StepExecution stepExecution) { list.add("fail"); return ExitStatus.FAILED; @@ -74,10 +74,10 @@ public class CompositeStepListenerTests extends TestCase { /** * Test method for - * {@link org.springframework.batch.core.listener.CompositeStepListener#beforeStep(StepExecution)}. + * {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#beforeStep(StepExecution)}. */ public void testOpen() { - listener.register(new StepListenerSupport() { + listener.register(new StepExecutionListenerSupport() { public void beforeStep(StepExecution stepExecution) { list.add("foo"); } @@ -88,10 +88,10 @@ public class CompositeStepListenerTests extends TestCase { /** * Test method for - * {@link org.springframework.batch.core.listener.CompositeStepListener#beforeStep(StepExecution)}. + * {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#beforeStep(StepExecution)}. */ public void testOnError() { - listener.register(new StepListenerSupport() { + listener.register(new StepExecutionListenerSupport() { public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { list.add("foo"); return null; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java index 3df28a024..444da9def 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java @@ -29,10 +29,10 @@ import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.job.JobSupport; -import org.springframework.batch.core.listener.StepListenerSupport; +import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.repository.dao.MapJobExecutionDao; import org.springframework.batch.core.repository.dao.MapJobInstanceDao; import org.springframework.batch.core.repository.dao.MapStepExecutionDao; @@ -231,7 +231,7 @@ public class ItemOrientedStepTests extends TestCase { }; itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter)); - itemOrientedStep.registerStepListener(new StepListenerSupport() { + itemOrientedStep.registerStepListener(new StepExecutionListenerSupport() { public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { return ExitStatus.FAILED.addExitDescription("FOO"); } @@ -394,7 +394,7 @@ public class ItemOrientedStepTests extends TestCase { } public void testDirectlyInjectedListener() throws Exception { - itemOrientedStep.registerStepListener(new StepListenerSupport() { + itemOrientedStep.registerStepListener(new StepExecutionListenerSupport() { public void beforeStep(StepExecution stepExecution) { list.add("foo"); } @@ -431,7 +431,7 @@ public class ItemOrientedStepTests extends TestCase { final ExitStatus customStatus = new ExitStatus(false, "custom code"); - itemOrientedStep.setStepListeners(new StepListener[] { new StepListenerSupport() { + itemOrientedStep.setStepListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() { public ExitStatus afterStep(StepExecution stepExecution) { list.add("afterStepCalled"); return customStatus; @@ -452,7 +452,7 @@ public class ItemOrientedStepTests extends TestCase { } public void testDirectlyInjectedListenerOnError() throws Exception { - itemOrientedStep.registerStepListener(new StepListenerSupport() { + itemOrientedStep.registerStepListener(new StepExecutionListenerSupport() { public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) { list.add(e); return null; @@ -725,7 +725,7 @@ public class ItemOrientedStepTests extends TestCase { return str.indexOf(searchStr) != -1; } - private class MockRestartableItemReader extends ItemStreamSupport implements ItemReader, StepListener { + private class MockRestartableItemReader extends ItemStreamSupport implements ItemReader, StepExecutionListener { private boolean getExecutionAttributesCalled = false; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java index 89afa3479..40bd5d3eb 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java @@ -23,7 +23,7 @@ import java.util.List; import junit.framework.TestCase; -import org.springframework.batch.core.BatchListener; +import org.springframework.batch.core.StepListener; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.JobExecution; @@ -141,7 +141,7 @@ public class SimpleStepFactoryBeanTests extends TestCase { throw new RuntimeException("Error!"); } }); - factory.setListeners(new BatchListener[] { new ItemListenerSupport() { + factory.setListeners(new StepListener[] { new ItemListenerSupport() { public void onReadError(Exception ex) { recovered.add(ex); } @@ -207,7 +207,7 @@ public class SimpleStepFactoryBeanTests extends TestCase { } } CountingChunkListener chunkListener = new CountingChunkListener(); - factory.setListeners(new BatchListener[]{ chunkListener }); + factory.setListeners(new StepListener[]{ chunkListener }); factory.setCommitInterval(commitInterval); ItemOrientedStep step = (ItemOrientedStep) factory.getObject(); 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 49c0a0c71..1b47edc8a 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 @@ -12,9 +12,9 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.job.JobSupport; -import org.springframework.batch.core.listener.StepListenerSupport; +import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.step.JobRepositorySupport; import org.springframework.batch.core.step.StepSupport; import org.springframework.batch.core.step.tasklet.Tasklet; @@ -109,7 +109,7 @@ public class TaskletStepTests extends TestCase { public void testSuccessfulExecutionWithListener() throws Exception { TaskletStep step = new TaskletStep(new StubTasklet(false, false), new JobRepositorySupport()); - step.setStepListeners(new StepListener[] { new StepListenerSupport() { + step.setStepListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() { public void beforeStep(StepExecution context) { list.add("open"); } @@ -169,7 +169,7 @@ public class TaskletStepTests extends TestCase { } } - private class StubTasklet extends StepListenerSupport implements Tasklet { + private class StubTasklet extends StepExecutionListenerSupport implements Tasklet { private final boolean exitFailure; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/reader/StagingItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/reader/StagingItemReader.java index f1ed32cdc..43488302a 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/reader/StagingItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/reader/StagingItemReader.java @@ -10,7 +10,7 @@ import org.apache.commons.lang.SerializationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; @@ -25,7 +25,7 @@ import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; -public class StagingItemReader extends JdbcDaoSupport implements ItemStream, ItemReader, StepListener { +public class StagingItemReader extends JdbcDaoSupport implements ItemStream, ItemReader, StepExecutionListener { // Key for buffer in transaction synchronization manager private static final String BUFFER_KEY = StagingItemReader.class.getName() + ".BUFFER"; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/writer/StagingItemWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/writer/StagingItemWriter.java index 1db096a2e..729d52a2d 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/writer/StagingItemWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/item/writer/StagingItemWriter.java @@ -6,7 +6,7 @@ import java.sql.SQLException; import org.apache.commons.lang.SerializationUtils; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepListener; +import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ClearFailedException; import org.springframework.batch.item.FlushFailedException; import org.springframework.batch.item.ItemWriter; @@ -19,7 +19,7 @@ import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -public class StagingItemWriter extends JdbcDaoSupport implements StepListener, ItemWriter { +public class StagingItemWriter extends JdbcDaoSupport implements StepExecutionListener, ItemWriter { public static final String NEW = "N"; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java index 1b76b5617..bdcf67654 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java @@ -19,7 +19,7 @@ package org.springframework.batch.sample.tasklet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.listener.StepListenerSupport; +import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.ExitStatus; @@ -31,7 +31,7 @@ import org.springframework.batch.repeat.ExitStatus; * @author Lucas Ward * */ -public class InfiniteLoopTasklet extends StepListenerSupport implements Tasklet { +public class InfiniteLoopTasklet extends StepExecutionListenerSupport implements Tasklet { private StepExecution stepExecution; private int count = 0;