IN PROGRESS - BATCH-127: Allow job configuration to control re-entrant behavior
http://opensource.atlassian.com/projects/spring/browse/BATCH-127 Added additional exception to signature of JobRepository.findOrCreate().
This commit is contained in:
@@ -47,10 +47,11 @@ import org.springframework.batch.core.domain.StepInstance;
|
||||
public interface JobRepository {
|
||||
|
||||
/**
|
||||
* Find or create a job for a given Job identifier or configuration. If the
|
||||
* job that is uniquely identified by JobIdentifier already exists, it's
|
||||
* persisted values (including ID) will be returned in a new Job object. If
|
||||
* no previous run is found, a new job will be created and returned.
|
||||
* Find or create a job for a given {@link JobIdentifier} and configuration.
|
||||
* If the job that is uniquely identified by {@link JobIdentifier} already
|
||||
* exists, its persisted values (including ID) will be returned in a new
|
||||
* {@link JobInstance} object. If no previous run is found, a new job will
|
||||
* be created and returned.
|
||||
*
|
||||
* @param jobConfiguration
|
||||
* describes the configuration for this job
|
||||
|
||||
@@ -41,9 +41,10 @@ interface JobExecutorFacade {
|
||||
* the identifier of the job to start
|
||||
*
|
||||
* @throws NoSuchJobConfigurationException
|
||||
* @throws JobExecutionAlreadyRunningException
|
||||
*/
|
||||
JobExecution createExecutionFrom(JobIdentifier jobIdentifier)
|
||||
throws NoSuchJobConfigurationException;
|
||||
throws NoSuchJobConfigurationException, JobExecutionAlreadyRunningException;
|
||||
|
||||
/**
|
||||
* Start a job execution.
|
||||
|
||||
@@ -139,7 +139,8 @@ class SimpleJobExecutorFacade implements JobExecutorFacade,
|
||||
* Locates a {@link JobConfiguration} by using the name of the provided
|
||||
* {@link JobIdentifier} and the {@link JobConfigurationLocator}.
|
||||
*
|
||||
* @param jobIdentifier the identifier of the job that is being prepared.
|
||||
* @param jobIdentifier
|
||||
* the identifier of the job that is being prepared.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the {@link JobIdentifier} is null or its name is null
|
||||
@@ -150,14 +151,15 @@ class SimpleJobExecutorFacade implements JobExecutorFacade,
|
||||
* @see org.springframework.batch.execution.launch.JobExecutorFacade#createExecutionFrom(org.springframework.batch.core.domain.JobIdentifier)
|
||||
*/
|
||||
public JobExecution createExecutionFrom(JobIdentifier jobIdentifier)
|
||||
throws NoSuchJobConfigurationException {
|
||||
throws NoSuchJobConfigurationException, JobExecutionAlreadyRunningException {
|
||||
Assert.notNull(jobIdentifier, "JobIdentifier must not be null.");
|
||||
Assert.notNull(jobIdentifier.getName(),
|
||||
"JobIdentifier name must not be null.");
|
||||
|
||||
Assert
|
||||
.state(!jobExecutionRegistry.containsKey(jobIdentifier),
|
||||
"A job with this JobRuntimeInformation is already executing in this container");
|
||||
if (jobExecutionRegistry.containsKey(jobIdentifier)) {
|
||||
throw new JobExecutionAlreadyRunningException(
|
||||
"A job with this JobIdentifier is already executing in this container: "+jobIdentifier);
|
||||
};
|
||||
|
||||
JobConfiguration jobConfiguration = jobConfigurationLocator
|
||||
.getJobConfiguration(jobIdentifier.getName());
|
||||
@@ -270,10 +272,11 @@ class SimpleJobExecutorFacade implements JobExecutorFacade,
|
||||
*
|
||||
* @see org.springframework.batch.container.BatchContainer#onStop(org.springframework.batch.container.common.runtime.JobRuntimeInformation)
|
||||
*/
|
||||
public void stop(JobExecution execution)
|
||||
throws NoSuchJobExecutionException {
|
||||
public void stop(JobExecution execution) throws NoSuchJobExecutionException {
|
||||
if (!jobExecutionRegistry.containsValue(execution)) {
|
||||
throw new NoSuchJobExecutionException("The job is not executing in this executor: ["+execution+"]");
|
||||
throw new NoSuchJobExecutionException(
|
||||
"The job is not executing in this executor: [" + execution
|
||||
+ "]");
|
||||
}
|
||||
for (Iterator iter = execution.getStepContexts().iterator(); iter
|
||||
.hasNext();) {
|
||||
|
||||
@@ -247,6 +247,21 @@ public class SimpleJobExecutorFacadeTests extends TestCase {
|
||||
assertTrue(statistics.containsKey("job1.step1"));
|
||||
}
|
||||
|
||||
public void testJobAlreadyExecutingLocally() throws Exception {
|
||||
SimpleJobIdentifier runtimeInformation = new SimpleJobIdentifier(
|
||||
"TestJob");
|
||||
JobExecution execution = new JobExecution(new JobInstance(
|
||||
runtimeInformation, new Long(0)));
|
||||
registerExecution(runtimeInformation, execution);
|
||||
try {
|
||||
jobExecutorFacade.createExecutionFrom(runtimeInformation);
|
||||
fail("Expected JobExecutionAlreadyRunningException");
|
||||
} catch (JobExecutionAlreadyRunningException e) {
|
||||
// expected
|
||||
assertTrue("Message does not contain TestJob: "+e.getMessage(), e.getMessage().indexOf("TestJob")>=0);
|
||||
}
|
||||
}
|
||||
|
||||
public void testListenersCalledLastOnStop() throws Exception {
|
||||
List listeners = new ArrayList();
|
||||
listeners.add(new JobExecutionListenerSupport() {
|
||||
|
||||
Reference in New Issue
Block a user