How print all actors in akka system?

后端 未结 3 1470
醉梦人生
醉梦人生 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:49

    According to the documentation you can use ActorSelection with a wildcard * to make actors send identifying messages. You can have an actor that collect the ActorRefs.

    As mentioned by @chris-martin only actors that are not currently busy will send. A very simple actor:

    // make all the available actor to send an identifying message
    public void freeActors()
    {
      ActorSelection selection =
        getContext().actorSelection("/user/*");
      selection.tell(new Identify(identifyId), getSelf());
    }
    
    ...
    // collect responses
    @Override
    public void onReceive(Object message) {
      if (message instanceof ActorIdentity) {
        ActorIdentity identity = (ActorIdentity) message;
        // get the ref of the sender 
        ActorRef ref = identity.getRef();
        // the sender is up and available
       ...
    

    EDIT: I know this is for Java, but it seemed helpful to me.

提交回复
热议问题