Skip to content

Instantly share code, notes, and snippets.

@rkuhn
Last active December 19, 2015 02:29
Show Gist options
  • Save rkuhn/5883262 to your computer and use it in GitHub Desktop.
Save rkuhn/5883262 to your computer and use it in GitHub Desktop.
supervisorStrategy with adapted logging
private static SupervisorStrategy strategy =
new OneForOneStrategy(10, Duration.create("1 minute"),
new Function<Throwable, Directive>() {
@Override
public Directive apply(Throwable t) {
if (t instanceof ArithmeticException) {
return resume();
} else if (t instanceof NullPointerException) {
log.warning("restarting misbehaving child");
return restart();
} else if (t instanceof IllegalArgumentException) {
log.error(t, "child cannot continue, service degraded");
return stop();
} else {
return escalate();
}
}
}, false); // <- this is the important bit
override val supervisorStrategy =
OneForOneStrategy(loggingEnabled = false) { // <- this is the important bit
case _: ArithmeticException =>
SupervisorStrategy.Resume
case _: NullPointerException =>
log.warning("restarting misbehaving child")
SupervisorStrategy.Restart
case _: IllegalArgumentException =>
log.error("child cannot continue, service degraded")
SupervisorStrategy.Stop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment