Open Adam5Wu opened 8 years ago
Sending Java 8 lambdas to remote machines is not officially supported yet. At the moment Mobility-RPC targets Java 6 and later, but some newer language features are not guaranteed to work.
I'm going to rename this issue to Add support for sending lambdas, as I want to add support for this.
Hi, I have in the past investigated serialization of lambdas. It basically works out of the box if Java serialization is used and the interface that the lambda is implementing is serializable. So the probable solution to this is to allow the user of Java serialization instead of Kryo.
The other solution is to enable lambda serialization in Kryo: https://github.com/magro/kryo/blob/bf803974ba6351d993093636aac00245f1ec28bc/test/com/esotericsoftware/kryo/serializers/Java8ClosureSerializerTest.java#L52 This could be done with reflection to prevent a dependency on Java8.
I'm not too concerned about Java 6 compatibility anymore. And I think Java 8 lambdas are quite a natural way to send tasks to remote machines.
@BrynCooke I like the second option, to enable Java 8 closure support in Kryo. If you have time to try that out by modifying the KryoSerializer class in mobility-rpc and testing locally, it would help. I'm totally open to merging pull requests which would help with this!
The main challenge I can envisage is that currently the mobility-rpc protocol supports sending only Runnable or Callable objects. Any other type of object to be sent (including lambdas) need to be wrapped in one of these. So the easiest solution if we want to send a lambda, is to write a helper method which wraps the lambda in a Runnable or Callable object. If this is possible then it should not be a problem to send a lambda.
Thanks, I'll create a PR.
Triggers exception message on the server:
However, if a formal inheritance class is made like the test code in #11, then the error is gone.