OPEN - issue BATCH-378: RepeatListener is confusing and too generic to use for 'intercepting' a step
http://jira.springframework.org/browse/BATCH-378 Remove unnecessary listener implementations and migrate some functionality to samples. In the process discovered that tasklet steps cannot be stopped.
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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.repeat.interceptor;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatListener;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ApplicationEventPublisherRepeatListener implements ApplicationEventPublisherAware, RepeatListener {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
|
||||
*/
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#after(org.springframework.batch.repeat.RepeatContext,
|
||||
* java.lang.Object)
|
||||
*/
|
||||
public void after(RepeatContext context, ExitStatus result) {
|
||||
publish(context, "After repeat callback with result=[" + result + "]", RepeatOperationsApplicationEvent.AFTER);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#before(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void before(RepeatContext context) {
|
||||
publish(context, "Before repeat callback", RepeatOperationsApplicationEvent.BEFORE);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#close(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void close(RepeatContext context) {
|
||||
publish(context, "Closed repeat context with batch complete", RepeatOperationsApplicationEvent.CLOSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#onError(org.springframework.batch.repeat.RepeatContext,
|
||||
* java.lang.Throwable)
|
||||
*/
|
||||
public void onError(RepeatContext context, Throwable e) {
|
||||
publish(context, "Error in repeat operations with Throwable type=["+e.getClass()+"], message=["+e.getMessage()+"]", RepeatOperationsApplicationEvent.ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatInterceptor#open(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public void open(RepeatContext context) {
|
||||
publish(context, "Repeat operations opened", RepeatOperationsApplicationEvent.OPEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a {@link RepeatOperationsApplicationEvent} with the given
|
||||
* parameters.
|
||||
*
|
||||
* @param context the current batch context
|
||||
* @param message the message to publish
|
||||
* @param type the type of event to publish
|
||||
*/
|
||||
private void publish(RepeatContext context, String message, int type) {
|
||||
applicationEventPublisher.publishEvent(new RepeatOperationsApplicationEvent(context, message, type));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.repeat.interceptor;
|
||||
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class RepeatOperationsApplicationEvent extends ApplicationEvent {
|
||||
|
||||
public static final int AFTER = 3;
|
||||
|
||||
public static final int BEFORE = 2;
|
||||
|
||||
public static final int CLOSE = 4;
|
||||
|
||||
public static final int OPEN = 1;
|
||||
|
||||
public static final int ERROR = 5;
|
||||
|
||||
final private int type;
|
||||
|
||||
final private String message;
|
||||
|
||||
/**
|
||||
* Constructor for {@link RepeatOperationsApplicationEvent}.
|
||||
*
|
||||
* @param source the source of the event. Normally the current
|
||||
* {@link RepeatContext} if there is one.
|
||||
*/
|
||||
public RepeatOperationsApplicationEvent(Object source, String message, int type) {
|
||||
super(source);
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.EventObject#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return ClassUtils.getShortName(getClass())+": type="+type+"; message="+message;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user