BATCH-378:Moved and renamed packages for listeners, added support objects, and tests, and removed the ItemFailureHandler.
This commit is contained in:
@@ -28,9 +28,9 @@ import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.JobListener;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.interceptor.CompositeJobListener;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier;
|
||||
import org.springframework.batch.execution.listener.CompositeJobListener;
|
||||
import org.springframework.batch.execution.scope.SimpleStepContext;
|
||||
import org.springframework.batch.execution.scope.StepContext;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.ChunkListener;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class CompositeChunkListener implements ChunkListener {
|
||||
|
||||
private List listeners = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public setter for the listeners.
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
public void setListeners(ChunkListener[] listeners) {
|
||||
this.listeners = Arrays.asList(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register additional listener.
|
||||
*
|
||||
* @param stepListener
|
||||
*/
|
||||
public void register(ChunkListener chunkListener) {
|
||||
if (!listeners.contains(chunkListener)) {
|
||||
listeners.add(chunkListener);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.ChunkListener#afterChunk()
|
||||
*/
|
||||
public void afterChunk() {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ChunkListener listener = (ChunkListener) iterator.next();
|
||||
listener.afterChunk();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.ChunkListener#beforeChunk()
|
||||
*/
|
||||
public void beforeChunk() {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ChunkListener listener = (ChunkListener) iterator.next();
|
||||
listener.beforeChunk();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.ChunkListener;
|
||||
import org.springframework.batch.core.domain.ItemReadListener;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class CompositeItemReadListener implements ItemReadListener {
|
||||
|
||||
private List listeners = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public setter for the listeners.
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
public void setListeners(ChunkListener[] listeners) {
|
||||
this.listeners = Arrays.asList(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register additional listener.
|
||||
*
|
||||
* @param itemReaderListener
|
||||
*/
|
||||
public void register(ItemReadListener itemReaderListener) {
|
||||
if (!listeners.contains(itemReaderListener)) {
|
||||
listeners.add(itemReaderListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void afterRead(Object item) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ItemReadListener listener = (ItemReadListener) iterator.next();
|
||||
listener.afterRead(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeRead() {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ItemReadListener listener = (ItemReadListener) iterator.next();
|
||||
listener.beforeRead();
|
||||
}
|
||||
}
|
||||
|
||||
public void onReadError(Exception ex) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ItemReadListener listener = (ItemReadListener) iterator.next();
|
||||
listener.onReadError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.ChunkListener;
|
||||
import org.springframework.batch.core.domain.ItemReadListener;
|
||||
import org.springframework.batch.core.domain.ItemWriteListener;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class CompositeItemWriteListener implements ItemWriteListener {
|
||||
|
||||
private List listeners = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public setter for the listeners.
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
public void setListeners(ChunkListener[] listeners) {
|
||||
this.listeners = Arrays.asList(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register additional listener.
|
||||
*
|
||||
* @param itemReaderListener
|
||||
*/
|
||||
public void register(ItemWriteListener itemReaderListener) {
|
||||
if (!listeners.contains(itemReaderListener)) {
|
||||
listeners.add(itemReaderListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void afterWrite() {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ItemWriteListener listener = (ItemWriteListener) iterator.next();
|
||||
listener.afterWrite();
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeWrite(Object item) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ItemWriteListener listener = (ItemWriteListener) iterator.next();
|
||||
listener.beforeWrite(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void onWriteError(Exception ex, Object item) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ItemWriteListener listener = (ItemWriteListener) iterator.next();
|
||||
listener.onWriteError(ex, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobListener;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class CompositeJobListener implements JobListener {
|
||||
|
||||
private List listeners = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public setter for the listeners.
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
public void setListeners(JobListener[] listeners) {
|
||||
this.listeners = Arrays.asList(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register additional listener.
|
||||
*
|
||||
* @param stepListener
|
||||
*/
|
||||
public void register(JobListener stepListener) {
|
||||
if (!listeners.contains(stepListener)) {
|
||||
listeners.add(stepListener);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#close()
|
||||
*/
|
||||
public void afterJob() {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
JobListener listener = (JobListener) iterator.next();
|
||||
listener.afterJob();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.core.domain.JobParameters)
|
||||
*/
|
||||
public void beforeJob(JobExecution jobExecution) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
JobListener listener = (JobListener) iterator.next();
|
||||
listener.beforeJob(jobExecution);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class CompositeStepListener implements StepListener {
|
||||
|
||||
private List listeners = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public setter for the listeners.
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
public void setListeners(StepListener[] listeners) {
|
||||
this.listeners = Arrays.asList(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register additional listener.
|
||||
*
|
||||
* @param stepListener
|
||||
*/
|
||||
public void register(StepListener stepListener) {
|
||||
if (!listeners.contains(stepListener)) {
|
||||
listeners.add(stepListener);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#close()
|
||||
*/
|
||||
public ExitStatus afterStep() {
|
||||
ExitStatus status = null;
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
StepListener listener = (StepListener) iterator.next();
|
||||
ExitStatus close = listener.afterStep();
|
||||
status = status!=null ? status.and(close): close;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.core.domain.JobParameters)
|
||||
*/
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
StepListener listener = (StepListener) iterator.next();
|
||||
listener.beforeStep(stepExecution);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#onError(java.lang.Throwable)
|
||||
*/
|
||||
public ExitStatus onErrorInStep(Throwable e) {
|
||||
ExitStatus status = null;
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
StepListener listener = (StepListener) iterator.next();
|
||||
ExitStatus close = listener.onErrorInStep(e);
|
||||
status = status!=null ? status.and(close): close;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -73,13 +73,13 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
private String createJobKey(JobParameters jobParameters) {
|
||||
|
||||
Map props = jobParameters.getParameters();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
stringBuilder.append(entry.toString() + ";");
|
||||
stringBuffer.append(entry.toString() + ";");
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,13 +15,11 @@
|
||||
*/
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import org.springframework.batch.core.domain.ItemFailureHandler;
|
||||
import org.springframework.batch.core.domain.ItemSkipPolicy;
|
||||
import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.execution.step.support.DefaultItemFailureHandler;
|
||||
import org.springframework.batch.execution.step.support.NeverSkipItemSkipPolicy;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
@@ -55,8 +53,6 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
|
||||
protected ItemSkipPolicy itemSkipPolicy = new NeverSkipItemSkipPolicy();
|
||||
|
||||
protected ItemFailureHandler itemFailureHandler = new DefaultItemFailureHandler();
|
||||
|
||||
protected String name;
|
||||
|
||||
protected int startLimit = Integer.MAX_VALUE;
|
||||
@@ -182,10 +178,6 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
this.itemSkipPolicy = itemSkipPolicy;
|
||||
}
|
||||
|
||||
public void setItemFailureHandler(ItemFailureHandler itemFailureHandler) {
|
||||
this.itemFailureHandler = itemFailureHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that all mandatory properties are set (the {@link JobRepository}).
|
||||
*
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Date;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.domain.BatchListener;
|
||||
import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
|
||||
@@ -24,9 +24,9 @@ import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.core.interceptor.CompositeStepListener;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.execution.listener.CompositeStepListener;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
|
||||
@@ -17,10 +17,10 @@ package org.springframework.batch.execution.step.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.domain.ItemFailureHandler;
|
||||
import org.springframework.batch.core.listener.ItemListenerSupport;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link ItemFailureHandler} interface that
|
||||
* Default implementation of the {@link ItemListenerSupport} class that
|
||||
* writes all exceptions via commons logging. Since generics can't be used to
|
||||
* ensure the list contains exceptions, any non exceptions will be logged out by
|
||||
* calling toString on the object.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.batch.core.domain.ItemFailureHandler;
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class DefaultItemFailureHandler implements ItemFailureHandler {
|
||||
public class DefaultItemFailureHandler extends ItemListenerSupport {
|
||||
|
||||
protected static final Log logger = LogFactory
|
||||
.getLog(DefaultItemFailureHandler.class);
|
||||
@@ -38,7 +38,7 @@ public class DefaultItemFailureHandler implements ItemFailureHandler {
|
||||
*
|
||||
* @see org.springframework.batch.core.domain.ItemFailureLog#log(java.util.List)
|
||||
*/
|
||||
public void handleReadFailure(Exception ex) {
|
||||
public void onReadError(Exception ex) {
|
||||
try {
|
||||
logger.error("Error encountered while reading", ex);
|
||||
} catch (Exception exception) {
|
||||
@@ -47,7 +47,7 @@ public class DefaultItemFailureHandler implements ItemFailureHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleWriteFailure(Object item, Exception ex) {
|
||||
public void onWriteError(Exception ex, Object item) {
|
||||
try {
|
||||
logger.error("Error encountered while writing item: [ " + item + "]", ex);
|
||||
} catch (Exception exception) {
|
||||
|
||||
@@ -15,15 +15,16 @@
|
||||
*/
|
||||
package org.springframework.batch.execution.step.support;
|
||||
|
||||
import org.springframework.batch.core.domain.BatchListener;
|
||||
import org.springframework.batch.core.domain.ChunkListener;
|
||||
import org.springframework.batch.core.domain.ItemReadListener;
|
||||
import org.springframework.batch.core.domain.ItemWriteListener;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.core.interceptor.CompositeChunkListener;
|
||||
import org.springframework.batch.core.interceptor.CompositeItemReadListener;
|
||||
import org.springframework.batch.core.interceptor.CompositeItemWriteListener;
|
||||
import org.springframework.batch.core.interceptor.CompositeStepListener;
|
||||
import org.springframework.batch.execution.listener.CompositeChunkListener;
|
||||
import org.springframework.batch.execution.listener.CompositeItemReadListener;
|
||||
import org.springframework.batch.execution.listener.CompositeItemWriteListener;
|
||||
import org.springframework.batch.execution.listener.CompositeStepListener;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
@@ -83,7 +84,7 @@ public class ListenerMulticaster implements ItemStream, StepListener, ChunkListe
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see org.springframework.batch.core.interceptor.CompositeStepListener#afterStep()
|
||||
* @see org.springframework.batch.execution.listener.CompositeStepListener#afterStep()
|
||||
*/
|
||||
public ExitStatus afterStep() {
|
||||
return stepListener.afterStep();
|
||||
@@ -91,7 +92,7 @@ public class ListenerMulticaster implements ItemStream, StepListener, ChunkListe
|
||||
|
||||
/**
|
||||
* @param stepExecution
|
||||
* @see org.springframework.batch.core.interceptor.CompositeStepListener#beforeStep(org.springframework.batch.core.domain.StepExecution)
|
||||
* @see org.springframework.batch.execution.listener.CompositeStepListener#beforeStep(org.springframework.batch.core.domain.StepExecution)
|
||||
*/
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
stepListener.beforeStep(stepExecution);
|
||||
@@ -100,7 +101,7 @@ public class ListenerMulticaster implements ItemStream, StepListener, ChunkListe
|
||||
/**
|
||||
* @param e
|
||||
* @return
|
||||
* @see org.springframework.batch.core.interceptor.CompositeStepListener#onErrorInStep(java.lang.Throwable)
|
||||
* @see org.springframework.batch.execution.listener.CompositeStepListener#onErrorInStep(java.lang.Throwable)
|
||||
*/
|
||||
public ExitStatus onErrorInStep(Throwable e) {
|
||||
return stepListener.onErrorInStep(e);
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.interceptor.JobListenerSupport;
|
||||
import org.springframework.batch.core.listener.JobListenerSupport;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier;
|
||||
import org.springframework.batch.execution.repository.SimpleJobRepository;
|
||||
|
||||
@@ -23,11 +23,12 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.domain.BatchListener;
|
||||
import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.ItemFailureHandler;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.listener.ItemListenerSupport;
|
||||
import org.springframework.batch.execution.job.SimpleJob;
|
||||
import org.springframework.batch.execution.repository.SimpleJobRepository;
|
||||
import org.springframework.batch.execution.repository.dao.MapJobExecutionDao;
|
||||
@@ -149,17 +150,19 @@ public class SimpleJobTests extends TestCase {
|
||||
throw new RuntimeException("Error!");
|
||||
}
|
||||
});
|
||||
step.setItemFailureHandler(new ItemFailureHandler(){
|
||||
|
||||
step.setListeners(new BatchListener[]{new ItemListenerSupport(){
|
||||
|
||||
public void handleReadFailure(Exception ex) {
|
||||
public void onReadError(Exception ex) {
|
||||
recovered.add(ex);
|
||||
}
|
||||
|
||||
public void handleWriteFailure(Object item, Exception ex) {
|
||||
public void onWriteError(Exception ex, Object item) {
|
||||
recovered.add(ex);
|
||||
}
|
||||
|
||||
});
|
||||
}});
|
||||
|
||||
step.afterPropertiesSet();
|
||||
job.setSteps(Collections.singletonList(step));
|
||||
|
||||
@@ -195,4 +198,5 @@ public class SimpleJobTests extends TestCase {
|
||||
}
|
||||
assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.core.domain.ChunkListener;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class CompositeChunkListenerTests extends TestCase {
|
||||
|
||||
MockControl listenerControl = MockControl.createControl(ChunkListener.class);
|
||||
|
||||
ChunkListener listener;
|
||||
CompositeChunkListener compositeListener;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
listener = (ChunkListener)listenerControl.getMock();
|
||||
compositeListener = new CompositeChunkListener();
|
||||
compositeListener.register(listener);
|
||||
}
|
||||
|
||||
public void testBeforeChunk(){
|
||||
|
||||
listener.beforeChunk();
|
||||
listenerControl.replay();
|
||||
compositeListener.beforeChunk();
|
||||
listenerControl.verify();
|
||||
}
|
||||
|
||||
public void testAfterChunk(){
|
||||
|
||||
listener.afterChunk();
|
||||
listenerControl.replay();
|
||||
compositeListener.afterChunk();
|
||||
listenerControl.verify();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.core.domain.ItemReadListener;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class CompositeItemReadListenerTests extends TestCase {
|
||||
|
||||
MockControl listenerControl = MockControl.createControl(ItemReadListener.class);
|
||||
|
||||
ItemReadListener listener;
|
||||
CompositeItemReadListener compositeListener;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
listener = (ItemReadListener)listenerControl.getMock();
|
||||
compositeListener = new CompositeItemReadListener();
|
||||
compositeListener.register(listener);
|
||||
}
|
||||
|
||||
public void testBeforeRead(){
|
||||
|
||||
listener.beforeRead();
|
||||
listenerControl.replay();
|
||||
compositeListener.beforeRead();
|
||||
listenerControl.verify();
|
||||
}
|
||||
|
||||
public void testAfterRead(){
|
||||
Object item = new Object();
|
||||
listener.afterRead(item);
|
||||
listenerControl.replay();
|
||||
compositeListener.afterRead(item);
|
||||
listenerControl.verify();
|
||||
}
|
||||
|
||||
public void testOnReadError(){
|
||||
|
||||
Exception ex = new Exception();
|
||||
listener.onReadError(ex);
|
||||
listenerControl.replay();
|
||||
compositeListener.onReadError(ex);
|
||||
listenerControl.verify();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.core.domain.ItemWriteListener;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class CompositeItemWriteListenerTests extends TestCase {
|
||||
|
||||
MockControl listenerControl = MockControl.createControl(ItemWriteListener.class);
|
||||
|
||||
ItemWriteListener listener;
|
||||
CompositeItemWriteListener compositeListener;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
listener = (ItemWriteListener)listenerControl.getMock();
|
||||
compositeListener = new CompositeItemWriteListener();
|
||||
compositeListener.register(listener);
|
||||
}
|
||||
|
||||
public void testBeforeWrite(){
|
||||
Object item = new Object();
|
||||
listener.beforeWrite(item);
|
||||
listenerControl.replay();
|
||||
compositeListener.beforeWrite(item);
|
||||
listenerControl.verify();
|
||||
}
|
||||
|
||||
public void testAfterWrite(){
|
||||
listener.afterWrite();
|
||||
listenerControl.replay();
|
||||
compositeListener.afterWrite();
|
||||
listenerControl.verify();
|
||||
}
|
||||
|
||||
public void testOnWriteError(){
|
||||
Object item = new Object();
|
||||
Exception ex = new Exception();
|
||||
listener.onWriteError(ex, item);
|
||||
listenerControl.replay();
|
||||
compositeListener.onWriteError(ex, item);
|
||||
listenerControl.verify();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobListener;
|
||||
import org.springframework.batch.core.listener.JobListenerSupport;
|
||||
import org.springframework.batch.execution.job.JobSupport;
|
||||
import org.springframework.batch.execution.listener.CompositeJobListener;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class CompositeJobListenerTests extends TestCase {
|
||||
|
||||
private CompositeJobListener listener = new CompositeJobListener();
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.listener.CompositeJobListener#setListeners(org.springframework.batch.core.domain.JobListener[])}.
|
||||
*/
|
||||
public void testSetListeners() {
|
||||
listener.setListeners(new JobListener[] { new JobListenerSupport() {
|
||||
public void afterJob() {
|
||||
list.add("fail");
|
||||
}
|
||||
}, new JobListenerSupport() {
|
||||
public void afterJob() {
|
||||
list.add("continue");
|
||||
}
|
||||
} });
|
||||
listener.afterJob();
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.listener.CompositeJobListener#setListener(org.springframework.batch.core.domain.JobListener)}.
|
||||
*/
|
||||
public void testSetListener() {
|
||||
listener.register(new JobListenerSupport() {
|
||||
public void afterJob() {
|
||||
list.add("fail");
|
||||
}
|
||||
});
|
||||
listener.afterJob();
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.listener.CompositeJobListener#beforeJob(JobExecution)}.
|
||||
*/
|
||||
public void testOpen() {
|
||||
listener.register(new JobListenerSupport() {
|
||||
public void beforeJob(JobExecution stepExecution) {
|
||||
list.add("foo");
|
||||
}
|
||||
});
|
||||
listener.beforeJob(new JobExecution(new JobInstance(new Long(11L), null, new JobSupport())));
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.execution.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepListener;
|
||||
import org.springframework.batch.core.listener.StepListenerSupport;
|
||||
import org.springframework.batch.execution.step.StepSupport;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class CompositeStepListenerTests extends TestCase {
|
||||
|
||||
private CompositeStepListener listener = new CompositeStepListener();
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.listener.CompositeStepListener#setListeners(org.springframework.batch.core.domain.StepListener[])}.
|
||||
*/
|
||||
public void testSetListeners() {
|
||||
listener.setListeners(new StepListener[] { new StepListenerSupport() {
|
||||
public ExitStatus afterStep() {
|
||||
list.add("fail");
|
||||
return ExitStatus.FAILED;
|
||||
}
|
||||
}, new StepListenerSupport() {
|
||||
public ExitStatus afterStep() {
|
||||
list.add("continue");
|
||||
return ExitStatus.CONTINUABLE;
|
||||
}
|
||||
} });
|
||||
assertFalse(listener.afterStep().isContinuable());
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.listener.CompositeStepListener#setListener(org.springframework.batch.core.domain.StepListener)}.
|
||||
*/
|
||||
public void testSetListener() {
|
||||
listener.register(new StepListenerSupport() {
|
||||
public ExitStatus afterStep() {
|
||||
list.add("fail");
|
||||
return ExitStatus.FAILED;
|
||||
}
|
||||
});
|
||||
assertFalse(listener.afterStep().isContinuable());
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.listener.CompositeStepListener#beforeStep(StepExecution)}.
|
||||
*/
|
||||
public void testOpen() {
|
||||
listener.register(new StepListenerSupport() {
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
list.add("foo");
|
||||
}
|
||||
});
|
||||
listener.beforeStep(new StepExecution(new StepSupport("foo"), null));
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.listener.CompositeStepListener#beforeStep(StepExecution)}.
|
||||
*/
|
||||
public void testOnError() {
|
||||
listener.register(new StepListenerSupport() {
|
||||
public ExitStatus onErrorInStep(Throwable e) {
|
||||
list.add("foo");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
listener.onErrorInStep(new RuntimeException());
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.domain.BatchListener;
|
||||
import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
@@ -29,7 +30,7 @@ import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepContribution;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.interceptor.StepListenerSupport;
|
||||
import org.springframework.batch.core.listener.StepListenerSupport;
|
||||
import org.springframework.batch.execution.job.JobSupport;
|
||||
import org.springframework.batch.execution.repository.SimpleJobRepository;
|
||||
import org.springframework.batch.execution.repository.dao.MapJobExecutionDao;
|
||||
@@ -371,7 +372,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testDirectlyInjectedListener() throws Exception {
|
||||
itemOrientedStep.setListeners(new Object[] {new StepListenerSupport() {
|
||||
itemOrientedStep.setListeners(new BatchListener[] {new StepListenerSupport() {
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
list.add("foo");
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.interceptor.StepListenerSupport;
|
||||
import org.springframework.batch.core.listener.StepListenerSupport;
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.execution.job.JobSupport;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
|
||||
Reference in New Issue
Block a user