Class JobContext
java.lang.Object
org.springframework.batch.repeat.context.SynchronizedAttributeAccessor
org.springframework.batch.core.scope.context.JobContext
- All Implemented Interfaces:
org.springframework.core.AttributeAccessor
A context object that can be used to interrogate the current
JobExecution
and
some of its associated properties using expressions based on bean paths. Has public
getters for the job execution and convenience methods for accessing commonly used
properties like the ExecutionContext
associated with the job execution.- Since:
- 3.0
- Author:
- Dave Syer, Jimmy Praet (create JobContext based on
StepContext
), Mahmoud Ben Hassine
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Clean up the context at the end of a step execution.boolean
Extend the base class method to include the job execution itself as a key (i.e. two contexts are only equal if their job executions are the same).getId()
The currentJobExecution
that is active in this context.Convenient accessor for current job name identifier.Convenient accessor for System properties to make it easy to access them from placeholder expressions.int
hashCode()
Overrides the default behaviour to provide a hash code based only on the job execution.void
registerDestructionCallback
(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, setAttributeIfAbsent
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.core.AttributeAccessor
computeAttribute
-
Constructor Details
-
JobContext
-
-
Method Details
-
getJobName
Convenient accessor for current job name identifier.- Returns:
- the job name identifier of the enclosing
JobInstance
associated with the currentJobExecution
-
getSystemProperties
Convenient accessor for System properties to make it easy to access them from placeholder expressions.- Returns:
- the current System properties
-
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:
removeAttribute
in interfaceorg.springframework.core.AttributeAccessor
- Overrides:
removeAttribute
in 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
. -
getJobExecution
The currentJobExecution
that is active in this context.- Returns:
- the current
JobExecution
-
getId
- Returns:
- unique identifier for this context based on the step execution
-
equals
Extend the base class method to include the job execution itself as a key (i.e. two contexts are only equal if their job executions are the same).- Overrides:
equals
in classSynchronizedAttributeAccessor
-
hashCode
public int hashCode()Overrides the default behaviour to provide a hash code based only on the job execution.- Overrides:
hashCode
in classSynchronizedAttributeAccessor
-
toString
- Overrides:
toString
in classSynchronizedAttributeAccessor
-