Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka doc is unclear about how to get an ExtendedActorSystem to deserialize ActorRef

Tags:

akka-cluster

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?

like image 419
stackoverflower Avatar asked Jul 02 '17 22:07

stackoverflower


1 Answers

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].

like image 136
SourceCodeBot Avatar answered Nov 03 '22 01:11

SourceCodeBot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!