3

When the System is restarted, the context.children() call returns zero children for a particular parent. Before restart, context.children() returned the actual count of children that parent had.

Can someone please let me know how can we get the children ActorRef for a parent after restart?

My use case is:

Before restart, there are let say 5 children of a parent. Now, i wish to calculate performance and to calculate performance i need participation from all these 5 children. So, after restart, i could just send the same message to all children, after which children will work and respond to parent. However, after restart, i am not even aware of who the children were. So, what's the best way to solve these type of problems?

achin
  • 169
  • 8

2 Answers2

0

One way is to make the parent actor persistent while making its state as list of children ids. This way, when the system restarts and parent is re-created, it will restore its state.

flare
  • 344
  • 2
  • 6
0

The only issue with 'parent-child' actors relation where child is a persistent actor is that when you restart your application that 'parent-child' relation itself is lost. Basically, this relation itself is not persistent.

So as flare mentioned you need to make your parent actor persistent as well and to maintain all children's names. And then during the restart your persistent parent actor have to manually recreate all those 'parent-child' relations based on the stored IDs (names) via context.actorOf(...)

Andrei
  • 303
  • 3
  • 7