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

问题描述 投票:9回答:1

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

该文档提到使用ExtendedActorSystem进行反序列化(请参见here)。但是,尚不清楚如何获取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

编辑

[我在这里找到了这个问题:Akka (JVM): Serialize an actorref with protobuf within another message,其中提到将ActorSystem强制转换为ExtendedActorSystem。这是正确的方法吗?它会一直有效吗?

akka-cluster
1个回答
0
投票

亲爱的@stackoverflower,

无论何时使用ActorSystem(...),它都会构建一个ActorSystemImpl的实例。

类型树看起来像:

ActorSystemImpl extends ExtendedActorSystem

ExtendedActorSystem implements ActorSystem

您可以使用类似的语句

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

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

© www.soinside.com 2019 - 2024. All rights reserved.