Akka文档尚不清楚如何获取ExtendedActorSystem以反序列化ActorRef

sta*_*wer 8 akka akka-cluster

我正在尝试通过protobuf序列化/反序列化ActorRef。根据Akka的文档,唯一的方法是将ActorRef转换为String,然后将其转换回远程actor系统。

该文档提到使用an ExtendedActorSystem进行反序列化(请参阅此处)。但是,尚不清楚如何获取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
Run Code Online (Sandbox Code Playgroud)

编辑

我在这里找到了这个问题:Akka(JVM):在另一条消息中使用protobuf序列化actorref,其中提到将转换ActorSystemExtendedActorSystem。这是正确的方法吗?它会一直有效吗?

小智 1

亲爱的@stackoverflower,

每当您使用ActorSystem(...)它时都会构建一个ActorSystemImpl.

类型树看起来像:

ActorSystemImpl extends ExtendedActorSystem

ExtendedActorSystem implements ActorSystem

你可以使用类似的语句

val system: ExtendedActorSystem = ActorSystem(...).asInstanceOf[ExtendedActorSystem]

访问正确的类型自动完成。ActorSystemImpl不幸的是,范围是[akka].