如何在Akka系统中打印所有演员? [英] How print all actors in akka system?

查看:105
本文介绍了如何在Akka系统中打印所有演员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了akka系统。假设其中有一些参与者。如何从Akka系统中使用其路径打印所有演员? (出于调试目的)

I have created akka system. Suppose there are some actors in it. How I can print all actors from akka system with their path? (for debug purposes)

推荐答案

罗兰·库恩(Roland Kuhn)的回复表明,这并不是一个完全无关紧要的问题,但是您可以很接近(对于将回复消息的演员在合理的时间内)使用 标识所有参与者都遵循的- ActorIdentity 请求-响应协议。

This reply by Roland Kuhn suggests that this isn't a completely trivial problem, but you can get pretty close (for actors that will reply to messages in a reasonable time) using the Identify-ActorIdentity request-response protocol that all actors obey.

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

Some untested code thrown together to illustrate the idea:

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
}

这篇关于如何在Akka系统中打印所有演员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆