Akka - how to tell the system what to do after reaching the maximum magic of the strategy?

Assuming that the supervisor actor defined a specific strategy:

    private static SupervisorStrategy strategy =
        new OneForOneStrategy(10, Duration.create("1 minute"), DeciderBuilder.
                match(Exception.class, e -> resume()).
                matchAny(o -> escalate()).build());

And let's say the actor was asked to resume it, but it failed 11th time for the current duration.

What is happening now?

Is the parent actor an escalation of the problem?

Is there any way to stop an actor in an orderly way (for example, tell a child actor to close the database connection)?

Is there any other overide method to call in this case?

+4
source share
2 answers

, , .

0

maxNrOfRetries withinTimeRange OneForOneStrategy restart(); resume(). , 11 , , , 11 .

Exception, , , resume(). -t25 > (.. Error), escalate(). , Error, .

, Map ActorRef , . , sender . , , . - ( Scala, Java):

class Parent extends Actor {

  override val supervisorStrategy =
    OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
      case _: Exception =>
        val child = sender
        resumeCounts.get(child) match {
          case Some(count) if count == resumeMax =>
            child ! StopDB
          case Some(count) =>
            resumeCounts = resumeCounts + (child -> count + 1)
          case None =>
            resumeCounts = resumeCounts + (child -> 1)
        }
        Resume
      case _ => Escalate
    }

  val resumeMax = 10
  var resumeCounts: Map[ActorRef, Int] = Map.empty[ActorRef, Int]

  def receive = ???
}

, .

restart(), , " , maxNrOfRetries withinTimeRange ." , postStop hook. , postStop.

0

Source: https://habr.com/ru/post/1683789/


All Articles