I'm working with the Akka Java library (unfortunately, the Classic version). When implementing the fault tolerance Strategy, the documentation provide a snippet like this:
private static SupervisorStrategy strategy =
new OneForOneStrategy(
10,
Duration.ofMinutes(1), // <----- Note here!
DeciderBuilder.match(...)
.build();
Moreover, it says:
"Also, there are special values for these parameters. If you specify:
-1 to maxNrOfRetries, and Duration.Inf() to withinTimeRange, then the child is always restarted without any limit".
The problem is that, in my Java (openjdk-11), Duration.Inf() doesn't actually exist!.
I have read some SO answers that specify what is the effective maximum Duration, but Akka seem to not recognize them. The best I could do is to specify Duration.ofNanos(Long.MAX_VALUE).
Am I missing something? Is there actually a value to input or is the Akka documentation just wrong?
The
Duration.Inf()there isn't referring tojava.time.Duration(even though the snippet above that in the docs does use the JavaDurationAPI). Under the hood, Akka converts the JavaDurationto ascala.concurrent.duration.Duration, which does have anInf(the naming pattern indicates that it's a constant in Scala) which is defined to be greater than anyFiniteDuration). The Java API just has a constructor which takesjava.time.Duration.This should work:
The maximum value of a Java
DurationisDuration.ofSeconds(Long.MAX_VALUE).plusNanos(999999999). Note that inside Akka, when converted to ScalaDurationthis will be considered less than an infinite duration, but that probably doesn't matter.