@Override public SupervisorStrategy create() { return new OneForOneStrategy( false, new PFBuilder<Throwable, SupervisorStrategy.Directive>() .match( Exception.class, (Exception e) -> { if (e instanceof ActorKilledException) { LOG.debug("Actor was killed. Stopping it now.", e); } else { LOG.error("Actor failed with exception. Stopping it now.", e); } return SupervisorStrategy.Stop$.MODULE$; }) .build()); }
@Override public Directive apply(final Throwable t) { if (t instanceof DocumentTypeDataGenerationException) { return restart(); } else if (t instanceof DocumentGenerationException) { return restart(); } else if (t instanceof IndexDataException) { return restart(); } else if (t instanceof ActorInitializationException) { return stop(); } else if (t instanceof ActorKilledException) { return stop(); } else if (t instanceof Exception) { return restart(); } else { return escalate(); } }
private Function<Throwable, Directive> myDecider() { return new Function<Throwable, Directive>() { @Override public Directive apply(Throwable t) { if ( t instanceof ActorInitializationException || t instanceof ActorKilledException || t instanceof DeathPactException ) { return SupervisorStrategy.stop(); } else if ( t instanceof Exception ) { Class<? extends Throwable> clazz = t.getClass(); ImmutableSet<Entry<Class<?>, Method>> entrySet = javactorInfoByJavactorType .get(javactor.getClass()).getSupervisorStrategyInfo().getOnExceptionMethods() .entrySet(); for (Entry<Class<?>, Method> entry : entrySet) { if (entry.getKey().isAssignableFrom(clazz)) { final Method method = entry.getValue(); try { return map((SupervisorDirective) methodInvoke( method, javactor, t)); } catch (Exception e) { throw new RuntimeException(e); } } } return SupervisorStrategy.restart(); } else { return SupervisorStrategy.escalate(); } } }; }