BATCH-295: JobLauncher now only contains one method: run(Job, JobInstanceProperties). Misc. other changes were made to facilitate.

This commit is contained in:
lucasward
2008-01-22 23:40:40 +00:00
parent 2e68e82e84
commit 4f69c324e6
9 changed files with 63 additions and 64 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.domain;
import java.io.Serializable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
@@ -42,6 +43,10 @@ public class Entity implements Serializable {
public Entity(Long id) {
super();
//Commented out because StepExecutions are still created in a disconnected
//manner. The Repository should create them, then this can be uncommented.
//Assert.notNull(id, "Entity id must not be null.");
this.id = id;
}

View File

@@ -19,6 +19,7 @@ package org.springframework.batch.core.domain;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import org.springframework.batch.repeat.ExitStatus;
@@ -54,8 +55,8 @@ public class JobExecution extends Entity {
* the job of which this execution is a part
*/
public JobExecution(JobInstance job, Long id) {
super(id);
this.jobInstance = job;
setId(id);
}
/**
@@ -140,7 +141,7 @@ public class JobExecution extends Entity {
* @param stepExecution
*/
public StepExecution createStepExecution(StepInstance stepInstance) {
StepExecution stepExecution = new StepExecution(stepInstance, this);
StepExecution stepExecution = new StepExecution(stepInstance, this, null);
this.stepExecutions.add(stepExecution);
return stepExecution;
}
@@ -153,10 +154,26 @@ public class JobExecution extends Entity {
}
/**
* Test if this {@link JobExecution} indicates that it is running.
* Test if this {@link JobExecution} indicates that it is running. It should
* be noted that this does not necessarily mean that it has been
* persisted as such yet.
* @return true if the end time is null
*/
public boolean isRunning() {
return endTime==null;
}
/**
* Stop the JobExecution, each StepExecution will be iterated through, calling
* setTermianteOnly, signaling to the StepExecutor currently running that it should
* be terminated.
*
*/
public void stop(){
for(Iterator it = stepExecutions.iterator();it.hasNext();){
StepExecution stepExecution = (StepExecution)it.next();
stepExecution.setTerminateOnly();
}
}
}

View File

@@ -19,6 +19,8 @@ package org.springframework.batch.core.domain;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.Assert;
/**
* Batch domain object representing a job instance. A job instance is defined as
@@ -33,7 +35,7 @@ public class JobInstance extends Entity {
private List stepInstances = new ArrayList();
private JobIdentifier identifier;
private JobInstanceProperties jobInstanceProperties;
private Job job;
@@ -42,21 +44,17 @@ public class JobInstance extends Entity {
private int jobExecutionCount;
public JobInstance(JobIdentifier jobIdentifier){
this.identifier = jobIdentifier;
public JobInstance(Long id, JobInstanceProperties jobInstanceProperties) {
super(id);
Assert.notNull(jobInstanceProperties, "JobInstanceProperties must not be null.");
this.jobInstanceProperties = jobInstanceProperties;
}
public JobInstance(JobIdentifier identifier, Long id, Job job) {
super();
setId(id);
this.identifier = identifier;
public JobInstance(Long id, JobInstanceProperties jobInstanceProperties, Job job){
this(id, jobInstanceProperties);
this.job = job;
}
public JobInstance(JobIdentifier jobIdentifier, Long id){
this(jobIdentifier, id, null);
}
public BatchStatus getStatus() {
return status;
}
@@ -64,7 +62,7 @@ public class JobInstance extends Entity {
public void setStatus(BatchStatus status) {
this.status = status;
}
public List getStepInstances() {
return stepInstances;
}
@@ -86,19 +84,17 @@ public class JobInstance extends Entity {
}
/**
* Public accessor for the identifier property.
*
* @return the identifier
* @return JobInstanceProperties
*/
public JobIdentifier getIdentifier() {
return identifier;
public JobInstanceProperties getJobInstanceProperties() {
return jobInstanceProperties;
}
/**
* @return the identifier name if there is one
* @return the job name. (Equivalent to getJob().getName())
*/
public String getName() {
return identifier==null ? null : identifier.getName();
public String getJobName() {
return getJob().getName();
}
public JobExecution createJobExecution() {
@@ -106,7 +102,8 @@ public class JobInstance extends Entity {
}
public String toString() {
return super.toString()+", identifier=["+identifier+"]";
return super.toString()+", JobInstanceProperties=["+ jobInstanceProperties +"]" +
", Job=[" + job + "]";
}
public Job getJob() {

View File

@@ -71,13 +71,12 @@ public class StepExecution extends Entity {
* @param jobExecution the current job execution
*/
public StepExecution(StepInstance step, JobExecution jobExecution, Long id) {
this();
super(id);
this.step = step;
this.jobExecution = jobExecution;
setId(id);
}
public StepExecution(StepInstance step, JobExecution jobExecution) {
public StepExecution(StepInstance step, JobExecution jobExecution){
this(step, jobExecution, null);
}

View File

@@ -20,6 +20,7 @@ import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -52,12 +53,9 @@ public interface JobRepository {
* 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 jobInstanceProperties TODO
* @param jobConfiguration
* describes the configuration for this job
* @param jobIdentifier
* identifies this particular run of the configuration across
* possible restarts
*
* @return a valid job execution for the identifier provided
* @throws JobExecutionAlreadyRunningException
@@ -65,8 +63,8 @@ public interface JobRepository {
* job instance that would otherwise be returned
*
*/
public JobExecution findOrCreateJob(Job job,
JobIdentifier jobIdentifier)
public JobExecution createJobExecution(Job job,
JobInstanceProperties jobInstanceProperties)
throws JobExecutionAlreadyRunningException;
/**