Results 1 to 6 of 6

Thread: How to access StepExecutionContext from the reader

  1. #1
    Join Date
    May 2010
    Posts
    11

    Default How to access StepExecutionContext from the reader

    I have a requirement to store the data read in the reader in the job execution context so that it is accessible to the other steps. Is it possible to access step execution context in the read method of the reader and then promote the data in step execution context to job execution context? Is there any listener which has access to both the data returned by the reader and the step/job execution context?

    Thanks in advance.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    There's an ExecutionContextPromotionListener for that use case. Be careful how much data you store there because it is persisted in the JobRepository.

  3. #3
    Join Date
    May 2010
    Posts
    11

    Default

    In my case the first step is a partition step and each partition has the same key in its execution context. How can i promote the values in all the partitions to the job execution context(as a list or an array).

    Can I do this explicitly in the afterStep method of ExecutionContextPromotionListener listener? Is that the preferred approach? My assumption here is that the listener will be invoked after the completion of each partition.

    Below is the pseudo code I am planning to use:

    public ExitStatus afterStep(StepExecution stepExecution){
    ExecutionContext stepExecutionContext = stepExecution.getExecutionContext();
    ExecutionContext jobExecutionContext = stepExecution.getJobExecution().getExecutionContex t();

    String value = stepExecutionContext.get("key");
    if(jobExecutionContext.containsKey("key")){
    List valueList = jobExecutionContext.get("key");
    valueList.add(value);
    }else{
    List valueList = new ArrayList();
    valueList.add(value);
    jobExecutionContext.put("key",valueList);
    }
    return super.afterStep(stepExecution);
    }

    Please let me know if there are alternate approaches to this.
    Last edited by Bhuvana; Jul 29th, 2010 at 06:47 AM.

  4. #4
    Join Date
    May 2010
    Posts
    11

    Default

    I tried a sample job with the above contextlistener but it looks like the listener is getting invoked only once. I am not sure this is because of the exit status being returned by the afterStep method. Is there a specific exit status I need to return so that the execution will still be for the current step until the listener is invoked for all the partition steps?

    Please help since this is holding up my work.

  5. #5

    Default

    Any working model for this ?

  6. #6
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    The super class return null, so the ExitStatus is not a problem. The problem might be that since you are using a partition step, so you are overwriting JobExecution context entries - each partition adds its own data to the same keys. You would need to make the keys unique in the JobExecution maybe by adding the step name as a prefix.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •