OPEN - issue BATCH-159: JobExecutor should return a JobExecution (which itself contains the ExitStatus)
http://opensource.atlassian.com/projects/spring/browse/BATCH-159 Add listeners to JobExecutionFacade
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.facade;
|
||||
|
||||
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.facade.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.facade.JobExecutionListener#before(org.springframework.batch.core.domain.JobExecution)
|
||||
*/
|
||||
public void before(JobExecution execution) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.batch.execution.facade;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.core.configuration.JobConfiguration;
|
||||
@@ -64,6 +67,18 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade,
|
||||
|
||||
private Object mutex = new Object();
|
||||
|
||||
private List listeners = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public setter for the listeners property.
|
||||
*
|
||||
* @param listeners
|
||||
* the listeners to set - a list of {@link JobExecutionListener}.
|
||||
*/
|
||||
public void setJobExecutionListeners(List listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public accessor for the running property.
|
||||
*
|
||||
@@ -158,7 +173,9 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade,
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal accounting for the job execution. Callback at start of job.
|
||||
* Internal accounting for the job execution. Callback at start of job,
|
||||
* dealing with internal housekeeping before delegating to listeners in the
|
||||
* order that they were given.
|
||||
*
|
||||
* @param execution
|
||||
*/
|
||||
@@ -166,14 +183,28 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade,
|
||||
synchronized (mutex) {
|
||||
running++;
|
||||
}
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
JobExecutionListener listener = (JobExecutionListener) iterator
|
||||
.next();
|
||||
listener.before(execution);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal accounting for the job execution. Callback at end of job.
|
||||
* Internal accounting for the job execution. Callback at end of job
|
||||
* delegating first to listeners, in reverse order to the list supplied, and
|
||||
* then finally dealing with internal housekeeping.
|
||||
*
|
||||
* @param execution
|
||||
*/
|
||||
public void after(JobExecution execution) {
|
||||
ArrayList reversed = new ArrayList(listeners);
|
||||
Collections.reverse(reversed);
|
||||
for (Iterator iterator = reversed.iterator(); iterator.hasNext();) {
|
||||
JobExecutionListener listener = (JobExecutionListener) iterator
|
||||
.next();
|
||||
listener.after(execution);
|
||||
}
|
||||
synchronized (mutex) {
|
||||
// assume execution is synchronous so when we get to here we are
|
||||
// not running any more
|
||||
|
||||
@@ -77,11 +77,6 @@ public class SimpleStepExecutor implements StepExecutor {
|
||||
*/
|
||||
private static final String STEP_EXECUTION_KEY = "STEP_EXECUTION";
|
||||
|
||||
/**
|
||||
* Attribute key for statistics instance in step context.
|
||||
*/
|
||||
public static final String STATISTICS_KEY = "STATISTICS";
|
||||
|
||||
private RepeatOperations chunkOperations = new RepeatTemplate();
|
||||
|
||||
private RepeatOperations stepOperations = new RepeatTemplate();
|
||||
@@ -239,8 +234,6 @@ public class SimpleStepExecutor implements StepExecutor {
|
||||
}
|
||||
Properties statistics = getStatistics(module);
|
||||
stepExecution.setStatistics(statistics);
|
||||
context.setAttribute(STATISTICS_KEY,
|
||||
statistics);
|
||||
stepExecution.incrementCommitCount();
|
||||
jobRepository.saveOrUpdate(stepExecution);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user