gpt4 book ai didi

scala - 如何打印akka系统中的所有 Actor ?

转载 作者:行者123 更新时间:2023-12-03 14:45:34 24 4
gpt4 key购买 nike

我创建了akka系统。假设里面有一些 Actor 。我如何用他们的路径打印来自akka系统的所有 Actor ? (用于调试目的)

最佳答案

This reply by Roland Kuhn表明这不是一个完全微不足道的问题,但您可以使用 Identify - ActorIdentity 非常接近(对于将在合理时间内回复消息的参与者)所有参与者都遵守的请求-响应协议(protocol)。

一些未经测试的代码拼凑在一起来说明这个想法:

import akka.actor._

def receive = {
case 'listActors =>
context.actorSelection("/user/*") ! Identify()

case path: ActorPath =>
context.actorSelection(path / "*") ! Identify()

case ActorIdentity(_, Some(ref)) =>
log.info("Got actor " + ref.path.toString)
self ! ref.path
}

关于scala - 如何打印akka系统中的所有 Actor ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25860939/

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