Reputation: 4063
I'm trying to serialize/deserialize ActorRef through protobuf. According to the Akka doc, the only way to do it is to convert the ActorRef into a String, and convert it back in the remote actor system.
The doc mentions using an ExtendedActorSystem
to do the deserialization (see here). However, it is unclear how to get the ExtendedActorSystem
:
// Serialize
// (beneath toBinary)
val identifier: String = Serialization.serializedActorPath(theActorRef)
// Then just serialize the identifier however you like
// Deserialize
// (beneath fromBinary)
// ==== Where is this extendedSystem from? ====
val deserializedActorRef = extendedSystem.provider.resolveActorRef(identifier)
// Then just use the ActorRef
Edit
I found this question here: Akka (JVM): Serialize an actorref with protobuf within another message, which mentions casting an ActorSystem
to ExtendedActorSystem
. Is this the right approach? Will it always work?
Upvotes: 9
Views: 755
Reputation: 175
dear @stackoverflower,
whenever you use ActorSystem(...)
it build an instance of ActorSystemImpl
.
The type-tree looks like:
ActorSystemImpl extends ExtendedActorSystem
and
ExtendedActorSystem implements ActorSystem
you can use statements like
val system: ExtendedActorSystem = ActorSystem(...).asInstanceOf[ExtendedActorSystem]
to access the correct type autocomplete. ActorSystemImpl
is unfortunately scoped to [akka]
.
Upvotes: 1