0

First of all, I'm pretty new to Akka and actor model, so maybe I'm doing everything wrong.

I have an input actor, which gets data from stream source and passes them on to child processor actors, which have some internal state. Input actor may crash if its connection dies, which triggers its restart. The problem is that in addition that triggers a restart of its children, which makes them lose their state. I don't want that, as the input stream might recover and their state will become relevant again. Also, processors are spawned in reaction to some data in the input, so I don't see a way of creating them outside the input actor.

In other words, the question is "how do I restart only input of actor pipeline without restarting further stages"?

fghkngfdx
  • 135
  • 4
  • Please look at this answer: http://stackoverflow.com/questions/20528411/prevent-akka-actor-from-restarting-child-actor The short answer is: no, you can't restart parent actor without restarting his children actors. You can store the actor state somewhere outside the JVM (take a look at akka persistence). – codejitsu Aug 05 '16 at 11:38

2 Answers2

1

Basically there are 3 types of reasons for an Actor to restart (1) Systematic error for example when an Exception occurs (2) transient errors which is totally the stuff you are dealing with (connection loss) and (3) corrupt interal state. Because you have a parent-child relation the restart of its childs will occur. At this point Iam not sure if you can handle it via SupervisionStrategy. Therefore take a look here http://doc.akka.io/docs/akka/snapshot/general/supervision.html#What_Restarting_Means - it's also the source Iam "citing)

Another way to handle this maybe an fault tolerant handling of your connection. Here you have to approaches: (1) Put the connection handling also error handling into a separate child-actor. The underlying supervision strategy will be OneForOne (default) which means if the child dies only the child will restart.

(2) You have two root Actors which will be actor of the actor system. One connectionActor and your inputActor. You will pass the instance of the connectionActor to the inputActor or the other way around whether ask for the data from the connectionActor or you will send the data to the inputActor.

If you're new to akka-actors this is quite a bit hard. But I recommend to read the introduction of the documentation (according to the version you are using): http://doc.akka.io/docs/akka/snapshot/scala.html

sascha10000
  • 1,245
  • 1
  • 10
  • 22
0

The perfect solution for this case is the use of Akka Persistence. Use the akka-persistence with the db that you are using and save the internal state of the actors

You can find more about it here: http://doc.akka.io/docs/akka/current/scala/persistence.html

I hope I solved your problem ! Thanks :)

Shivansh
  • 3,454
  • 23
  • 46