Back in June I made some updated proposals for a suitable scope for injected JMSContext objects, and came up with a
combined transaction/method scope proposal which I wrote up here:
http://java.net/projects/jms-spec/pages/JMSContextScopeProposals (these are "option 2" and "option 3")
Essentially, this proposed that the injected JMSContext would have a single scope which was a combination of transaction
and method scope.
This received support from this expert group, but I have since spent a lot of time discussing this with the Java EE spec
leads and others in Oracle and had some strong feedback that this proposal was potentially confusing and needed
improvement. After much discussion we have come up with a new proposal "option 4", which I have described here:
http://java.net/projects/jms-spec/pages/JMSContextScopeProposalsv4p1
Essentially, the proposal is that the scope of an injected JMSContext object will depend on whether it is used in a
transaction. Whereas Option 2 and Option 3 proposed a single scope which was used irrespective of whether there was a
transaction or not, this option proposes that the scope used depends on whether the injected JMSContext is used in a
transaction or not.
* If an injected JMSContext is used in a JTA transaction (both bean-managed and container-managed), its scope will be
that of the transaction. This means that:
- The JMSContext object will be automatically created the first time it is used within the transaction.
- The JMSContext object will be automatically closed when the transaction is committed.
- If, within the same JTA transaction, different beans, or different methods within the same bean, use an injected
JMSContext which is injected using identical annotations then they will all share the same JMSContext object.
* If an injected JMSContext is used when there is no JTA transaction then its scope will be the existing CDI scope
@RequestScoped. This means that:
- The JMSContext object will be created the first time it is used within a request.
- The JMSContext object will be closed when the request ends.
- If, within the same request, different beans, or different methods within the same bean, use an injected
JMSContext which is injected using identical annotations then they will all share the same JMSContext object.
* If injected JMSContext is used both in a JTA transaction and outside a JTA transaction then separate JMSContext
objects will be used, with a separate JMSContext object being used for each JTA transaction as described above.
I have updated that long list of use cases to demonstrate how this scope would work in practice. This is split over two
wiki pages here:
http://java.net/projects/jms-spec/pages/JMSContextScopeProposalsv4p2
http://java.net/projects/jms-spec/pages/JMSContextScopeProposalsv4p3
Please take a look and let me know if you have any questions or comments.
I'm going to send a separate email proposing some changes to the JMSContext API itself. Since those don't depend on the
details of what scope we use I'd like to keep that discussion separate.
Thanks,
Nigel
P.S. If you're getting confused with all these different proposals, I've assembled a list of links on this wiki page:
http://java.net/projects/jms-spec/pages/JMSContextScopeUseCases