Java源码示例:akka.actor.ActorKilledException

示例1
@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());
}
 
示例2
@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());
}
 
示例3
@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());
}
 
示例4
@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();
	}
}
 
示例5
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());
}
 
示例6
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());
}