Announcement Announcement Module
Collapse
No announcement yet.
ExecutionContext is missing in Listeners Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ExecutionContext is missing in Listeners

    In some Listener class, such as ItemReadListener / ItemWriteListener / ItemRecoverer, it lacks of passing in of context variable to the listener's method.

    My use case is that I record some state to the step execution context so that I determine step exit status at the end of step.

    For example,

    If no item error, step exit status = SUCCESS
    If some items are skipped, step exit status = WARNING
    If some items are skipped and exceed a limit, step exit status = FAILED

    Any suggestion for doing this use case?

  • #2
    Currently you have to use a listener that is both a StepExecutionListener and one of the others, so you can stash the context. I can see that we might need to rethink that (I don't like stateful components).

    Careful with that ExecutionContext though - if the transaction rolls back, you might want to adjust the context as well. That's what the ItemStream interface is for. It is better if you implement that interface if you want to do stuff with ExecutionContext generally.

    Comment


    • #3
      I cannot get exactly your meaning. What I mean is that we do not have the reference of context variable inside listener methods. For example,

      SkipListener
      void onSkipInRead(Throwable t)
      void onSkipInWrite(Object item, Throwable t)

      ItemWriteListener
      void afterWrite(Object item)
      void beforeWrite(Object item)
      void onWriteError(Exception ex, Object item)

      We can only do things on the item and exceptions. It is not very helpful in most cases. E.g.:

      If we want to save the item to database (we do not have context to get DAO).

      Another use case is we want to have a variable to keep track of certain apperance of abnormalty in an item. If it reach a limit, we throw a fatal exception.

      Comment


      • #4
        Those are only two of the listeners you can use, take a look at StepExecutionListener:

        http://static.springframework.org/sp...n.html#d0e3618


        This gives you access to the StepExecution, from which you can get the ExecutionContext. There is also the ItemStream interface that gives you more direct access:

        http://static.springframework.org/sp...re.html#d0e968

        Comment

        Working...
        X