I have a supervisor actor per node which is already subscribed to cluster 
events,
I avoided using ask when the actor system is going down anyway and it is 
driven by the JVM shutdown hook,
so instead I came up with this hack, maybe a bit ugly but it works:

For supervisor actor which once it receives MemberRemoved for itself it 
terminates the actor system:
      if (message instanceof MemberRemoved) {
        final Member member = ((MemberRemoved) message).member();
        final ActorSystem system = context().system();
        if (Cluster.get(system).selfAddress().equals(member.address())) {
          // It was me that left so, terminate actor system.
          system.terminate();
        } else {
          // Invalidates that other supervisor cache that left.
          removeSupervisor(member);
        }
      }

For main class which once the system is shutdown it also shutdowns the 
logger manager:
  public static void registerShutdownHook(ActorSystem system) {
    final CountDownLatch latch = new CountDownLatch(1);
    system.registerOnTermination(() -> {
      try {
        Configurator.shutdown((LoggerContext) LogManager.getContext());
      } finally {
        latch.countDown();
      }
    });
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        final Cluster cluster = Cluster.get(system);
        cluster.leave(cluster.selfAddress());
        try {
          latch.await();
        } catch (InterruptedException ignored) {
        }
      }
    });
  }

Regards,

Guido.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to