Why is classloader setup necessary with Scala RemoteActors?

When using Scala RemoteActors, I was getting a ClassNotFoundException that was referring to scala.actors.remote.NetKernel. I copied some other example and added to RemoteActor.classLoader = getClass.getClassLoadermy actor, and now everything works. Why is this necessary?

+5
source share
1 answer

Remote participants use Java serialization to send messages back and forth. Inside the actors library you will find a custom input stream for objects ( https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/actors/scala/actors/remote/JavaSerializer.scala ), which is used to serialize objects to / from socket. It also has routing code and other magic.

In any case, the ClassLoader used for remote access is very important. I would recommend looking for Java RMI if you are not familiar with it. In any case, the ClassLoader that Scala selects when it serializes / deserializes the actors is the one set to RemoteActor, which defaults to null.

This means that by default you will be unhappy without specifying ClassLoader;).

, , OSGi, , , , .

, !

+5

All Articles