Results 1 to 3 of 3

Thread: Conditional Flow for an item within an ItemProcessor

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Default Conditional Flow for an item within an ItemProcessor

    Hi,
    is there a way to make the item processor step in the chunk to invoke and start a flow? Spring provides composite item processor out of the box to call multiple processors, but its linear. I want to add spring batch's conditional flow features while processing an item. How would I make a single ItemProcessor a stateful workflow in itself?

    I want to add a FlowExecutionContext and that serves as an in between place to hold the item object in it (job execution context is too big and step exection context is too small). anybody tried to do this and have any helpful information, I really appreciate your help.

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    There isn't a way within the framework to execute a flow within just the ItemProcessor piece of a step. For what you are describing, you essentially have two options:

    1. Write your own ItemProcessor to handle the logic yourself. That will also require you to handle the state management within your custom ItemProcessor.
    2. Execute the flow as a job step. You can execute a job from a step.


    What is the logic you are attempting to run within the scope of an ItemProcessor? It sounds like you may be attempting to do more than you should in that single step.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3
    Join Date
    Feb 2013
    Posts
    2

    Default

    Quote Originally Posted by mminella View Post
    There isn't a way within the framework to execute a flow within just the ItemProcessor piece of a step. For what you are describing, you essentially have two options:

    1. Write your own ItemProcessor to handle the logic yourself. That will also require you to handle the state management within your custom ItemProcessor.
    2. Execute the flow as a job step. You can execute a job from a step.


    What is the logic you are attempting to run within the scope of an ItemProcessor? It sounds like you may be attempting to do more than you should in that single step.
    Thanks for the reply. Code is reading items from db using reader and each item can belong to any of the 3 categories to write (export) data related to it. So, it ends up like, if i read 100 items fro db, some of those items need to be exported to a specific output format(say xml) and some to a different format.In order to gather data to be written for output formats , different local service calls may have to be made in some cases or make a webservice call before writing to output format.

    so, i am trying to write item processor that can make these multiple service calls depending on the category that item belongs to. So far, I have tried this. Please let me know if you see a better way to arrange the job.

    public class RunFlowItemProcessor implements ItemProcessor<MyItemFromDB, MyItemFromDB>, StepExecutionListener {
    //these beans are wired in xml
    protected Flow flow;
    protected JobRepository jobRepository;
    //this is here because of listener
    protected StepExecution stepExecution;

    @Override
    public MyItemFromDB process(MyItemFromDB item) throws Exception {
    FlowStep fStep = new FlowStep();
    fStep.setFlow(flow);
    fStep.setJobRepository(getJobRepository());
    fStep.registerStepExecutionListener(this);
    getStepExecution().getExecutionContext().put("item ", item);
    fStep.execute(getStepExecution());
    return item;
    }
    Last edited by rgangarapu; Feb 25th, 2013 at 10:33 PM.

Posting Permissions

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