How print all actors in akka system?

后端 未结 3 1466
醉梦人生
醉梦人生 2021-01-31 05:07

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)

3条回答
  •  借酒劲吻你
    2021-01-31 05:51

    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
    }
    

提交回复
热议问题