akka/akka-core

Improve Documentation on Creating a Supervisor Strategy [Java]

Open

#16,729 建立於 2015年1月27日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)Scala (3,547 fork)batch import
1 - triagedhelp wantedt:docs

倉庫指標

Star
 (13,277 star)
PR 合併指標
 (平均合併 17小時 35分鐘) (30 天內合併 11 個 PR)

描述

Regarding http://doc.akka.io/docs/akka/snapshot/java/fault-tolerance.html: The code samples don't compile out-of-the-box. Also, the documentation should say how the default strategy (http://doc.akka.io/docs/akka/snapshot/java/fault-tolerance.html#Default_Supervisor_Strategy) is implemented, so when you start implementing your own strategy, you can start from there.

Here's what I suppose is a working replica in Java of the default implementation:

new OneForOneStrategy(-1, Duration.Inf(), new Function<Throwable, SupervisorStrategy.Directive>() {
        @Override
        public SupervisorStrategy.Directive apply(final Throwable throwable) throws Exception {
            if (throwable instanceof ActorInitializationException) {
                return SupervisorStrategy.stop();
            } else if (throwable instanceof ActorKilledException) {
                return SupervisorStrategy.stop();
            } else if (throwable instanceof DeathPactException) {
                return SupervisorStrategy.stop();
            } else if (throwable instanceof Exception) {
                return SupervisorStrategy.restart();
            } else {
                return SupervisorStrategy.escalate();
            }
        }
    }, true);

貢獻者指南