0

I have a Supervisor actor that creates a couple of child actors. I have also defined a Supervision strategy that does a OneToOne handling:

  override val supervisorStrategy =
    OneForOneStrategy() {
      case _ =>
        logger.info("doing restart")
        Restart
    }

I would like to know how could I introduce a Timeout to this Restart so that I want for let's say 5 seconds before I restart the children? I do not see any Akka documentation pointing me to any configurable timeouts. Any clues? I do not want to have Thread.sleep(...). It is definitely out of the equation. Any other suggestions?

joesan
  • 13,963
  • 27
  • 95
  • 232

2 Answers2

1

How about overriding the OneForOneStrategy with the parameters as:

OneForOneStrategy(maxNrOfRetries = 6, withinTimeRange = 1.minute) {
  ...
  ...
}

This would ensure that the child actors are restarted only 6 times within a span of 1 minute!

joesan
  • 13,963
  • 27
  • 95
  • 232
  • This will attempt to restart the child N times in the time interval. The intervals at which these attempts are made are not defined nor is the interval of time that passes before the first attempt is made. – nattyddubbs May 02 '16 at 18:01
0

You could use a backoff supervisor that is configured with a min and max backoff being equal to each other.

Note that there are two different kinds of backoff instances. One for onStop and one for onFailure. In your case I'd use the onFailure as this is the supervisor that is configured to handle exception cases.

nattyddubbs
  • 2,085
  • 15
  • 24
  • The BackoffSupervisor restarts the child with a growing delay. I might not need that! How about overriding the maxNrOfRetries and withinTimeRange parameters to the OneForOneStrategy? This does exactly what I want! – joesan May 02 '16 at 16:15
  • It's all based on configuration. If you configure the min backoff and max backoff are both the same, then it will wait that amount of time before attempting to restart the child. – nattyddubbs May 02 '16 at 18:00