I reckon there might be a broader question of application design using Akka hidden in here but I'll ask how does one set up a supervision tree where a "kernel" or "top" supervisor might supervise children that are other supervisors which supervisor workers?
2
votes
Make the top supervisor spawn and link the other supervisors, and have those supervisors spawn and link workers.
– Viktor Klang
Thanks Viktor, are you aware of an example doing that programatically vs. declaratively?
– Tim
You'll have to do it programmatically, check this out for docs: doc.akka.io/fault-tolerance-scala
– Viktor Klang
@Viktor: I converted your suggestions into an answer. Hope that's ok.
– Steffen
If I have some time I may push out an example to github. I've been using this setup in java quite happily.
– chaostheory
1 Answers
1
votes
You might start with a declarative supervisor on the top level
val kernel = Supervisor(
SupervisorConfig(
OneForOneStrategy(List(classOf[Exception]), 3, 1000),
Supervise(
actorOf[Module1],
Permanent) ::
Supervise(
actorOf[Module2],
Permanent) ::
Supervise(
actorOf[Module3],
Permanent) ::
Nil
)
)
where module 1 to 3 represents the next level of your application architecture. Each module itself is a supervisor for all of its child actors and implemented like for example
class Module1 extends Actor {
self.faultHandler = OneForOneStrategy(List(classOf[Throwable]), 5, 5000)
def receive = {
case Register(actor) =>
self.link(actor)
}
}
You might replace the "Register(actor)" message with something more suitable for your application, and you might want to span a further programmatically created supervisor layer but basically that would be the approach to follow.
You'll find further details (as Viktor already commented) in the official akka documentation on Fault tolerance with Scala or Fault tolerance with Java.