OPEN - issue BATCH-378: RepeatListener is confusing and too generic to use for 'intercepting' a step

http://jira.springframework.org/browse/BATCH-378

Replace RepeatListener with StepListener in TaskletStep.
This commit is contained in:
dsyer
2008-02-28 14:23:24 +00:00
parent 2a25a7a636
commit e9d74d0088
8 changed files with 302 additions and 56 deletions

View File

@@ -20,15 +20,12 @@ import org.springframework.batch.repeat.ExitStatus;
/**
* @author Lucas Ward
* @author Dave Syer
*
*/
public interface StepInterceptor {
public interface StepListener {
void open(ExecutionContext executionContext);
void beforeChunk();
void afterChunk();
ExitStatus close();
}

View File

@@ -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.core.interceptor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.core.domain.StepListener;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer
*
*/
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);
}
/**
* Public setter for the listeners. The result will be as if
* {@link #setListeners(StepListener[])} was called with an array of length
* one.
*
* @param listener
*/
public void setListener(StepListener listener) {
setListeners(new StepListener[] {listener});
}
/**
* 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 close() {
ExitStatus status = ExitStatus.CONTINUABLE;
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
StepListener listener = (StepListener) iterator.next();
status = status.and(listener.close());
}
return status;
}
/*
* (non-Javadoc)
* @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.item.ExecutionContext)
*/
public void open(ExecutionContext executionContext) {
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
StepListener listener = (StepListener) iterator.next();
listener.open(executionContext);
}
}
}

View File

@@ -0,0 +1,41 @@
/*
* 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.interceptor;
import org.springframework.batch.core.domain.StepListener;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer
*
*/
public class StepListenerSupport implements StepListener {
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.StepListener#close()
*/
public ExitStatus close() {
return ExitStatus.CONTINUABLE;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.item.ExecutionContext)
*/
public void open(ExecutionContext executionContext) {
}
}