<div dir="ltr">would be super cool to not have to write an extension for that, cant we use applicationscope init event or an prioritized event at this moment - avoiding the spi is a must for end user usage IMO?</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><br><span style="font-size:small">Romain Manni-Bucau</span><br><a href="https://twitter.com/rmannibucau" target="_blank">@rmannibucau</a> |  <a href="http://rmannibucau.wordpress.com" target="_blank">Blog</a> | <a href="https://github.com/rmannibucau" target="_blank">Github</a> | <a href="https://www.linkedin.com/in/rmannibucau" target="_blank">LinkedIn</a> | <a href="http://www.tomitribe.com" target="_blank">Tomitriber</a></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">2015-10-19 8:40 GMT+02:00 Martin Kouba <span dir="ltr">&lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In CDI 2.0 we propose to support lambdas in the bean builder API -<br>
currently available as a weld experimental feature in AfterBeanDiscovery<br>
and Weld SE - see also [1] and [2].<br>
<br>
For observers a similar builder might be useful.<br>
<br>
Martin<br>
<br>
[1]<br>
<a href="http://weld.cdi-spec.org/news/2015/02/25/weld-300Alpha5/#_bean_builder_api" rel="noreferrer" target="_blank">http://weld.cdi-spec.org/news/2015/02/25/weld-300Alpha5/#_bean_builder_api</a><br>
<br>
[2]<br>
<a href="https://github.com/weld/core/blob/master/tests-arquillian/src/test/java/org/jboss/weld/tests/extensions/custombeans/BuilderExtension.java" rel="noreferrer" target="_blank">https://github.com/weld/core/blob/master/tests-arquillian/src/test/java/org/jboss/weld/tests/extensions/custombeans/BuilderExtension.java</a><br>
<br>
<br>
<br>
Dne 17.10.2015 v 13:51 Sven Linstaedt napsal(a):<br>
<span class="">&gt; Just one question: Who is on charge and is able of managing this<br>
&gt; unmanaged instances, e.g. lifecycle, serialization, concurrency (e.g.<br>
&gt; when dealing with closures)?<br>
&gt;<br>
&gt; Functional programming and DI seem to be somehow disjunct in this case.<br>
&gt; E.g. manually setting up observers seem to better fit extension than<br>
&gt; normal application code.<br>
&gt;<br>
&gt; On the other side, specifying producer methods or fields, that are<br>
&gt; injectable and return lambda expressions seems to be a no brainier for<br>
&gt; CDI, is not it? As long as they are not scoped in a serializable context.<br>
&gt;<br>
&gt; Have a nice weekend<br>
&gt; Sven<br>
&gt;<br>
&gt; -- sent by phone<br>
&gt;<br>
&gt; Am 17.10.2015 um 11:06 schrieb David Blevins &lt;<a href="mailto:david.blevins@gmail.com">david.blevins@gmail.com</a><br>
</span>&gt; &lt;mailto:<a href="mailto:david.blevins@gmail.com">david.blevins@gmail.com</a>&gt;&gt;:<br>
<div><div class="h5">&gt;<br>
&gt;&gt; In brainstorming mode about fun that could be made possible with Java<br>
&gt;&gt; 8 and Java EE.<br>
&gt;&gt;<br>
&gt;&gt; Question in my mind is: is there some way we could make it possible<br>
&gt;&gt; for Lambdas or Method Refs to be CDI beans?<br>
&gt;&gt;<br>
&gt;&gt; It goes against the grain obviously as CDI creation is very much a<br>
&gt;&gt; “Don’t call us, we’ll call you” kind of thing.  The VM dynamically<br>
&gt;&gt; creates a wrapper object around the Lambda or method reference and it<br>
&gt;&gt; implements the given interface.<br>
&gt;&gt;<br>
&gt;&gt; To make it work, there would need to be some non-producer method way<br>
&gt;&gt; of saying “put this thing in the context with these qualifiers”.<br>
&gt;&gt;<br>
&gt;&gt; Imagine a method somewhere that would allow you to:<br>
&gt;&gt;<br>
&gt;&gt;    public &lt;T&gt; void addObserver(java.util.function.Consumer&lt;T&gt;<br>
&gt;&gt; observer, Annotation... qualifiers);<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Then you could take advantage as follows:<br>
&gt;&gt;<br>
&gt;&gt;    final List&lt;URI&gt; uris = new ArrayList&lt;&gt;();<br>
&gt;&gt;    // @Observes URI<br>
&gt;&gt;    addObserver((Consumer&lt;URI&gt;) uris::add);<br>
&gt;&gt;<br>
&gt;&gt;    // @Observes Thread<br>
&gt;&gt;    addObserver(Runtime.getRuntime()::addShutdownHook);<br>
&gt;&gt;<br>
&gt;&gt;    // @Observes Runnable<br>
&gt;&gt;    addObserver((Consumer&lt;Runnable&gt;)<br>
&gt;&gt; Executors.newFixedThreadPool(3)::submit);<br>
&gt;&gt;<br>
&gt;&gt;    // @Observes URI<br>
&gt;&gt;    addObserver((Consumer&lt;URI&gt;) System.out::println, new<br>
&gt;&gt; AnnotationLiteral&lt;Fine&gt;() {<br>
&gt;&gt;    });<br>
&gt;&gt;<br>
&gt;&gt;    // @Observes Handler<br>
&gt;&gt;    final Logger logger = Logger.getLogger(&quot;somewhere&quot;);<br>
&gt;&gt;    addObserver(logger::addHandler); // add handlers via event<br>
&gt;&gt;<br>
&gt;&gt;    // @Observes @Fine String<br>
&gt;&gt;    addObserver((Consumer&lt;String&gt;) logger::fine, new<br>
&gt;&gt; AnnotationLiteral&lt;Fine&gt;() {});<br>
&gt;&gt;    }<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; -David<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; David Blevins<br>
&gt;&gt; <a href="http://twitter.com/dblevins" rel="noreferrer" target="_blank">http://twitter.com/dblevins</a><br>
&gt;&gt; <a href="http://www.tomitribe.com" rel="noreferrer" target="_blank">http://www.tomitribe.com</a><br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; cdi-dev mailing list<br>
</div></div>&gt;&gt; <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>&gt;<br>
<span class="im HOEnZb">&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
&gt;&gt;<br>
&gt;&gt; Note that for all code provided on this list, the provider licenses<br>
&gt;&gt; the code under the Apache License, Version 2<br>
&gt;&gt; (<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<br>
&gt;&gt; provided on this list, the provider waives all patent and other<br>
&gt;&gt; intellectual property rights inherent in such information.<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; cdi-dev mailing list<br>
&gt; <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
&gt;<br>
&gt; 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>
&gt;<br>
<br>
</span><span class="HOEnZb"><font color="#888888">--<br>
Martin Kouba<br>
Software Engineer<br>
Red Hat, Czech Republic<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br></div>