Remove JobExecutionListener - doesn't do anything that an AOP listener on the Job couldn't do.

This commit is contained in:
dsyer
2008-01-30 09:13:41 +00:00
parent 6ffefbc184
commit 0734480dd6
4 changed files with 0 additions and 270 deletions

View File

@@ -1,80 +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.execution.bootstrap.support;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.execution.launch.JobExecutionListener;
import org.springframework.batch.execution.launch.JobExecutionListenerSupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;
/**
* {@link JobExecutionListener} that will interrupt the Thread that the job was
* started in when the stop signal comes. Use only for a standalone process, not
* in an application server container.
*
* @author Dave Syer
*
*/
public class ThreadInterruptJobExecutionListener extends
JobExecutionListenerSupport {
private volatile Thread processingThread;
private int running = 0;
/**
* Save the current thread so it can be interrupted later. This may seem odd
* at first, however, a simple bootstrap requires that only one thread can
* kick off a container, and that the first thread that calls start is the
* 'processing thread'. If the container has already been started, no
* exception will be thrown.
*
* @see org.springframework.batch.execution.launch.JobExecutionListenerSupport#before(org.springframework.batch.core.domain.JobExecution)
*/
public void before(JobExecution execution) {
Assert.isTrue(running == 0,
"This listener only supports one job at at time.");
running++;
/*
* There is no reason to kick off a new thread, since only one thread
* should be processing at once. However, a handle to the thread is
* maintained to allow for interrupt
*/
processingThread = Thread.currentThread();
}
/**
* Interrupt the thread that is running the job if the {@link ExitStatus}
* indicates that it is still running.
*
* @see org.springframework.batch.execution.launch.JobExecutionListenerSupport#onStop(org.springframework.batch.core.domain.JobExecution)
*/
public void onStop(JobExecution execution) {
if (execution==null || execution.getExitStatus().isRunning()) {
processingThread.interrupt();
}
}
/**
* internal housekeeping.
*
* @see org.springframework.batch.execution.launch.JobExecutionListenerSupport#after(org.springframework.batch.core.domain.JobExecution)
*/
public void after(JobExecution execution) {
running--;
}
}

View File

@@ -1,50 +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.execution.launch;
import org.springframework.batch.core.domain.JobExecution;
/**
* Listener interface for the job execution lifecycle.
*
* @author Dave Syer
*
*/
public interface JobExecutionListener {
/**
* Callback for the start of a job, before any steps are processed.
*
* @param execution
* the current {@link JobExecution}
*/
void before(JobExecution execution);
/**
* Callback for the start of a job, after all steps are processed, or on an
* error.
*
* @param execution
*/
void after(JobExecution execution);
/**
* Callback for a job that has been stopped, or asked to stop.
*
* @param execution
*/
void onStop(JobExecution execution);
}

View File

@@ -1,58 +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.execution.launch;
import org.springframework.batch.core.domain.JobExecution;
/**
* Simple no-op implementation of {@link JobExecutionListener} which does
* nothing.
*
* @author Dave Syer
*
*/
public class JobExecutionListenerSupport implements JobExecutionListener {
/**
* No-op for subclasses to extend.
*
* @see org.springframework.batch.execution.launch.JobExecutionListener#after(org.springframework.batch.core.domain.JobExecution)
*/
public void after(JobExecution execution) {
// no-op
}
/**
* No-op for subclasses to extend.
*
* @see org.springframework.batch.execution.launch.JobExecutionListener#before(org.springframework.batch.core.domain.JobExecution)
*/
public void before(JobExecution execution) {
// no-op
}
/**
* No-op for subclasses to extend.
*
* @see org.springframework.batch.execution.launch.JobExecutionListener#onStop(org.springframework.batch.core.domain.JobExecution)
*/
public void onStop(JobExecution execution) {
// no-op
}
}

View File

@@ -1,82 +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.execution.launch;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.execution.launch.JobExecutionListener;
import org.springframework.batch.execution.launch.JobExecutionListenerSupport;
/**
* @author Dave Syer
*
*/
public class JobExecutionListenerSupportTests extends TestCase {
private List list = new ArrayList();
/**
* Test method for
* {@link org.springframework.batch.execution.launch.JobExecutionListenerSupport#after(org.springframework.batch.core.domain.JobExecution)}.
*/
public void testAfter() {
JobExecutionListener listener = new JobExecutionListenerSupport() {
public void after(JobExecution execution) {
super.after(execution);
list.add("after");
}
};
listener.after(null);
assertEquals(1, list.size());
}
/**
* Test method for
* {@link org.springframework.batch.execution.launch.JobExecutionListenerSupport#before(org.springframework.batch.core.domain.JobExecution)}.
*/
public void testBefore() {
JobExecutionListener listener = new JobExecutionListenerSupport() {
public void before(JobExecution execution) {
super.before(execution);
list.add("after");
}
};
listener.before(null);
assertEquals(1, list.size());
}
/**
* Test method for
* {@link org.springframework.batch.execution.launch.JobExecutionListenerSupport#before(org.springframework.batch.core.domain.JobExecution)}.
*/
public void testStop() {
JobExecutionListener listener = new JobExecutionListenerSupport() {
public void onStop(JobExecution execution) {
super.onStop(execution);
list.add("stop");
}
};
listener.onStop(null);
assertEquals(1, list.size());
}
}