Bug 4546

Summary: Passing the BatchContext where apropriate instead of relying solely on injection
Product: jbatch Reporter: mminella
Component: sourceAssignee: cvignola
Severity: normal CC: issues
Priority: P5    
Version: 1   
Target Milestone: ---   
Hardware: All   
OS: All   

Description mminella 2013-01-17 21:42:08 UTC
We have chosen to inject the BatchContext via an annotation but on event based calls like the listeners, I think it makes more sense to pass it in as a parameter. It's not something that we can set once on object creation and then forget; it will need to be passed each time the method is called.  Because of that, I would expect each of the listeners methods (where appropriate) to accept the context as a parameter.
Comment 1 cvignola 2013-01-23 20:14:10 UTC
It's a reasonable suggestion. But actually context is something you can set once on a batch artifact instance and then forget.  This is because batch artifacts and batch contexts have the same life cycle.  E.g. a job level artifact exists for the life of the job;  there is one and only one job context and it also exists for the life of the job.  Same applies to step level batch artifacts and the step context - they both exist for the life of the step.
Comment 2 mminella 2013-01-24 14:24:27 UTC
That makes sense.  My only other thought is that it is (at least to me) more intuitive if the context is passed in as a parameter than being injected.
Comment 3 cvignola 2013-02-02 00:16:03 UTC
I thought about this suggestion further and indeed found the proposition tempting. However, as I considered it, I decided against it.  The reason I decided against it is because parameters represent data on which a method is expected to operate.  It's part of the contract.  In no case that I can think of is a context object an intentional part of a method contract; in other words, there is no case in which a batch artifact is expected to operate on a context.  It may be true that a developer chooses to operate on a context in some cases,  maybe even in many cases,  but that is developer prerogative and not an inherent part of any one of the batch artifacts contracts.  Context objects are available to those batch artifacts that choose to operate on them via injection. I consider that both appropriate and sufficient.