1

This earlier question suggests that calling 'stop' on a supervisor actor will shut down all linked actors. However, if one creates a 'custom' actor (not through a factory), it seems that this auto-shutdown doesn't happen. For example, see this code from the answer to another question:

class Module1 extends Actor {
   self.faultHandler = OneForOneStrategy(List(classOf[Throwable]), 5, 5000)

   def receive = {
       case Register(actor) =>
           self.link(actor)
   }
}

If 'stop' was called on the above Module1 actor, the actors linked to it wouldn't shut down. Is there a way to make a custom actor automatically shut down linked actors? Or is this just something that you have to write yourself if you want to create a custom actor?

Thanks!

Community
  • 1
  • 1
bnsmith
  • 1,667
  • 19
  • 30

1 Answers1

2

You can call:

self.linkedActors.values.iterator

and then send a PoisonPill or stop() them.

Ibraheem
  • 25
  • 1
  • 8
Viktor Klang
  • 26,479
  • 7
  • 51
  • 68
  • being in a nit-picky mood: might be good to mention that postStop() is the perfect place to put this code ;-) – Roland Kuhn Dec 17 '11 at 16:11
  • I saw some code like that in the SupervisorActor class in the Akka source code. So I could copy and paste that code from SupervisorActor into my own custom supervisor class for sure. I was just wondering if there was a better way than copy-and-paste coding. Are there any other behaviors that I need to copy and paste into my custom supervisor? Like the ability to restart child Actors that have crashed? – bnsmith Dec 17 '11 at 21:21
  • Nope, that should be it. Although, should be noted that you don't need to do it manually in 2.0-M1 and forward. – Viktor Klang Dec 18 '11 at 23:20