OPEN - issue BATCH-324: Step as factory for StepExecutor

http://jira.springframework.org/browse/BATCH-324

Same treatment for JobExecutor - roll it up into the Job interface
This commit is contained in:
dsyer
2008-01-29 18:07:57 +00:00
parent 3d7f40ca90
commit 911e368a71
64 changed files with 486 additions and 581 deletions

View File

@@ -1,34 +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.core.domain;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
/**
* Interface for running a job.
*
* @author Lucas Ward
* @author Dave Syer
* @see Job
* @see JobExecution
*/
public interface JobExecutor {
public ExitStatus run(Job job, JobExecution execution) throws BatchCriticalException;
}

View File

@@ -19,6 +19,8 @@ package org.springframework.batch.core.domain;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.util.ClassUtils;
@@ -31,7 +33,7 @@ import org.springframework.util.ClassUtils;
* @author Lucas Ward
* @author Dave Syer
*/
public class Job implements BeanNameAware {
public class JobSupport implements BeanNameAware, Job {
private List steps = new ArrayList();
@@ -44,7 +46,7 @@ public class Job implements BeanNameAware {
/**
* Default constructor.
*/
public Job() {
public JobSupport() {
super();
}
@@ -54,7 +56,7 @@ public class Job implements BeanNameAware {
*
* @param name
*/
public Job(String name) {
public JobSupport(String name) {
super();
this.name = name;
}
@@ -84,10 +86,16 @@ public class Job implements BeanNameAware {
this.name = name;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getName()
*/
public String getName() {
return name;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getSteps()
*/
public List getSteps() {
return steps;
}
@@ -101,6 +109,9 @@ public class Job implements BeanNameAware {
this.steps.add(step);
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getStartLimit()
*/
public int getStartLimit() {
return startLimit;
}
@@ -113,11 +124,21 @@ public class Job implements BeanNameAware {
this.restartable = restartable;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#isRestartable()
*/
public boolean isRestartable() {
return restartable;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.Job#run(org.springframework.batch.core.domain.JobExecution)
*/
public ExitStatus run(JobExecution execution) throws BatchCriticalException {
throw new UnsupportedOperationException("JobSupport does not provide an implementation of run(). Use a smarter subclass.");
}
public String toString() {
return ClassUtils.getShortName(Job.class) + ": [name=" + name + "]";
return ClassUtils.getShortName(JobSupport.class) + ": [name=" + name + "]";
}
}

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.batch.core.domain;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
/**
* Batch domain interface representing the configuration of a step. As with the
@@ -52,8 +55,16 @@ public interface Step {
int getStartLimit();
/**
* @return a {@link StepExecutor} that could be used to execute this step
* It is not safe to re-use an instance of {@link StepExecutor} to process
* multiple concurrent executions. Use the factory method in {@link Step} to
* create a new instance and execute that.
*
* @param stepExecution an entity representing the step to be executed
*
* @throws StepInterruptedException if the step is interrupted externally
* @throws BatchCriticalException if there is a problem that needs to be
* signalled to the caller
*/
StepExecutor createStepExecutor();
ExitStatus process(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException;
}

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.core.domain;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
/**
* Interface for processing a step. Implementations are free to process the step
* and return when finished, or to schedule the step for processing
* concurrently, or in the future. The status of the execution should be
* trackable with the step execution. The step should be treated as immutable.<br/>
*
* Because step execution parameters and policies can vary from step to step, a
* {@link StepExecutor} should be created by the caller using a {@link Step}.
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public interface StepExecutor {
/**
* It is not safe to re-use an instance of {@link StepExecutor} to process
* multiple concurrent executions. Use the factory method in {@link Step} to
* create a new instance and execute that.
*
* @param stepExecution an entity representing the step to be executed
*
* @throws StepInterruptedException if the step is interrupted externally
* @throws BatchCriticalException if there is a problem that needs to be
* signalled to the caller
*/
ExitStatus process(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException;
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.batch.core.domain;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.beans.factory.BeanNameAware;
/**
@@ -133,10 +134,11 @@ public class StepSupport implements Step, BeanNameAware {
*
* @throws UnsupportedOperationException always
*
* @see org.springframework.batch.core.domain.Step#createStepExecutor()
* @see org.springframework.batch.core.domain.Step#process(org.springframework.batch.core.domain.StepExecution)
*/
public StepExecutor createStepExecutor() {
public org.springframework.batch.repeat.ExitStatus process(StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
throw new UnsupportedOperationException(
"Cannot create a StepExecutor. Use a smarter subclass of StepSupport like a SimpleStep.");
"Cannot process a StepExecution. Use a smarter subclass of StepSupport.");
}
}

View File

@@ -15,11 +15,11 @@
*/
package org.springframework.batch.core.repository;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
/**
* Checked exception that indicates a name clash when registering
* {@link Job} instances.
* {@link JobSupport} instances.
*
* @author Dave Syer
*

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.batch.core.repository;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
/**
* Base class for checked exceptions related to {@link Job}
* Base class for checked exceptions related to {@link JobSupport}
* creation, registration or use.
*
* @author Dave Syer

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.core.repository;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
/**
* A runtime service locator interface for retrieving job configurations by
@@ -27,11 +28,11 @@ import org.springframework.batch.core.domain.Job;
public interface JobLocator {
/**
* Locates a {@link Job} at runtime.
* Locates a {@link JobSupport} at runtime.
*
* @param name the name of the {@link Job} which should be
* @param name the name of the {@link JobSupport} which should be
* unique
* @return a {@link Job} identified by the given name
* @return a {@link JobSupport} identified by the given name
*
* @throws NoSuchJobException if the required configuratio can
* not be found.

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.core.repository;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
/**
* A runtime service registry interface for registering job configurations by
@@ -27,9 +28,9 @@ import org.springframework.batch.core.domain.Job;
public interface JobRegistry extends JobLocator {
/**
* Registers a {@link Job} at runtime.
* Registers a {@link JobSupport} at runtime.
*
* @param jobConfiguration the {@link Job} to be registered
* @param jobConfiguration the {@link JobSupport} to be registered
*
* @throws DuplicateJobException if a configuration with the
* same name has already been registered.
@@ -37,10 +38,10 @@ public interface JobRegistry extends JobLocator {
void register(Job jobConfiguration) throws DuplicateJobException;
/**
* Unregisters a previously registered {@link Job}. If it was
* Unregisters a previously registered {@link JobSupport}. If it was
* not previously registered there is no error.
*
* @param jobConfiguration the {@link Job} to unregister.
* @param jobConfiguration the {@link JobSupport} to unregister.
*/
void unregister(Job jobConfiguration);
}

View File

@@ -17,7 +17,7 @@ package org.springframework.batch.core.repository;
import java.util.Collection;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
/**
* A listable extension of {@link JobRegistry}.
@@ -31,7 +31,7 @@ public interface ListableJobRegistry extends JobRegistry {
* Provides the currently registered configurations. The return value is
* unmodifiable and disconnected from the underlying registry storage.
*
* @return a collection of {@link Job} instances. Empty if none
* @return a collection of {@link JobSupport} instances. Empty if none
* are registered.
*/
Collection getJobConfigurations();

View File

@@ -15,11 +15,11 @@
*/
package org.springframework.batch.core.repository;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
/**
* Checked exception to indicate that a required {@link Job} is not
* Checked exception to indicate that a required {@link JobSupport} is not
* available.
*
* @author Dave Syer