Package org.springframework.batch.core.listener

# Class ExecutionContextPromotionListener

java.lang.Object
org.springframework.batch.core.listener.ExecutionContextPromotionListener

All Implemented Interfaces:
  `StepExecutionListener`, `StepListener`, `org.springframework.beans.factory.InitializingBean`

public class ExecutionContextPromotionListener extends Object implements StepExecutionListener, org.springframework.beans.factory.InitializingBean
This class can be used to automatically promote items from the `Step` `ExecutionContext` to the `Job` `ExecutionContext` at the end of a step. A list of keys should be provided that correspond to the items in the `Step` `ExecutionContext` that should be promoted. Additionally, an optional list of statuses can be set to indicate for which exit status codes the promotion should occur. These statuses will be checked using the `PatternMatcher`, so wildcards are allowed. By default, promotion will only occur for steps with an exit code of "COMPLETED".

Since:
  2.0
Author:
  Dan Garrette, Mahmoud Ben Hassine

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ExecutionContextPromotionListener()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `afterPropertiesSet()`
  `ExitStatus`
  `afterStep(StepExecution stepExecution)`
  Give a listener a chance to modify the exit status from a step.
  `void`
  `setKeys(String[] keys)`
  `void`
  `setStatuses(String[] statuses)`
  `void`
  `setStrict(boolean strict)`
  If set to TRUE, the listener will throw an exception if any 'key' is not found in the Step `ExecutionContext`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.springframework.batch.core.StepExecutionListener

  `beforeStep`

- ## Constructor Details

  - ### ExecutionContextPromotionListener

    public ExecutionContextPromotionListener()

- ## Method Details

  - ### afterStep

    @Nullable public ExitStatus afterStep(StepExecution stepExecution)
    Description copied from interface: `StepExecutionListener`
    Give a listener a chance to modify the exit status from a step. The value returned will be combined with the normal exit status using `ExitStatus.and(ExitStatus)`. Called after execution of step's processing logic (both successful or failed). Throwing exception in this method has no effect, it will only be logged.
    Specified by:
      `afterStep` in interface `StepExecutionListener`
    Parameters:
      `stepExecution` - `StepExecution` instance.
    Returns:
      an `ExitStatus` to combine with the normal value. Return `null` to leave the old value unchanged.

  - ### afterPropertiesSet

    public void afterPropertiesSet() throws Exception
    Specified by:
      `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
    Throws:
      `Exception`

  - ### setKeys

    public void setKeys(String[] keys)
    Parameters:
      `keys` - A list of keys corresponding to items in the `Step` `ExecutionContext` that must be promoted.

  - ### setStatuses

    public void setStatuses(String[] statuses)
    Parameters:
      `statuses` - A list of statuses for which the promotion should occur. Statuses can may contain wildcards recognizable by a `PatternMatcher`.

  - ### setStrict

    public void setStrict(boolean strict)
    If set to TRUE, the listener will throw an exception if any 'key' is not found in the Step `ExecutionContext`. FALSE by default.
    Parameters:
      `strict` - boolean the value of the flag.