加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – Akka actorSelection vs actorOf差异

发布时间:2020-12-16 18:18:34 所属栏目:安全 来源:网络整理
导读:这两者有区别吗?当我做: context.actorSelection(actorNameString) 我得到一个ActorSelection引用,我可以使用resolveOne解析它,然后我得到一个Future [ActorRef].但是对于actorOf,我立即获得了ActorRef.除此之外还有其他重要的区别吗? 在我希望将ActorRef
这两者有区别吗?当我做:

context.actorSelection(actorNameString)

我得到一个ActorSelection引用,我可以使用resolveOne解析它,然后我得到一个Future [ActorRef].但是对于actorOf,我立即获得了ActorRef.除此之外还有其他重要的区别吗?

在我希望将ActorRef包装在Future中的用例可能是什么?

解决方法

actorOf用于通过提供其Props对象来创建新actor.

actorSelection是actor树中路径的“指针”.通过使用resolveOne,您将在该路径下获得已存在的actor的actorRef – 但是actorRef需要时间来解析,因此Future.

这里有更详细的解释:
http://doc.akka.io/docs/akka/snapshot/general/addressing.html

An actor reference designates a single actor and the life-cycle of the reference matches that actor’s life-cycle; an actor path represents a name which may or may not be inhabited by an actor and the path itself does not have a life-cycle,it never becomes invalid. You can create an actor path without creating an actor,but you cannot create an actor reference without creating corresponding actor.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读