org.springframework.batch.core.scope.context

## 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

      public class StepContext
      extends SynchronizedAttributeAccessor

  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

    Constructors
    Constructor and Description
    `StepContext(StepExecution stepExecution)` Create a new instance of `StepContext` for this `StepExecution`.
    `StepContext(StepExecution stepExecution, BatchPropertyContext propertyContext)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Clean up the context at the end of a step execution.
    `boolean` | `equals(java.lang.Object other)` Extend the base class method to include the step execution itself as a key (i.e.
    `java.lang.String` | `getId()`
    `java.util.Map<java.lang.String,java.lang.Object>` | `getJobExecutionContext()`
    `java.lang.Long` | `getJobInstanceId()` Convenient accessor for current `JobInstance` identifier.
    `java.lang.String` | `getJobName()` Convenient accessor for current job name identifier.
    `java.util.Map<java.lang.String,java.lang.Object>` | `getJobParameters()`
    `java.util.Map<java.lang.String,java.lang.Object>` | `getPartitionPlan()`
    `StepExecution` | `getStepExecution()` The current `StepExecution` that is active in this context.
    `java.util.Map<java.lang.String,java.lang.Object>` | `getStepExecutionContext()`
    `java.lang.String` | `getStepName()` Convenient accessor for current step name identifier.
    `java.util.Properties` | `getSystemProperties()` 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 step execution.
    `void` | `registerDestructionCallback(java.lang.String name, java.lang.Runnable callback)` Allow clients to register callbacks for clean up on close.
    `java.lang.Object` | `removeAttribute(java.lang.String name)` Override base class behaviour to ensure destruction callbacks are unregistered as well as the default behaviour.
    `java.lang.String` | `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`

- - ### Constructor Detail

    - #### StepContext

          public StepContext(StepExecution stepExecution)

      Create a new instance of `StepContext` for this `StepExecution`.
      Parameters:
        `stepExecution` - a step execution

    - #### StepContext

          public StepContext(StepExecution stepExecution,
                             BatchPropertyContext propertyContext)

  - ### Method Detail

    - #### getStepName

          public java.lang.String 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

          public java.lang.String getJobName()

      Convenient accessor for current job name identifier.
      Returns:
        the job name identifier of the enclosing `JobInstance` associated with the current `StepExecution`

    - #### getJobInstanceId

          public java.lang.Long getJobInstanceId()

      Convenient accessor for current `JobInstance` identifier.
      Returns:
        the identifier of the enclosing `JobInstance` associated with the current `StepExecution`

    - #### getSystemProperties

          public java.util.Properties getSystemProperties()

      Convenient accessor for System properties to make it easy to access them from placeholder expressions.
      Returns:
        the current System properties

    - #### getStepExecutionContext

          public java.util.Map<java.lang.String,java.lang.Object> getStepExecutionContext()

      Returns:
        a map containing the items from the step `ExecutionContext`

    - #### getJobExecutionContext

          public java.util.Map<java.lang.String,java.lang.Object> getJobExecutionContext()

      Returns:
        a map containing the items from the job `ExecutionContext`

    - #### getJobParameters

          public java.util.Map<java.lang.String,java.lang.Object> getJobParameters()

      Returns:
        a map containing the items from the `JobParameters`

    - #### getPartitionPlan

          public java.util.Map<java.lang.String,java.lang.Object> getPartitionPlan()

    - #### registerDestructionCallback

          public void registerDestructionCallback(java.lang.String name,
                                                  java.lang.Runnable callback)

      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

          @Nullable
          public java.lang.Object removeAttribute(java.lang.String name)

      Override base class behaviour to ensure destruction callbacks are unregistered as well as the default behaviour.
      Specified by:
        `removeAttribute` in interface `org.springframework.core.AttributeAccessor`
      Overrides:
        `removeAttribute` in class `SynchronizedAttributeAccessor`
      See Also:
        `SynchronizedAttributeAccessor.removeAttribute(String)`

    - #### 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 the `StepScope`.

    - #### getStepExecution

          public StepExecution getStepExecution()

      The current `StepExecution` that is active in this context.
      Returns:
        the current `StepExecution`

    - #### getId

          public java.lang.String getId()

      Returns:
        unique identifier for this context based on the step execution

    - #### equals

          public boolean equals(java.lang.Object other)

      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:
        `equals` in class `SynchronizedAttributeAccessor`
      See Also:
        `SynchronizedAttributeAccessor.equals(Object)`

    - #### hashCode

          public int hashCode()

      Overrides the default behaviour to provide a hash code based only on the step execution.
      Overrides:
        `hashCode` in class `SynchronizedAttributeAccessor`
      See Also:
        `SynchronizedAttributeAccessor.hashCode()`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `SynchronizedAttributeAccessor`