gpt4 book ai didi

java - 是否可以从 ActorSelection 中检索多个 actorRef?

转载 作者:行者123 更新时间:2023-12-01 11:09:22 25 4
gpt4 key购买 nike

我尝试从 ActorSelection 获取多个 ActorRef。有人知道是否可能吗?

我的代码

ActorRef actorRef = Await.result(getContext().actorSelection("/user/regions/*").resolveOne(timeout), timeout.duration());

最佳答案

不可能使用resolveOne,顾名思义,它返回单个引用。您可以向 ActorSelection 发送一条消息,该消息会将消息发送给与选择匹配的每个 Actor,并让这些 Actor 进行回复。如果您使用内置的 Identify 消息,那么您根本不需要更改接收参与者。来自 http://doc.akka.io/docs/akka/snapshot/scala/actors.html#Identifying_Actors_via_Actor_Selection 的文档:

Messages can be sent via the ActorSelection and the path of the ActorSelection is looked up when delivering each message. If the selection does not match any actors the message will be dropped.

To acquire an ActorRef for an ActorSelection you need to send a message to the selection and use the sender() reference of the reply from the actor. There is a built-in Identify message that all Actors will understand and automatically reply to with a ActorIdentity message containing the ActorRef. This message is handled specially by the actors which are traversed in the sense that if a concrete name lookup fails (i.e. a non-wildcard path element does not correspond to a live actor) then a negative result is generated. Please note that this does not mean that delivery of that reply is guaranteed, it still is a normal message.

关于java - 是否可以从 ActorSelection 中检索多个 actorRef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32555118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com