I've now updated the draft spec with the changes proposed below.
The updated draft spec is here:
http://java.net/projects/jms-spec/sources/repository/content/jms2.0/specification/word/JMS20.pdf
Section 11.3 "Injection of JMSContext objects" has been replaced and expanded. It now consists of the following subsections:
11.3.1 "Support for injection" explains how the Java EE classes which support injection are defined in the platform
spec, and how CDI support additionally needs to be enabled by means of a META_INF/beans.xml descriptor.
11.3.2 "Container-managed and application-managed JMSContexts" defines the terms "container-managed" and
"application-managed" in respect of JMSContext objects. This usage is consistent with JPA EntityManager objects.
11.3.3 "Injection syntax" is mostly unchanged and describes the other annotations: @JMSConnectionFactory,
@JMSPasswordCredential and @JMSSessionMode. A new note recommends that the @JMSPasswordCredential annotation is used in
conjunction with a Java EE 7 password alias. The annotation @AutoStart has been dropped.
11.3.4 "Scope of injected JMSContext objects" defines the scope as proposed below
11.3.5 "Restrictions on use of injected JMSContext objects" lists the methods on JMSContext which will not be permitted
if the JMSContext is injected.
In section "1.4. "Relationship to other Java APIs" a very short new section 1.4.8. "Contexts and dependency injection
(CDI)" has also been added.
Please take a look and let me know if you have any comments.
Nigel
On 02/08/2012 15:47, Nigel Deakin wrote:
> 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
>
>