Akka - How to restart a child spawned by a router?

697 views Asked by At

I have an Actor that creates children using a Router. When one of the children fail. I'm being notified in the startegy about the failure. However the Actor does not restart by itself.

private static SupervisorStrategy strategy = new OneForOneStrategy(10, Duration.create("1 minute"),
        throwable -> {
            Directive directive;
            if (throwable instanceof SocketTimeoutException) {
                directive = SupervisorStrategy.restart();
            } else {
                directive = SupervisorStrategy.stop();
            }
            return directive;
        });

I also found out from this SO post that if a child of a Router terminates, the Router will not automatically spawn a new child. And also, when all of the router's children terminate, the Router terminates itself as well.

Now the million dollar question - What is the right way to restart a child that was spawned by a Router?

1

There are 1 answers

1
Konrad 'ktoso' Malawski On

It seems that you're using a Pool router (it starts its own children). Instead what you want to use is a Group router (group router docs) in which case you create the child Actors and supply them to the router. This means that you're in charge (you as in the parent actor of these routees) is fully in charge of their lifecycle. So there you'd define the supervision strategy in the parent and all works as you'd want it to then.