<div dir="ltr">Jozef,<div><br></div><div>Can&#39;t say to what extent this could also apply for JMS but just wanted to point to the recent Portlet 3 draft <a href="https://java.net/downloads/portletspec3/SpecDrafts/PortletSpec3-Draft1-20150821.pdf">https://java.net/downloads/portletspec3/SpecDrafts/PortletSpec3-Draft1-20150821.pdf</a> (20.2 Custom Scopes) where the JSR intends to add new CDI scopes for certain parts of the standard while using the ones Java EE/CDI defines in other cases.</div><div><br></div><div><span lang="EN-US" style="font-size:13px;font-family:Calibri">Werner</span></div><div><div class="gmail_extra">
<br><div class="gmail_quote">On Wed, Aug 26, 2015 at 3:50 PM,  <span dir="ltr">&lt;<a href="mailto:cdi-dev-request@lists.jboss.org" target="_blank">cdi-dev-request@lists.jboss.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Send cdi-dev mailing list submissions to<br>
        <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:cdi-dev-request@lists.jboss.org">cdi-dev-request@lists.jboss.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:cdi-dev-owner@lists.jboss.org">cdi-dev-owner@lists.jboss.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of cdi-dev digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re: JMS 2.1: Proposal to allow any CDI managed bean in a Java<br>
      EE application to listen for JMS messages (arjan tijms)<br>
   2. Re: JMS 2.1: Proposal to allow any CDI managed bean in a Java<br>
      EE application to listen for JMS messages (Werner Keil)<br>
   3. Re: JMS 2.1: Proposal to allow any CDI managed bean in a Java<br>
      EE application to listen for JMS messages (Jozef Hartinger)<br>
   4. Re: JMS 2.1: Proposal to allow any CDI managed bean in a Java<br>
      EE application to listen for JMS messages (Nigel Deakin)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>Message: 3<br>
Date: Wed, 26 Aug 2015 15:04:06 +0200<br>
From: Jozef Hartinger &lt;<a href="mailto:jharting@redhat.com">jharting@redhat.com</a>&gt;<br>
Subject: Re: [cdi-dev] JMS 2.1: Proposal to allow any CDI managed bean<br>
        in a Java EE application to listen for JMS messages<br>
To: Nigel Deakin &lt;<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>&gt;,     Romain Manni-Bucau<br>
        &lt;<a href="mailto:rmannibucau@gmail.com">rmannibucau@gmail.com</a>&gt;<br>
Cc: cdi-dev &lt;<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>&gt;<br>
Message-ID: &lt;<a href="mailto:55DDB946.9050208@redhat.com">55DDB946.9050208@redhat.com</a>&gt;<br>
Content-Type: text/plain; charset=utf-8; format=flowed<br>
<br>
To me the proposed approach seems to be very strict about JMS semantics<br>
and bending CDI over it (not using CDI contextual instances properly,<br>
calling @RequestScoped instances from multiple threads in parallel, ..).<br>
<br>
A simpler approach would be a bridge where a JMS message would produce a<br>
single CDI event. The semantics of synchronous CDI events would apply<br>
from there. For users this should be straightforward as they would know<br>
that they are working with a CDI event that was raised by the container<br>
when it received a JMS message.<br>
<br>
Jozef<br>
<br>
<br>
On 26.08.2015 11:43, Nigel Deakin wrote:<br>
&gt;  &gt; On 25.08.2015 16:05, Romain Manni-Bucau wrote:<br>
&gt;  &gt;&gt;<br>
&gt;  &gt;&gt; For this last case a really elegant solution would be to just reuse<br>
&gt;  &gt;&gt; @Observes to fire the message from the jms &quot;container&quot; listener and<br>
&gt;  &gt;&gt; propagate it to the &quot;user&quot; listener. This would then allow to decouple<br>
&gt;  &gt;&gt; the application listener from JMS.<br>
&gt;<br>
&gt; On 25/08/2015 15:26, Jozef Hartinger wrote:<br>
&gt;&gt; Agreed. I think we should leverage the existing CDI event/observer<br>
&gt;&gt; functionality instead of introducing a completely new<br>
&gt;&gt; delivery mechanism.<br>
&gt;<br>
&gt; Can you please say a bit more about what you have in mind?<br>
&gt;<br>
&gt; Romain suggests using events to invoke the &quot;user&quot; listener from the &quot;JMS<br>
&gt; container listener&quot;.<br>
&gt; That&#39;s a useful distinction. Just to clarify the terminology:<br>
&gt;<br>
&gt; &quot;user&quot; listener = listener bean provided by the application<br>
&gt; &quot;JMS container listener&quot; = JMS consumer provided by the application<br>
&gt; server or resource adapter<br>
&gt;<br>
&gt; There needs to be one consumer for every listener bean since the two<br>
&gt; need to have the same lifecycle, and also so we can implement JMS queue<br>
&gt; sematics which require that a message from a queue is delivered to one<br>
&gt; and only one listener.<br>
&gt;<br>
&gt; The transaction needs to be started by the consumer before invoking the<br>
&gt; listener and ended after the listener returns. This allows the<br>
&gt; acknowledgement of the message (which is performed by the consumer) to<br>
&gt; take place in the same transaction as is used by the listener&#39;s method.<br>
&gt;<br>
&gt; Currently I&#39;m proposing that the &quot;consumer&quot; invokes the &quot;listener&quot; by a<br>
&gt; simple method call. I suppose instead of simply invoking the method it<br>
&gt; could fire a synchronous event, which only the associated listener<br>
&gt; instance would receive, but I&#39;m not sure what the benefit of this would<br>
&gt; be. Since JMS semantics are very different from CDI event semantics I<br>
&gt; think there&#39;s a danger that this will be confusing, since the user might<br>
&gt; think they were getting CDI event semantics, but they were actually<br>
&gt; getting JMS semantics.<br>
&gt;<br>
&gt; Since this is a bit of a FAQ, it might be useful to explore the<br>
&gt; differences between the two semantics, but currently they seem<br>
&gt; profoundly different to me. That&#39;s why my proposals are built on the CDI<br>
&gt; bean lifecycle model but not the CDI event observer model.<br>
&gt;<br>
&gt; Nigel<br>
&gt;<br>
<br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Wed, 26 Aug 2015 14:50:26 +0100<br>
From: Nigel Deakin &lt;<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>&gt;<br>
Subject: Re: [cdi-dev] JMS 2.1: Proposal to allow any CDI managed bean<br>
        in a Java EE application to listen for JMS messages<br>
To: arjan tijms &lt;<a href="mailto:arjan.tijms@gmail.com">arjan.tijms@gmail.com</a>&gt;<br>
Cc: cdi-dev &lt;<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>&gt;<br>
Message-ID: &lt;<a href="mailto:55DDC422.7000907@oracle.com">55DDC422.7000907@oracle.com</a>&gt;<br>
Content-Type: text/plain; charset=utf-8; format=flowed<br>
<br>
On 26/08/2015 13:26, arjan tijms wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; On Wed, Aug 26, 2015 at 2:03 PM, Nigel Deakin &lt;<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>&gt; wrote:<br>
&gt;&gt; In the case of a &quot;JMS listener bean&quot; with @RequestScoped (or any scope,<br>
&gt;&gt; really) then the JMS consumer (the thread which receives a message from the<br>
&gt;&gt; JMS server and invokes the listener) is associated with the actual bean<br>
&gt;&gt; instance.<br>
&gt;<br>
&gt; Indeed, so the call takes place in the context of the JMS consumer<br>
&gt; thread and happens to the &quot;bare&quot; bean instance and does not go through<br>
&gt; the proxy that&#39;s normally used to access that bean.<br>
&gt;<br>
&gt;<br>
&gt;&gt; However once you&#39;re inside the callback method then this request scope<br>
&gt;&gt; (which relates to a different thread) is not available.<br>
&gt;<br>
&gt; So this would be an important detail for the user to take into<br>
&gt; account. The callback method is NOT allowed to access any other normal<br>
&gt; scoped beans, be it via injection, beanmanager lookup or whatever.<br>
&gt;<br>
&gt; E.g. given:<br>
&gt;<br>
&gt; @RequestScoped<br>
&gt; public class MyCDIBean21 {<br>
&gt;<br>
&gt;    @Inject<br>
&gt;    private MyRequestScopedBean requestBean;<br>
&gt;<br>
&gt;     @JMSListener(lookup=&quot;java:global/java:global/Trades&quot;,type=JMSListener.Type.TOPIC<br>
&gt; )<br>
&gt;     @JMSConnectionFactory(&quot;java:global/MyCF&quot;)<br>
&gt;     @MessageSelector(&quot;ticker=&#39;ORCL&#39;&quot;)<br>
&gt;     public void processNewsItem(String newsItem) {<br>
&gt;       ...<br>
&gt;     }<br>
&gt;   }<br>
&gt;<br>
&gt; Then the callback processNewsItem() can not use requestBean, since<br>
&gt; it&#39;s a proxy and it will try to delegate to a scope that does not<br>
&gt; exist for that thread.<br>
&gt;<br>
&gt; Alternative, if there&#39;s an other @RequestScope active (as suggested<br>
&gt; below) it will end up calling a different bean instance than the user<br>
&gt; may expect.<br>
<br>
Yes, I can see how that might be surprising.<br>
<br>
However it looks as if this is exactly what is proposed in CDI 2.0 for asynchronous observer methods:<br>
<br>
10.5.3 &quot;Observer method invocation context&quot; states &quot;If the observer method is asynchronous, it is called in a new<br>
lifecycle contexts, a new transaction context but the same security context as the invocation of Event.fireAsync().&quot;<br>
<br>
19.3.1. &quot;Request context lifecycle in Java EE&quot;. States that &quot;The request scope is active...during any asynchronous<br>
invocation of an event observer&quot;.<br>
<br>
Please correct me if I have misunderstood what is proposed.<br>
<br>
&gt; While it could work, I wonder if this aspect wouldn&#39;t be a bit confusing?<br>
<br>
Good question!<br>
<br>
Nigel<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>).  For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
<br>
End of cdi-dev Digest, Vol 57, Issue 25<br>
***************************************<br>
</blockquote></div><br></div></div></div>