- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Akka 已弃用 actorFor
赞成 actorSelection
.前者返回 ActorRef
而后者返回 ActorSelection
这可能是 ActorRef
的集合s。
从 actorFor
迁移时至 actorSelection
,你有几个选项:
选项 1:两者 ActorSelection
和 ActorRef
有一个 tell
方法,所以你几乎可以交换actorSelection
为 actorFor
(这并不总是正确的 - ask
不一样并且 actorSelection
可以指向多个 ActorRef
s)只要该选择只有一个 Actor 并且您只是 tell
Actor 。
选项 2:获取 ActorRef
来自 ActorSelection
.这可以使用 Identify
来完成。 (涉及更多消息)或 resolveOne
(其中涉及 Future
)。
在选项 1 中,ActorSelection
有什么样的开销?相较于 ActorRef
添加来自 actorFor
?
有没有比上面列出的更好的选择?
最佳答案
使用 ActorSelection
会产生开销与 ActorRef
, 具体来说:
It is not as performant as with ActorRef, since it has to traverse the hierarchy of actors in the path. If you use remote sends the actor selection traversal will unlikely be the bottleneck, but you have to verify that for your specific usage. We optimized ActorSelection in 2.3.x, so it will be faster when you update to that version.
关于scala - ActorSelection 与 ActorRef - 从 actorFor 迁移到 actorSelection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24834466/
我正在学习 Akka,并试图弄清楚如何让 Actor 互相交谈(我们称他们为 A 和 B)。这不是请求/响应场景,A和 B随时互相发送消息。 目前我有两个兄弟 Actor ,他们在两个方向上互相传递消
我想获得一个可能已经创建的 ActorRef。是否有一种标准的方法来调用 context.actorFor,并且只有当它没有返回实时 ActorRef 时,才调用 context.actorOf?反之
代码是: // pilot = Await.result(context.actorSelection(s"../$pilotName").resolveOne, 5.seconds)
Akka 已弃用 actorFor赞成 actorSelection .前者返回 ActorRef而后者返回 ActorSelection这可能是 ActorRef 的集合s。 从 actorFor
我是一名优秀的程序员,十分优秀!