I am trying to send a message using akka remote participants, where the case class is a subclass of the superclass taking an argument in its constructor.
Here is a minimal example to reproduce the problem:
package com.tuvistavie.testremote import akka.actor.{ Actor, ActorSystem, Props, ActorLogging } import com.typesafe.config.ConfigFactory abstract class Foo(val a: Int) case class MessageFoo(override val a: Int) extends Foo(a) object Sender { def main(args: Array[String]) { val system = ActorSystem("Sender", ConfigFactory.load.getConfig("sender")) val actor = system.actorFor("akka:// Receiver@127.0.0.1 :2552/user/receiver") actor ! MessageFoo(1) } } object Receiver { class ReceiverActor extends Actor with ActorLogging { def receive = { case m: MessageFoo => log.debug(m.toString) } } def main(args: Array[String]) { val system = ActorSystem("Receiver", ConfigFactory.load.getConfig("receiver")) val actor = system.actorOf(Props[ReceiverActor], "receiver") } }
When I run this code, I get the following error:
[ERROR] [06/26/2013 02:53:16.132] [Receiver-9] [NettyRemoteTransport(akka:// Receiver@127.0.0.1 :2552)] RemoteServerError@akka :// Receiver@127.0.0.1 :2552] Error[java.io.InvalidClassException: com.tuvistavie.testremote.MessageFoo; no valid constructor]
I think this is because the message cannot be deserialized (using akka.serialization.JavaSerializer ) due to the parent constructor. If it were only one or two messages that I know, I could write my own serializer, but in my application I have many case classes.
Will there be any easy way to pass this type of objects using remote participants?
source share