Class StepContext
java.lang.Object
org.springframework.batch.repeat.context.SynchronizedAttributeAccessor
org.springframework.batch.core.scope.context.StepContext
- All Implemented Interfaces:
org.springframework.core.AttributeAccessor
A context object that can be used to interrogate the current
StepExecution and
some of its associated properties using expressions based on bean paths. Has public
getters for the step execution and convenience methods for accessing commonly used
properties like the ExecutionContext associated with the step or its enclosing
job execution.- Author:
- Dave Syer, Michael Minella, Mahmoud Ben Hassine, Nicolas Widart
-
Constructor Summary
ConstructorsConstructorDescriptionStepContext(StepExecution stepExecution) Create a new instance ofStepContextfor thisStepExecution. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Clean up the context at the end of a step execution.booleanExtend the base class method to include the step execution itself as a key (i.e.getId()Convenient accessor for currentJobInstanceidentifier.Convenient accessor for current job name identifier.The currentStepExecutionthat is active in this context.Convenient accessor for current step name identifier.Convenient accessor for System properties to make it easy to access them from placeholder expressions.inthashCode()Overrides the default behaviour to provide a hash code based only on the step execution.voidregisterDestructionCallback(String name, Runnable callback) Allow clients to register callbacks for clean up on close.removeAttribute(String name) Override base class behaviour to ensure destruction callbacks are unregistered as well as the default behaviour.toString()Methods inherited from class org.springframework.batch.repeat.context.SynchronizedAttributeAccessor
attributeNames, getAttribute, hasAttribute, setAttribute, setAttributeIfAbsentMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.AttributeAccessor
computeAttribute
-
Constructor Details
-
StepContext
Create a new instance ofStepContextfor thisStepExecution.- Parameters:
stepExecution- a step execution
-
-
Method Details
-
getStepName
Convenient accessor for current step name identifier. Usually this is the same as the bean name of the step that is executing (but might not be e.g. in a partition).- Returns:
- the step name identifier of the current
StepExecution
-
getJobName
Convenient accessor for current job name identifier.- Returns:
- the job name identifier of the enclosing
JobInstanceassociated with the currentStepExecution
-
getJobInstanceId
Convenient accessor for currentJobInstanceidentifier.- Returns:
- the identifier of the enclosing
JobInstanceassociated with the currentStepExecution
-
getSystemProperties
Convenient accessor for System properties to make it easy to access them from placeholder expressions.- Returns:
- the current System properties
-
getStepExecutionContext
- Returns:
- a map containing the items from the step
ExecutionContext
-
getJobExecutionContext
- Returns:
- a map containing the items from the job
ExecutionContext
-
getJobParameters
- Returns:
- a map containing the items from the
JobParameters
-
registerDestructionCallback
Allow clients to register callbacks for clean up on close.- Parameters:
name- the callback id (unique attribute key in this context)callback- a callback to execute on close
-
removeAttribute
Override base class behaviour to ensure destruction callbacks are unregistered as well as the default behaviour.- Specified by:
removeAttributein interfaceorg.springframework.core.AttributeAccessor- Overrides:
removeAttributein classSynchronizedAttributeAccessor- See Also:
-
close
public void close()Clean up the context at the end of a step execution. Must be called once at the end of a step execution to honour the destruction callback contract from theStepScope. -
getStepExecution
The currentStepExecutionthat is active in this context.- Returns:
- the current
StepExecution
-
getId
- Returns:
- unique identifier for this context based on the step execution
-
equals
Extend the base class method to include the step execution itself as a key (i.e. two contexts are only equal if their step executions are the same).- Overrides:
equalsin classSynchronizedAttributeAccessor- See Also:
-
hashCode
public int hashCode()Overrides the default behaviour to provide a hash code based only on the step execution.- Overrides:
hashCodein classSynchronizedAttributeAccessor- See Also:
-
toString
- Overrides:
toStringin classSynchronizedAttributeAccessor
-