StepExecution详解
StepExecution详解
StepExecution源代码详解
根据StepExecution的构造方法可以看出,构造方法需要stepName、jobExecution,或者id。 从StepExecution的属性可以看出,StepExecution的属性有jobExecution、executionContext、exitStatus。
package org.springframework.batch.core;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.util.Assert;
public class StepExecution extends Entity {
private final JobExecution jobExecution;
private final String stepName;
private volatile BatchStatus status;
private volatile int readCount;
private volatile int writeCount;
private volatile int commitCount;
private volatile int rollbackCount;
private volatile int readSkipCount;
private volatile int processSkipCount;
private volatile int writeSkipCount;
private volatile Date startTime;
private volatile Date endTime;
private volatile Date lastUpdated;
private volatile ExecutionContext executionContext;
private volatile ExitStatus exitStatus;
private volatile boolean terminateOnly;
private volatile int filterCount;
private transient volatile List<Throwable> failureExceptions;
public StepExecution(String stepName, JobExecution jobExecution, Long id) {
this(stepName, jobExecution);
Assert.notNull(jobExecution, "JobExecution must be provided to re-hydrate an existing StepExecution");
Assert.notNull(id, "The entity Id must be provided to re-hydrate an existing StepExecution");
this.setId(id);
jobExecution.addStepExecution(this);
}
public StepExecution(String stepName, JobExecution jobExecution) {
this.status = BatchStatus.STARTING;
this.readCount = 0;
this.writeCount = 0;
this.commitCount = 0;
this.rollbackCount = 0;
this.readSkipCount = 0;
this.processSkipCount = 0;
this.writeSkipCount = 0;
this.startTime = new Date(System.currentTimeMillis());
this.endTime = null;
this.lastUpdated = null;
this.executionContext = new ExecutionContext();
this.exitStatus = ExitStatus.EXECUTING;
this.failureExceptions = new CopyOnWriteArrayList();
Assert.hasLength(stepName);
this.stepName = stepName;
this.jobExecution = jobExecution;
}
public ExecutionContext getExecutionContext() {
return this.executionContext;
}
public void setExecutionContext(ExecutionContext executionContext) {
this.executionContext = executionContext;
}
public int getCommitCount() {
return this.commitCount;
}
public void setCommitCount(int commitCount) {
this.commitCount = commitCount;
}
public Date getEndTime() {
return this.endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public int getReadCount() {
return this.readCount;
}
public void setReadCount(int readCount) {
this.readCount = readCount;
}
public int getWriteCount() {
return this.writeCount;
}
public void setWriteCount(int writeCount) {
this.writeCount = writeCount;
}
public int getRollbackCount() {
return this.rollbackCount;
}
public int getFilterCount() {
return this.filterCount;
}
public void setFilterCount(int filterCount) {
this.filterCount = filterCount;
}
public void setRollbackCount(int rollbackCount) {
this.rollbackCount = rollbackCount;
}
public Date getStartTime() {
return this.startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public BatchStatus getStatus() {
return this.status;
}
public void setStatus(BatchStatus status) {
this.status = status;
}
public void upgradeStatus(BatchStatus status) {
this.status = this.status.upgradeTo(status);
}
public String getStepName() {
return this.stepName;
}
public Long getJobExecutionId() {
return this.jobExecution != null ? this.jobExecution.getId() : null;
}
public void setExitStatus(ExitStatus exitStatus) {
this.exitStatus = exitStatus;
}
public ExitStatus getExitStatus() {
return this.exitStatus;
}
public JobExecution getJobExecution() {
return this.jobExecution;
}
public StepContribution createStepContribution() {
return new StepContribution(this);
}
public synchronized void apply(StepContribution contribution) {
this.readSkipCount += contribution.getReadSkipCount();
this.writeSkipCount += contribution.getWriteSkipCount();
this.processSkipCount += contribution.getProcessSkipCount();
this.filterCount += contribution.getFilterCount();
this.readCount += contribution.getReadCount();
this.writeCount += contribution.getWriteCount();
this.exitStatus = this.exitStatus.and(contribution.getExitStatus());
}
public synchronized void incrementRollbackCount() {
++this.rollbackCount;
}
public boolean isTerminateOnly() {
return this.terminateOnly;
}
public void setTerminateOnly() {
this.terminateOnly = true;
}
public int getSkipCount() {
return this.readSkipCount + this.processSkipCount + this.writeSkipCount;
}
public void incrementCommitCount() {
++this.commitCount;
}
public JobParameters getJobParameters() {
return this.jobExecution == null ? new JobParameters() : this.jobExecution.getJobParameters();
}
public int getReadSkipCount() {
return this.readSkipCount;
}
public int getWriteSkipCount() {
return this.writeSkipCount;
}
public void setReadSkipCount(int readSkipCount) {
this.readSkipCount = readSkipCount;
}
public void setWriteSkipCount(int writeSkipCount) {
this.writeSkipCount = writeSkipCount;
}
public int getProcessSkipCount() {
return this.processSkipCount;
}
public void setProcessSkipCount(int processSkipCount) {
this.processSkipCount = processSkipCount;
}
public Date getLastUpdated() {
return this.lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public List<Throwable> getFailureExceptions() {
return this.failureExceptions;
}
public void addFailureException(Throwable throwable) {
this.failureExceptions.add(throwable);
}
public boolean equals(Object obj) {
Object jobExecutionId = this.getJobExecutionId();
if (jobExecutionId != null && obj instanceof StepExecution && this.getId() != null) {
StepExecution other = (StepExecution)obj;
return this.stepName.equals(other.getStepName()) && jobExecutionId.equals(other.getJobExecutionId()) && this.getId().equals(other.getId());
} else {
return super.equals(obj);
}
}
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.failureExceptions = new ArrayList();
}
public int hashCode() {
Object jobExecutionId = this.getJobExecutionId();
Long id = this.getId();
return super.hashCode() + 31 * (this.stepName != null ? this.stepName.hashCode() : 0) + 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0) + 59 * (id != null ? id.hashCode() : 0);
}
public String toString() {
return String.format(this.getSummary() + ", exitDescription=%s", this.exitStatus.getExitDescription());
}
public String getSummary() {
return super.toString() + String.format(", name=%s, status=%s, exitStatus=%s, readCount=%d, filterCount=%d, writeCount=%d readSkipCount=%d, writeSkipCount=%d, processSkipCount=%d, commitCount=%d, rollbackCount=%d", this.stepName, this.status, this.exitStatus.getExitCode(), this.readCount, this.filterCount, this.writeCount, this.readSkipCount, this.writeSkipCount, this.processSkipCount, this.commitCount, this.rollbackCount);
}
}