<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"><<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>></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="">> Just one question: Who is on charge and is able of managing this<br>
> unmanaged instances, e.g. lifecycle, serialization, concurrency (e.g.<br>
> when dealing with closures)?<br>
><br>
> Functional programming and DI seem to be somehow disjunct in this case.<br>
> E.g. manually setting up observers seem to better fit extension than<br>
> normal application code.<br>
><br>
> On the other side, specifying producer methods or fields, that are<br>
> injectable and return lambda expressions seems to be a no brainier for<br>
> CDI, is not it? As long as they are not scoped in a serializable context.<br>
><br>
> Have a nice weekend<br>
> Sven<br>
><br>
> -- sent by phone<br>
><br>
> Am 17.10.2015 um 11:06 schrieb David Blevins <<a href="mailto:david.blevins@gmail.com">david.blevins@gmail.com</a><br>
</span>> <mailto:<a href="mailto:david.blevins@gmail.com">david.blevins@gmail.com</a>>>:<br>
<div><div class="h5">><br>
>> In brainstorming mode about fun that could be made possible with Java<br>
>> 8 and Java EE.<br>
>><br>
>> Question in my mind is: is there some way we could make it possible<br>
>> for Lambdas or Method Refs to be CDI beans?<br>
>><br>
>> It goes against the grain obviously as CDI creation is very much a<br>
>> “Don’t call us, we’ll call you” kind of thing. The VM dynamically<br>
>> creates a wrapper object around the Lambda or method reference and it<br>
>> implements the given interface.<br>
>><br>
>> To make it work, there would need to be some non-producer method way<br>
>> of saying “put this thing in the context with these qualifiers”.<br>
>><br>
>> Imagine a method somewhere that would allow you to:<br>
>><br>
>> public <T> void addObserver(java.util.function.Consumer<T><br>
>> observer, Annotation... qualifiers);<br>
>><br>
>><br>
>> Then you could take advantage as follows:<br>
>><br>
>> final List<URI> uris = new ArrayList<>();<br>
>> // @Observes URI<br>
>> addObserver((Consumer<URI>) uris::add);<br>
>><br>
>> // @Observes Thread<br>
>> addObserver(Runtime.getRuntime()::addShutdownHook);<br>
>><br>
>> // @Observes Runnable<br>
>> addObserver((Consumer<Runnable>)<br>
>> Executors.newFixedThreadPool(3)::submit);<br>
>><br>
>> // @Observes URI<br>
>> addObserver((Consumer<URI>) System.out::println, new<br>
>> AnnotationLiteral<Fine>() {<br>
>> });<br>
>><br>
>> // @Observes Handler<br>
>> final Logger logger = Logger.getLogger("somewhere");<br>
>> addObserver(logger::addHandler); // add handlers via event<br>
>><br>
>> // @Observes @Fine String<br>
>> addObserver((Consumer<String>) logger::fine, new<br>
>> AnnotationLiteral<Fine>() {});<br>
>> }<br>
>><br>
>><br>
>><br>
>> -David<br>
>><br>
>><br>
>><br>
>> --<br>
>> David Blevins<br>
>> <a href="http://twitter.com/dblevins" rel="noreferrer" target="_blank">http://twitter.com/dblevins</a><br>
>> <a href="http://www.tomitribe.com" rel="noreferrer" target="_blank">http://www.tomitribe.com</a><br>
>><br>
>> _______________________________________________<br>
>> cdi-dev mailing list<br>
</div></div>>> <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a> <mailto:<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>><br>
<span class="im HOEnZb">>> <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<br>
>> the code under the Apache License, Version 2<br>
>> (<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>
>> provided on this list, the provider waives all patent and other<br>
>> intellectual property rights inherent in such information.<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>
<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>