akka.japi.pf.DeciderBuilder Java Examples
The following examples show how to use
akka.japi.pf.DeciderBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractProxyActor.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Override public SupervisorStrategy supervisorStrategy() { return new OneForOneStrategy(true, DeciderBuilder .match(NullPointerException.class, e -> { log.error(e, "NullPointer in child actor - restarting it...", e.getMessage()); log.info("Restarting child..."); return SupervisorStrategy.restart(); }) .match(ActorKilledException.class, e -> { log.error(e.getCause(), "ActorKilledException in child actor - stopping it..."); return SupervisorStrategy.stop(); }) .matchAny(e -> SupervisorStrategy.escalate()) .build()); }
Example #2
Source File: ClusterSingleton.java From ts-reaktive with MIT License | 6 votes |
/** * Starts and returns the an {@link ActorRef} to the {@link ClusterSingletonManager} (and backoff supervisor) * that manage this actor singleton. * * Note that you can't send this ActorRef messages that should go to your actor: use {@link StartProxy} for that. * * @param constructor Constructor to pass to Props in order to actually create the actor */ public ActorRef start(ActorSystem system, Supplier<T> constructor) { Config config = system.settings().config().getConfig("ts-reaktive.actors.singleton"); Props backoffSupervisorProps = BackoffSupervisor.props( Backoff.onStop( Props.create(type, () -> constructor.get()), "actor", FiniteDuration.create(config.getDuration("min-backoff", SECONDS), SECONDS), FiniteDuration.create(config.getDuration("max-backoff", SECONDS), SECONDS), 0.2 ).withSupervisorStrategy(new OneForOneStrategy( DeciderBuilder .matchAny(e -> { log.info("{}: Stopping and awaiting restart.", name, e); return stop(); }) .build() )) ); return system.actorOf( ClusterSingletonManager.props(backoffSupervisorProps, PoisonPill.getInstance(), ClusterSingletonManagerSettings.create(system) ), name); }
Example #3
Source File: AbstractPubSubSupervisor.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public SupervisorStrategy supervisorStrategy() { return new AllForOneStrategy( DeciderBuilder.matchAny(error -> { final Duration restartDelay = config.getRestartDelay(); log.error(error, "Child <{}> crashed. Restarting all children after <{}>", getSender(), restartDelay); getTimers().startSingleTimer(Control.RESTART, Control.RESTART, restartDelay); onChildFailure(); return SupervisorStrategy.stop(); }).build()); }
Example #4
Source File: ConnectivityRootActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override protected PartialFunction<Throwable, SupervisorStrategy.Directive> getSupervisionDecider() { return DeciderBuilder.match(JMSRuntimeException.class, e -> { log.warning("JMSRuntimeException '{}' occurred.", e.getMessage()); return restartChild(); }).match(NamingException.class, e -> { log.warning("NamingException '{}' occurred.", e.getMessage()); return restartChild(); }).build().orElse(super.getSupervisionDecider()); }
Example #5
Source File: ClusterSingletonSupervisorActor.java From ditto with Eclipse Public License 2.0 | 4 votes |
private OneForOneStrategy buildDefaultSupervisorStrategy() { return new OneForOneStrategy(true, DeciderBuilder .match(NullPointerException.class, e -> { log.error(e, "NullPointer in singleton actor: {}", e.getMessage()); return restartChild(); }).match(IllegalArgumentException.class, e -> { log.warning("Illegal Argument in singleton actor: {}", e.getMessage()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); log.warning("Illegal Argument in singleton actor: {}", sw.toString()); return SupervisorStrategy.resume(); }).match(IllegalStateException.class, e -> { log.warning("Illegal State in singleton actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(IndexOutOfBoundsException.class, e -> { log.warning("IndexOutOfBounds in singleton actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(NoSuchElementException.class, e -> { log.warning("NoSuchElement in singleton actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(AskTimeoutException.class, e -> { log.warning("AskTimeoutException in singleton actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(ConnectException.class, e -> { log.warning("ConnectException in singleton actor: {}", e.getMessage()); return restartChild(); }).match(InvalidActorNameException.class, e -> { log.warning("InvalidActorNameException in singleton actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(ActorKilledException.class, e -> { log.error(e, "ActorKilledException in singleton actor: {}", e.message()); return restartChild(); }).match(DittoRuntimeException.class, e -> { log.error(e, "DittoRuntimeException '{}' should not be escalated to SupervisorActor. Simply resuming Actor.", e.getErrorCode()); return SupervisorStrategy.resume(); }).match(UnsupportedOperationException.class, e -> { log.error(e, "UnsupportedOperationException in singleton actor: {}", e.getMessage()); terminateActorSystem(); return SupervisorStrategy.stop(); // only stopping as ActorSystem is terminated anyways }).match(Throwable.class, e -> { log.error(e, "Escalating above root actor!"); terminateActorSystem(); return SupervisorStrategy.stop(); // only stopping as ActorSystem is terminated anyways }).matchAny(e -> { log.error("Unknown message:'{}'! Escalating above root actor!", e); terminateActorSystem(); return SupervisorStrategy.stop(); // only stopping as ActorSystem is terminated anyways }).build()); }
Example #6
Source File: RootSupervisorStrategyFactory.java From ditto with Eclipse Public License 2.0 | 4 votes |
public static OneForOneStrategy createStrategy(final LoggingAdapter log) { return new OneForOneStrategy(true, DeciderBuilder .match(NullPointerException.class, e -> { log.error(e, "NullPointer in child actor: {}", e.getMessage()); log.info(RESTARTING_CHILD_MSG); return SupervisorStrategy.restart(); }).match(IllegalArgumentException.class, e -> { log.warning("Illegal Argument in child actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(IndexOutOfBoundsException.class, e -> { log.warning("IndexOutOfBounds in child actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(IllegalStateException.class, e -> { log.warning("Illegal State in child actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(NoSuchElementException.class, e -> { log.warning("NoSuchElement in child actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(AskTimeoutException.class, e -> { log.warning("AskTimeoutException in child actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(ConnectException.class, e -> { log.warning("ConnectException in child actor: {}", e.getMessage()); log.info(RESTARTING_CHILD_MSG); return SupervisorStrategy.restart(); }).match(InvalidActorNameException.class, e -> { log.warning("InvalidActorNameException in child actor: {}", e.getMessage()); return SupervisorStrategy.resume(); }).match(ActorKilledException.class, e -> { log.error(e, "ActorKilledException in child actor: {}", e.message()); log.info(RESTARTING_CHILD_MSG); return SupervisorStrategy.restart(); }).match(DittoRuntimeException.class, e -> { log.error(e, "DittoRuntimeException '{}' should not be escalated to RootActor. Simply resuming Actor.", e.getErrorCode()); return SupervisorStrategy.resume(); }).match(Throwable.class, e -> { log.error(e, "Escalating above root actor!"); return SupervisorStrategy.escalate(); }).matchAny(e -> { log.error("Unknown message:'{}'! Escalating above root actor!", e); return SupervisorStrategy.escalate(); }).build()); }
Example #7
Source File: PolicyPersistenceActorTest.java From ditto with Eclipse Public License 2.0 | 4 votes |
@Test public void checkForActivityOfNonexistentPolicy() { new TestKit(actorSystem) { { // GIVEN: a PolicyPersistenceActor is created in a parent that forwards all messages to us final PolicyId policyId = PolicyId.of("test.ns", "nonexistent.policy"); final Props persistentActorProps = PolicyPersistenceActor.props(policyId, new PolicyMongoSnapshotAdapter(), pubSubMediator); final TestProbe errorsProbe = TestProbe.apply(actorSystem); final Props parentProps = Props.create(Actor.class, () -> new AbstractActor() { @Override public void preStart() { getContext().actorOf(persistentActorProps); } @Override public SupervisorStrategy supervisorStrategy() { return new OneForOneStrategy(true, DeciderBuilder.matchAny(throwable -> { errorsProbe.ref().tell(throwable, getSelf()); return SupervisorStrategy.restart(); }).build()); } @Override public Receive createReceive() { return ReceiveBuilder.create() .matchAny(message -> { if (getTestActor().equals(getSender())) { getContext().actorSelection(getSelf().path().child("*")) .forward(message, getContext()); } else { getTestActor().forward(message, getContext()); } }) .build(); } }); // WHEN: CheckForActivity is sent to a persistence actor of nonexistent policy after startup final ActorRef underTest = actorSystem.actorOf(parentProps); final Object checkForActivity = AbstractShardedPersistenceActor.checkForActivity(1L); underTest.tell(checkForActivity, getRef()); underTest.tell(checkForActivity, getRef()); underTest.tell(checkForActivity, getRef()); // THEN: persistence actor requests shutdown expectMsg(PolicySupervisorActor.Control.PASSIVATE); // THEN: persistence actor should not throw anything. errorsProbe.expectNoMessage(scala.concurrent.duration.Duration.create(3, TimeUnit.SECONDS)); } }; }
Example #8
Source File: SupervisorActor.java From flink with Apache License 2.0 | 4 votes |
@Override public PartialFunction<Throwable, Directive> decider() { return DeciderBuilder.match( Exception.class, e -> SupervisorStrategy.stop() ).build(); }