<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Mar 3, 2016 at 10:40 AM William Burns <<a href="mailto:mudokonman@gmail.com">mudokonman@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Mar 3, 2016 at 10:26 AM Sanne Grinovero <<a href="mailto:sanne@infinispan.org" target="_blank">sanne@infinispan.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 3 March 2016 at 15:19, William Burns <<a href="mailto:mudokonman@gmail.com" target="_blank">mudokonman@gmail.com</a>> wrote:<br>
> I now have a working branch that is using this for the new CacheStream<br>
> interface [1].<br>
><br>
> With this it allows users to use a stream without needing any casts for any<br>
> of the intermediate or terminal operations. Note I completely revamped the<br>
> BaseStreamTest [2] So in that case every example a user can find online can<br>
> be pretty much copy pasted without additional changes, which to me is HUGE.<br>
<br>
I agree, it's HUGE! Great work!<br></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>Oh I forgot to mention the 1 caveat with this approach. If the user defines their Cache or the various collections returned from it as the base type (ie. Map, ConcurrentMap, Set, Collection) this automatic serialization is lost and would require manual casting again. Normal method chaining keeps this benefit though. This seems like an acceptable and unavoidable issue to me.</div></div></div></blockquote><div><br></div><div>Sorry also these changes still require the use of the CacheCollectors when using [1] like we have had in the past it. It just removes the need for all of the various casting (ie. (Serializable & Function<? super R>) for the other methods.</div><div><br></div><div>[1] <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#collect-java.util.stream.Collector-">https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#collect-java.util.stream.Collector-</a></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
><br>
> Unfortunately this causes the API to bloat quite a bit and I had to add a<br>
> bunch of Serializable* classes (ex. [3]). The former bloat issue seems<br>
> acceptable to me, I had thought about making a new separate API, but it<br>
> seems like it is unneeded to me. The latter issue I had tried defining the<br>
> generics on the method itself but the compiler can't quite figure out which<br>
> method to invoke still [4].<br>
<br>
Rather than making many things serializable, did you consider to extend<br>
our collection of JBoss Marshallers?<br>
Maybe support for marshalling many of JDK's stream components could<br>
be contributed directly to the Marshaller project.<br></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>I personally haven't looked at this aspect. To be honest, I was leaning on Galder a bit more here, since he is much more familiar with the Marshalling code. If we can do this instead I think it would be even bigger. Unfortunately I don't know how feasible it is.</div></div></div><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
><br>
> I am still planning on adding a CacheIntStream, CacheDoubleStream and<br>
> CacheLongStream interfaces as well. Without those users would need to do<br>
> casts on the subsequent primitive stream if they used any of the<br>
> mapTo<Int|Double|Long> or flatMapTo<Int|Double|Long> methods.<br>
><br>
> Another side benefit of this refactoring is we can easily add new operations<br>
> to the stream interfaces. We could add approximation methods maybe that<br>
> return after a certain timeout, histogram specific support among others. I<br>
> am open to whatever people think they would want added here. Unfortunately,<br>
> we can't easily add in a Map.Entry stream (similar to spark PairRDD) without<br>
> redoing a bunch more of the APIs and I don't know if we have time to support<br>
> that.<br>
><br>
> Any feedback would be great, hoping to get this ironed out soon before API<br>
> freeze :)<br>
><br>
> Cheers,<br>
><br>
> - Will<br>
><br>
> [1] <a href="https://github.com/wburns/infinispan/tree/ISPN-6272" rel="noreferrer" target="_blank">https://github.com/wburns/infinispan/tree/ISPN-6272</a><br>
> [2]<br>
> <a href="https://github.com/wburns/infinispan/commit/09734d533a445df23df94f7a053b11bc496422ec#diff-170c50a8f618af028f238109f0f1392a" rel="noreferrer" target="_blank">https://github.com/wburns/infinispan/commit/09734d533a445df23df94f7a053b11bc496422ec#diff-170c50a8f618af028f238109f0f1392a</a><br>
> [3]<br>
> <a href="https://github.com/wburns/infinispan/blob/ISPN-6272/core/src/main/java/org/infinispan/util/SerializableFunction.java" rel="noreferrer" target="_blank">https://github.com/wburns/infinispan/blob/ISPN-6272/core/src/main/java/org/infinispan/util/SerializableFunction.java</a><br>
> [4] <a href="https://gist.github.com/wburns/dffe4f7543f68215f74b" rel="noreferrer" target="_blank">https://gist.github.com/wburns/dffe4f7543f68215f74b</a><br>
><br>
><br>
><br>
> On Wed, Feb 17, 2016 at 8:39 AM William Burns <<a href="mailto:mudokonman@gmail.com" target="_blank">mudokonman@gmail.com</a>> wrote:<br>
>><br>
>> Actually I have a PR that will go in before the 8.2 Final release that<br>
>> uses this [1]. Specifically check out the ClusterExecutor interface. It<br>
>> doesn't have the issues of streams with overloading existing methods,<br>
>> however it adds both overloaded variants and you can see how the tests<br>
>> invoke those.<br>
>><br>
>> [1] <a href="https://github.com/infinispan/infinispan/pull/4008" rel="noreferrer" target="_blank">https://github.com/infinispan/infinispan/pull/4008</a><br>
>><br>
>><br>
>> On Wed, Feb 17, 2016 at 3:23 AM Galder Zamarreño <<a href="mailto:galder@redhat.com" target="_blank">galder@redhat.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hey Will,<br>
>>><br>
>>> A very interesting discovery!<br>
>>><br>
>>> Do you have a branch were you've tried this out? I'd like to play with it<br>
>>> to see it in action and analyse the downsides more closely.<br>
>>><br>
>>> Cheers,<br>
>>> --<br>
>>> Galder Zamarreño<br>
>>> Infinispan, Red Hat<br>
>>><br>
>>> > On 9 Feb 2016, at 17:36, William Burns <<a href="mailto:mudokonman@gmail.com" target="_blank">mudokonman@gmail.com</a>> wrote:<br>
>>> ><br>
>>> > I wanted to propose a pretty simple way of making the lambdas<br>
>>> > serializable by default that I stumbled upon while working on another issue.<br>
>>> ><br>
>>> > I noticed that in the method resolution of the compiler it does some<br>
>>> > nice things [1]. To be more specific when you have 2 methods with the same<br>
>>> > name but vary by argument types, it will attempt to pick the most "specific"<br>
>>> > one. Specific in this case you can think of if I can cast one argument type<br>
>>> > to the other but it can't be cast to this type, then this one is most<br>
>>> > specific.<br>
>>> ><br>
>>> > Here is an example, given the following class<br>
>>> ><br>
>>> > interface SerializableFunction<T, R> extends Serializable, Function<T,<br>
>>> > R><br>
>>> ><br>
>>> > The stream interface already defines:<br>
>>> ><br>
>>> > Stream map(Function<? super T, ? extends R> mapper);<br>
>>> ><br>
>>> > But we could add this to the CacheStream interface<br>
>>> ><br>
>>> > CacheStream map(SerializableFunction<? super T, ? extends R> mapper);<br>
>>> ><br>
>>> > In this case you have 2 different map methods accessible from your<br>
>>> > CacheStream instance. When passing a lambda the Java compiler will<br>
>>> > automatically choose the most specific one (in this case the<br>
>>> > SerializableFunction one since Function can't be cast to<br>
>>> > SerializableFunction). This will then make the lambda automatically<br>
>>> > Serializable. In this way nothing special has to be done (ie. explicit<br>
>>> > cast) to make the instance Serializable.<br>
>>> ><br>
>>> > This allows anyone using our Cache interface to immediately get lambdas<br>
>>> > that are Serializable when using Streams.<br>
>>> ><br>
>>> > The main problem however would be ambiguity because the Serialization<br>
>>> > would only be applied assuming you are using a defined class of CacheStream<br>
>>> > etc. Also this means there are 2 methods (but that seems fine to me), so it<br>
>>> > could cause a bit of confusion. The non serialization method is still<br>
>>> > helpful if people want to their own Externalizer, since their implementation<br>
>>> > doesn't have to implement Serializable then.<br>
>>> ><br>
>>> > What do you guys think? It seems like a decent compromise to me.<br>
>>> ><br>
>>> > - Will<br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> > [1]<br>
>>> > <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.2.5" rel="noreferrer" target="_blank">https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.2.5</a><br>
>>> ><br>
>>> ><br>
>>> > _______________________________________________<br>
>>> > infinispan-dev mailing list<br>
>>> > <a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
>>> > <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> infinispan-dev mailing list<br>
>>> <a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
>>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
><br>
><br>
> _______________________________________________<br>
> infinispan-dev mailing list<br>
> <a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a></blockquote></div></div></blockquote></div></div>