OPEN - issue BATCH-303: Replace repeat contexts in core domain with boolean flag that can be checked by executors
http://jira.springframework.org/browse/BATCH-303
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
/**
|
||||
* Batch domain object representing the execution of a job.
|
||||
@@ -35,10 +34,6 @@ public class JobExecution extends Entity {
|
||||
|
||||
private transient Collection stepExecutions = new HashSet();
|
||||
|
||||
private transient Collection stepContexts = new HashSet();
|
||||
|
||||
private transient Collection chunkContexts = new HashSet();
|
||||
|
||||
private BatchStatus status = BatchStatus.STARTING;
|
||||
|
||||
private Date startTime = new Date(System.currentTimeMillis());
|
||||
@@ -123,86 +118,6 @@ public class JobExecution extends Entity {
|
||||
return exitStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the potentially multiple chunk contexts that are in
|
||||
* progress. In a single-threaded, sequential execution there would normally
|
||||
* be only one current chunk, but in more complicated scenarios there might
|
||||
* be multiple active contexts.
|
||||
*
|
||||
* @return all the chunk contexts that have been registered and not
|
||||
* unregistered. A collection of {@link RepeatContext} objects.
|
||||
*/
|
||||
public Collection getChunkContexts() {
|
||||
synchronized (chunkContexts) {
|
||||
return new HashSet(chunkContexts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the potentially multiple step contexts that are in progress.
|
||||
* In a single-threaded, sequential execution there would normally be only
|
||||
* one current step, but in more complicated scenarios there might be
|
||||
* multiple active contexts.
|
||||
*
|
||||
* @return all the step contexts that have been registered and not
|
||||
* unregistered. A collection of {@link RepeatContext} objects.
|
||||
*/
|
||||
public Collection getStepContexts() {
|
||||
synchronized (stepContexts) {
|
||||
return new HashSet(stepContexts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the start of a step, before any business logic is processed.
|
||||
*
|
||||
* @param context
|
||||
* the current step context.
|
||||
*/
|
||||
public void registerStepContext(RepeatContext stepContext) {
|
||||
synchronized (stepContexts) {
|
||||
this.stepContexts.add(stepContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the end of a step, after all business logic is processed, or in
|
||||
* the case of a failure.
|
||||
*
|
||||
* @param context
|
||||
* the current step context.
|
||||
*/
|
||||
public void unregisterStepContext(RepeatContext stepContext) {
|
||||
synchronized (stepContexts) {
|
||||
this.stepContexts.remove(stepContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the start of a chunk, before any business logic is processed.
|
||||
*
|
||||
* @param context
|
||||
* the current chunk context.
|
||||
*/
|
||||
public void registerChunkContext(RepeatContext chunkContext) {
|
||||
synchronized (chunkContexts) {
|
||||
this.chunkContexts.add(chunkContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the end of a chunk, after all business logic is processed, or
|
||||
* in the case of a failure.
|
||||
*
|
||||
* @param context
|
||||
* the current chunk context.
|
||||
*/
|
||||
public void unregisterChunkContext(RepeatContext chunkContext) {
|
||||
synchronized (chunkContexts) {
|
||||
this.chunkContexts.remove(chunkContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Job that is executing.
|
||||
*/
|
||||
@@ -224,8 +139,10 @@ public class JobExecution extends Entity {
|
||||
*
|
||||
* @param stepExecution
|
||||
*/
|
||||
public void registerStepExecution(StepExecution stepExecution) {
|
||||
public StepExecution createStepExecution(StepInstance stepInstance) {
|
||||
StepExecution stepExecution = new StepExecution(stepInstance, this);
|
||||
this.stepExecutions.add(stepExecution);
|
||||
return stepExecution;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.springframework.batch.core.domain;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
/**
|
||||
* Represents a contribution to a {@link StepExecution}, buffering changes
|
||||
* until they can be applied at a chunk boundary.
|
||||
@@ -28,22 +26,6 @@ import org.springframework.batch.repeat.RepeatContext;
|
||||
*/
|
||||
public class StepContribution {
|
||||
|
||||
/**
|
||||
* Key for destruction callback in StepContext for chunk.
|
||||
*/
|
||||
private static final String CHUNK_EXECUTION_CONTEXT_CALLBACK = "CHUNK_EXECUTION_CONTEXT_CALLBACK";
|
||||
|
||||
/**
|
||||
* Key for destruction callback in StepContext for step.
|
||||
*/
|
||||
private static final String STEP_EXECUTION_CONTEXT_CALLBACK = "STEP_EXECUTION_CONTEXT_CALLBACK";
|
||||
|
||||
/**
|
||||
* Context attribute key for step execution. Used by monitoring and managing
|
||||
* clients to inspect current step execution.
|
||||
*/
|
||||
private static final String STEP_EXECUTION_KEY = "STEP_EXECUTION";
|
||||
|
||||
private int taskCount = 0;
|
||||
|
||||
private StepExecution execution;
|
||||
@@ -75,34 +57,6 @@ public class StepContribution {
|
||||
return taskCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
*/
|
||||
public void registerChunkContext(final RepeatContext context) {
|
||||
execution.getJobExecution().registerChunkContext(context);
|
||||
context.registerDestructionCallback(CHUNK_EXECUTION_CONTEXT_CALLBACK, new Runnable() {
|
||||
public void run() {
|
||||
execution.getJobExecution().unregisterStepContext(context);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
*/
|
||||
public void registerStepContext(final RepeatContext context) {
|
||||
execution.getJobExecution().registerStepContext(context);
|
||||
context.registerDestructionCallback(STEP_EXECUTION_CONTEXT_CALLBACK, new Runnable() {
|
||||
public void run() {
|
||||
execution.getJobExecution().unregisterStepContext(context);
|
||||
}
|
||||
});
|
||||
// Add the step execution as an attribute so monitoring
|
||||
// clients can see it.
|
||||
context.setAttribute(STEP_EXECUTION_KEY, execution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the statistics properties.
|
||||
*
|
||||
@@ -135,4 +89,12 @@ public class StepContribution {
|
||||
return commitCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate call to the {@link StepExecution}.
|
||||
* @return the flag from the underlying execution
|
||||
*/
|
||||
public boolean isTerminateOnly() {
|
||||
return execution.isTerminateOnly();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ public class StepExecution extends Entity {
|
||||
|
||||
private ExitStatus exitStatus = ExitStatus.UNKNOWN;
|
||||
|
||||
private boolean terminateOnly;
|
||||
|
||||
/**
|
||||
* Package private constructor for Hibernate
|
||||
*/
|
||||
@@ -260,4 +262,19 @@ public class StepExecution extends Entity {
|
||||
rollbackCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return flag to indicate that an execution should halt
|
||||
*/
|
||||
public boolean isTerminateOnly() {
|
||||
return this.terminateOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag that will signal to an execution environment that this
|
||||
* execution (and its surrounding job) wishes to exit.
|
||||
*/
|
||||
public void setTerminateOnly() {
|
||||
this.terminateOnly = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user