Sending code to an actor

89 views
Skip to first unread message

G J

unread,
Nov 28, 2012, 6:24:51 AM11/28/12
to akka...@googlegroups.com
I'd like to have a definition similar to:

trait Message
case class Action(act: A => B) extends Message

My first attempt resulted in an exception related to class loaders, class not found, and anonymous functions.   In the test, act was the increment function and therefore referred to nothing that was not in the class path at the remote node.

Is there a simple way to accomplish this?

Best Regards.


√iktor Ҡlang

unread,
Nov 28, 2012, 7:26:46 AM11/28/12
to Akka User List
Try putting the function in an object:

object Functions {
  val increment: Int => Int = _ + 1
}

actor ! Action(Functions.increment)

Please note however that sending arbitrary functions is a huge security hole.

Cheers,


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
 
 



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

G J

unread,
Nov 28, 2012, 8:28:39 AM11/28/12
to akka...@googlegroups.com
Thanks Viktor.  it still does not work if I do that in the interactive loop:

   Error[java.lang.ClassNotFoundException:$line3.$read$$iw$$iw$$anonfun$1

It works if I embed the same interaction in an object, but that's not what I want.

A bit of context:

We have data/tables on remote nodes that we hope to interact with via actors. The interaction is really SQL-like queries except Scala is used in place of SQL. Hence our need for sending code typed (and therefore OTF compiled) into the interactive loop.

Perhaps, there is a better approach...

Best Regards.
-----------------------------

√iktor Ҡlang

unread,
Nov 28, 2012, 8:34:01 AM11/28/12
to Akka User List
No, how could it work, that class doesn't exist on the other end. (If you define it at runtime in the REPL)

Cheers,

G J

unread,
Nov 28, 2012, 9:11:17 AM11/28/12
to akka...@googlegroups.com
Maybe you're right.

It would be necessary to marshal the code and all its dependencies and ship it. I believe I did this sort of thing in Python, but it's been a while. In using a horrible version of MapReduce our solution was to bundle up jar files and copy them to all the remote nodes. Etc.

Whatever happened to remotely programming microwave ovens using verified/certified bytecode...;-)

Best regards.

Lee Mighdoll

unread,
Nov 29, 2012, 2:38:02 PM11/29/12
to akka...@googlegroups.com, Matei Zaharia
The spark guys are shipping code around between nodes.  They let users type code snippets into a local console for execution on the cluster.  The code snippet is compiled locally, serialized, and shipped to the cluster nodes.  As far as I know, they still rely on pre-positioned library jars.  

Take a peek at spark's technique if you're interested.

Code mobility is neato.  It'd be fun to see a common library come out for that.

Cheers,
Lee  

Niall Gallagher

unread,
Jul 2, 2013, 12:02:13 PM7/2/13
to akka...@googlegroups.com, Matei Zaharia, l...@underneath.ca
Code mobility is neato.  It'd be fun to see a common library come out for that.

Have you guys looked at mobility-rpc[1] for this? It is a general purpose code mobility library, it would (or should!) allow closures to be sent to remote machines like this.
 
Reply all
Reply to author
Forward
0 new messages