Skip to content

Commit

Permalink
fixed issues with supervision docs (#3308)
Browse files Browse the repository at this point in the history
* fixed issues with supervision docs

* one more bugfix in the example code
  • Loading branch information
Aaronontheweb committed Feb 19, 2018
1 parent 3bf32df commit 3661b52
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions docs/articles/actors/fault-tolerance.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,12 @@ currently failed child (available as the `Sender` of the failure message).

### Default Supervisor Strategy

`Escalate` is used if the defined strategy doesn't cover the exception that was thrown.

When the supervisor strategy is not defined for an actor the following
exceptions are handled by default:

* `ActorInitializationException` will stop the failing child actor
* `ActorKilledException` will stop the failing child actor
* `Exception` will restart the failing child actor
* Other types of `Exception` will be escalated to parent actor
* `ActorInitializationException` will stop the failing child actor;
* `ActorKilledException` will stop the failing child actor; and
* Any other type of `Exception` will restart the failing child actor.

If the exception escalate all the way up to the root guardian it will handle it
in the same way as the default strategy defined above.
Expand Down Expand Up @@ -155,7 +152,8 @@ public class Supervisor : UntypedActor
{
if (message is Props p)
{
Sender.Tell(p);
var child = Context.ActorOf(p); // create child
Sender.Tell(child); // send back reference to child actor
}
}
}
Expand Down Expand Up @@ -194,7 +192,7 @@ Let us create actors:
var supervisor = system.ActorOf<Supervisor>("supervisor");

supervisor.Tell(Props.Create<Child>());
var child = ExpectMsg<IActorRef>(); // retrieve answer from TestKit’s testActor
var child = ExpectMsg<IActorRef>(); // retrieve answer from TestKit’s TestActor
```

The first test shall demonstrate the `Resume` directive, so we try it out by
Expand All @@ -210,7 +208,7 @@ child.Tell("get");
ExpectMsg(42);
```

As you can see the value 42 survives the fault handling directive. Now, if we
As you can see the value 42 survives the fault handling directive because we're using the `Resume` directive, which does not cause the actor to restart. Now, if we
change the failure to a more serious `NullReferenceException`, that will no
longer be the case:

Expand All @@ -220,6 +218,8 @@ child.Tell("get");
ExpectMsg(0);
```

This is because the actor has restarted and the original `Child` actor instance that was processing messages will be destroyed and replaced by a brand-new instance defined using the original `Props` passed to its parent.

And finally in case of the fatal `IllegalArgumentException` the child will be
terminated by the supervisor:

Expand Down Expand Up @@ -288,7 +288,8 @@ public class Supervisor2 : UntypedActor
{
if (message is Props p)
{
Sender.Tell(p);
var child = Context.ActorOf(p); // create child
Sender.Tell(child); // send back reference to child actor
}
}
}
Expand Down

0 comments on commit 3661b52

Please sign in to comment.