<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">There is a cave-at serializing a
lambda, the capturing class must be the exact same on both ends.<br>
<br>
See also
<a class="moz-txt-link-freetext" href="https://github.com/wolfc/jboss-beach-lambchops/blob/d4677021899dc945c3acb1b7eb73ff7cc901b223/client/src/main/java/org/jboss/beach/lambchops/client/Client.java#L111">https://github.com/wolfc/jboss-beach-lambchops/blob/d4677021899dc945c3acb1b7eb73ff7cc901b223/client/src/main/java/org/jboss/beach/lambchops/client/Client.java#L111</a><br>
<br>
In my case I just serialize the capturing class as well and ensure
the other end has a defining class loader. :-)<br>
<br>
Carlo<br>
<br>
On 10/17/2015 06:57 PM, Romain Manni-Bucau wrote:<br>
</div>
<blockquote
cite="mid:CACLE=7OjT5pbOj-QkkaY-JXmnMxhLWEBvJHdtiTgMzv5itb_uQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div>
<div class="gmail_signature">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr"><br>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="gmail_quote">2015-10-17 18:54 GMT+02:00 Sven
Linstaedt <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:sven.linstaedt@gmail.com" target="_blank">sven.linstaedt@gmail.com</a>></span>:<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">
<div dir="auto">
<div>Hi John</div>
<div><br>
</div>
<div>most, if not all Java 8 lambda types are not
serializable afaik (sure, one can specify custom
serializable lambdas, but I guess this happens rather
rarely), so assigning a lambda typed bean a
serializable context will probably always cause
problems. Even the lamda type itself is serializable,
it does not mean it's closure is. Even though
application scoped lambda beans are in general no
problem at all, most other contexts are. So the
question is, whether to allow lambda typed bean to
have any serializable scope at all. </div>
<div><br>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>java.lang.invoke.SerializedLambda is done for that so
should be<br>
</div>
<div> </div>
<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">
<div dir="auto">
<div>Don't get me wrong. I am a huge fan of Java 8 and
functional programming in general, but I think FP's
way of expressive design somehow collides with CDI's
rather declarative style. At least for non-SPI code. </div>
<div><br>
</div>
</div>
</blockquote>
<div><br>
</div>
<div><br>
</div>
<div>Same here, I think a good API should deserve it. Being
able to bind in an extension or through an event not
needed a SPI file a lambda would be great but I think we
are out of CDI - as backbone - scope there. Maybe doing a
proto using custom events can help to play with it and see
what we can do of it.</div>
<div> </div>
<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">
<div dir="auto">
<div>Best regards</div>
<span class="">
<div>Sven</div>
<div><br>
<div>-- sent by phone</div>
</div>
</span>
<div>
<div class="h5">
<div><br>
Am 17.10.2015 um 15:03 schrieb John D. Ament <<a
moz-do-not-send="true"
href="mailto:john.d.ament@gmail.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:john.d.ament@gmail.com">john.d.ament@gmail.com</a></a>>:<br>
<br>
</div>
<blockquote type="cite">
<div>
<div dir="ltr">Sven,
<div><br>
</div>
<div>I'm a little curious, why do they need to
avoid serializable contexts? In all
honesty, I use app scoped functions,
predicates in my code, at least in a couple
of places. Lambdas are specifically meant
for operations, not data, so they should be
in a highly reusable scope (in my opinion at
least).</div>
<div><br>
</div>
<div>On the flip side, I have a hard time
justifying needing to provide injectable
beans for lambdas since good encapsulation
should indicate they're only used in a
single spot.</div>
<div><br>
</div>
<div>John</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Sat, Oct 17, 2015 at 7:51 AM
Sven Linstaedt <<a moz-do-not-send="true"
href="mailto:sven.linstaedt@gmail.com"
target="_blank">sven.linstaedt@gmail.com</a>>
wrote:<br>
</div>
<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">
<div dir="auto">
<div>Just one question: Who is on charge
and is able of managing this unmanaged
instances, e.g. lifecycle,
serialization, concurrency (e.g. when
dealing with closures)? </div>
<div><br>
</div>
<div>Functional programming and DI seem to
be somehow disjunct in this case. E.g.
manually setting up observers seem to
better fit extension than normal
application code. </div>
<div><br>
</div>
<div>On the other side, specifying
producer methods or fields, that are
injectable and return lambda expressions
seems to be a no brainier for CDI, is
not it? As long as they are not scoped
in a serializable context. </div>
<div><br>
</div>
<div>Have a nice weekend </div>
<div>Sven<br>
<br>
<div>-- sent by phone</div>
</div>
</div>
<div dir="auto">
<div><br>
Am 17.10.2015 um 11:06 schrieb David
Blevins <<a moz-do-not-send="true"
href="mailto:david.blevins@gmail.com"
target="_blank">david.blevins@gmail.com</a>>:<br>
<br>
</div>
<blockquote type="cite">
<div>In brainstorming mode about fun
that could be made possible with Java
8 and Java EE.<br>
<br>
Question in my mind is: is there some
way we could make it possible for
Lambdas or Method Refs to be CDI
beans?<br>
<br>
It goes against the grain obviously as
CDI creation is very much a “Don’t
call us, we’ll call you” kind of
thing. The VM dynamically creates a
wrapper object around the Lambda or
method reference and it implements the
given interface.<br>
<br>
To make it work, there would need to
be some non-producer method way 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>
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>)
Executors.newFixedThreadPool(3)::submit);<br>
<br>
// @Observes URI<br>
addObserver((Consumer<URI>)
System.out::println, new
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
AnnotationLiteral<Fine>() {});<br>
}<br>
<br>
<br>
<br>
-David<br>
<br>
<div>
<div
style="color:rgb(0,0,0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><br>
<br>
</div>
<div
style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">-- </div>
<div
style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">David
Blevins<br>
<a moz-do-not-send="true"
href="http://twitter.com/dblevins"
target="_blank">http://twitter.com/dblevins</a><br>
<a moz-do-not-send="true"
href="http://www.tomitribe.com"
target="_blank">http://www.tomitribe.com</a><br>
</div>
</div>
<br>
</div>
</blockquote>
<blockquote type="cite">
<div><span>_______________________________________________</span><br>
<span>cdi-dev mailing list</span><br>
<span><a moz-do-not-send="true"
href="mailto:cdi-dev@lists.jboss.org"
target="_blank">cdi-dev@lists.jboss.org</a></span><br>
<span><a moz-do-not-send="true"
href="https://lists.jboss.org/mailman/listinfo/cdi-dev"
target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a></span><br>
<span></span><br>
<span>Note that for all code provided
on this list, the provider licenses
the code under the Apache License,
Version 2 (<a moz-do-not-send="true"
href="http://www.apache.org/licenses/LICENSE-2.0.html" 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.</span></div>
</blockquote>
</div>
_______________________________________________<br>
cdi-dev mailing list<br>
<a moz-do-not-send="true"
href="mailto:cdi-dev@lists.jboss.org"
target="_blank">cdi-dev@lists.jboss.org</a><br>
<a moz-do-not-send="true"
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
moz-do-not-send="true"
href="http://www.apache.org/licenses/LICENSE-2.0.html"
rel="noreferrer" target="_blank"><a class="moz-txt-link-freetext" href="http://www.apache.org/licenses/LICENSE-2.0.html">http://www.apache.org/licenses/LICENSE-2.0.html</a></a>).
For all other ideas provided on this list,
the provider waives all patent and other
intellectual property rights inherent in
such information.</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a moz-do-not-send="true"
href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a moz-do-not-send="true"
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
moz-do-not-send="true"
href="http://www.apache.org/licenses/LICENSE-2.0.html"
rel="noreferrer" target="_blank"><a class="moz-txt-link-freetext" href="http://www.apache.org/licenses/LICENSE-2.0.html">http://www.apache.org/licenses/LICENSE-2.0.html</a></a>).
For all other ideas provided on this list, the provider
waives all patent and other intellectual property rights
inherent in such information.<br>
</blockquote>
</div>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cdi-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/cdi-dev">https://lists.jboss.org/mailman/listinfo/cdi-dev</a>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a class="moz-txt-link-freetext" href="http://www.apache.org/licenses/LICENSE-2.0.html">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.</pre>
</blockquote>
<br>
</body>
</html>