开发者

Is there a way in scala to execute arbitrary code on a remote node around using RemoteActor?

For example, I have a trusted client and a server.开发者_StackOverflow The client wants to execute arbitrary code on the server. Can this be achieved using RemoteActor (serialize a function and send it across the network, deserialize it and execute it)?


Here's an example of using URLClassLoader with remote actors, to fetch the classes via http from the client and execute generic computations on the server.

You may also be interested in HotSwap technique applied to serializable Akka Actors.


Not currently. Serializing a function means storing its fields into a object output stream and deserializing it means reading the function object from an object input stream somewhere else. Deserialization presumes that the class of the object being read from the object input stream is known to the JVM. Remember - functions are just objects behind the scene.

In this case, the server does not know the actual concrete class of the function object you're serializing, just possibly that it implements the Function interface. To support such a functionality, you'd have to locate the class file of the function in question, send it to the server, and load it on the server using a custom classloader. Then, if the object has any kind of state, you could serialize the object on the client, send it over the network and deserialize it on the server. Only then can you run its methods. Assuming your function objects are stateless, which is usually the case, you could skip the serialization/deserialization step.

EDIT:

Remember, also, that functions may internally hold references to their calling environments. This means you might end up serializing the environment of a function object along with it, which can potentially be your entire program data..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜