From 0734480dd6377640e504c2d5efed067b65dbe3a8 Mon Sep 17 00:00:00 2001 From: dsyer Date: Wed, 30 Jan 2008 09:13:41 +0000 Subject: [PATCH] Remove JobExecutionListener - doesn't do anything that an AOP listener on the Job couldn't do. --- .../ThreadInterruptJobExecutionListener.java | 80 ------------------ .../launch/JobExecutionListener.java | 50 ----------- .../launch/JobExecutionListenerSupport.java | 58 ------------- .../JobExecutionListenerSupportTests.java | 82 ------------------- 4 files changed, 270 deletions(-) delete mode 100644 spring-batch-execution/src/main/java/org/springframework/batch/execution/bootstrap/support/ThreadInterruptJobExecutionListener.java delete mode 100644 spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListener.java delete mode 100644 spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListenerSupport.java delete mode 100644 spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/JobExecutionListenerSupportTests.java diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/bootstrap/support/ThreadInterruptJobExecutionListener.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/bootstrap/support/ThreadInterruptJobExecutionListener.java deleted file mode 100644 index 19f847a0b..000000000 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/bootstrap/support/ThreadInterruptJobExecutionListener.java +++ /dev/null @@ -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--; - } - -} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListener.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListener.java deleted file mode 100644 index c440ca1eb..000000000 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListener.java +++ /dev/null @@ -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); -} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListenerSupport.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListenerSupport.java deleted file mode 100644 index 0cb1bf0d1..000000000 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/launch/JobExecutionListenerSupport.java +++ /dev/null @@ -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 - } - - - -} diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/JobExecutionListenerSupportTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/JobExecutionListenerSupportTests.java deleted file mode 100644 index 22032ecc6..000000000 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/JobExecutionListenerSupportTests.java +++ /dev/null @@ -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()); - } -}