Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2012 17:24
Show Gist options
  • Save anonymous/4026158 to your computer and use it in GitHub Desktop.
Save anonymous/4026158 to your computer and use it in GitHub Desktop.
class ActorRefSerializer(val system: ExtendedActorSystem) extends kryo.Serializer[ActorRef] {
override def read(kryo: Kryo, input: Input, typ: Class[ActorRef]): ActorRef = {
val path = input.readString()
system.actorFor(path)
}
override def write(kryo: Kryo, output: Output, obj: ActorRef) = {
Serialization.currentTransportAddress.value match {
case null => output.writeString(obj.path.toString)
case addr => output.writeString(obj.path.toStringWithAddress(addr))
}
}
}
//////////////
// And then inside getKryo...
kryo.addDefaultSerializer(classOf[ActorRef], new ActorRefSerializer(system))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment