Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SpringBatch-Passing an Object to Listener from the Processor

 
Konda Golamaru
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the requirement where I need to construct a Map with all incoming entities into the processor. When the processing is done, I need to make the Map available to Listener where I need to look into each object in the map and remove the objects which are not required after further processing.

My question is: How to make the Map which is constructed in the processor be available to Listener. Is there any alternative approach(other than listener)? I am looking for a kind of delegator where I can hand over the map(which is constructed in the processor) to delegator so that I can do the final processing in the delegator e.g. updating to db or creating error report etc.

Thanks and any suggestions are welcome!
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There a quite a few ways in which you could pass the map to the listener.

a) have the processor itself implement the listener (StepExecutionListener with @AfterJob)
Then do the end processing here or pass the map to a DelegateObject that will do the processing.

b) have the map created by spring (in the spring config)
Then you an create any listener and have this map passed to it

c) Save the map in the StepExecutionContext. Then it can be retrieved in the listener
http://static.springsource.org/spring-batch/apidocs/org/springframework/batch/item/ExecutionContext.html
Note: This is the correct way, in case you want your job to be re-startable from the point of failure.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic