From be877a6197fb6030013ce8776200462c8bfe62d2 Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 25 Sep 2012 12:18:44 +0200 Subject: [PATCH] export supervision tools in Act trait, and other review fixes - add more cross references to ActorDSL docs - improve SBT command line for running the multi-node test - correct small error in Restart Hooks section of actors.rst --- .../test/scala/akka/actor/ActorDSLSpec.scala | 4 +-- .../main/scala/akka/actor/dsl/Creators.scala | 30 +++++++++++++++++++ akka-docs/rst/java/untyped-actors.rst | 5 ++-- akka-docs/rst/scala/actors.rst | 18 ++++++----- .../scala/code/docs/actor/ActorDocSpec.scala | 8 +++++ akka-samples/akka-sample-multi-node/README.md | 2 +- 6 files changed, 55 insertions(+), 12 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala index 520c0de6bf..bb5ed0d4bd 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala @@ -139,8 +139,8 @@ class ActorDSLSpec extends AkkaSpec { val system = null // shadow the implicit system //#supervise-with superviseWith(OneForOneStrategy() { - case e: Exception if e.getMessage == "hello" ⇒ SupervisorStrategy.Stop - case _: Exception ⇒ SupervisorStrategy.Resume + case e: Exception if e.getMessage == "hello" ⇒ Stop + case _: Exception ⇒ Resume }) //#supervise-with val child = actor("child")(new Act { diff --git a/akka-actor/src/main/scala/akka/actor/dsl/Creators.scala b/akka-actor/src/main/scala/akka/actor/dsl/Creators.scala index b81f733013..29dda88300 100644 --- a/akka-actor/src/main/scala/akka/actor/dsl/Creators.scala +++ b/akka-actor/src/main/scala/akka/actor/dsl/Creators.scala @@ -54,6 +54,36 @@ trait Creators { this: ActorDSL.type ⇒ private[this] var postRestartFun: Throwable ⇒ Unit = null private[this] var strategy: SupervisorStrategy = null + /** + * @see [[akka.actor.OneForOneStrategy]] + */ + def OneForOneStrategy = akka.actor.OneForOneStrategy + + /** + * @see [[akka.actor.AllForOneStrategy]] + */ + def AllForOneStrategy = akka.actor.AllForOneStrategy + + /** + * @see [[akka.actor.SupervisorStrategy]] + */ + def Stop = SupervisorStrategy.Stop + + /** + * @see [[akka.actor.SupervisorStrategy]] + */ + def Restart = SupervisorStrategy.Restart + + /** + * @see [[akka.actor.SupervisorStrategy]] + */ + def Resume = SupervisorStrategy.Resume + + /** + * @see [[akka.actor.SupervisorStrategy]] + */ + def Escalate = SupervisorStrategy.Escalate + /** * Add the given behavior on top of the behavior stack for this actor. This * stack is cleared upon restart. Use `unbecome()` to pop an element off diff --git a/akka-docs/rst/java/untyped-actors.rst b/akka-docs/rst/java/untyped-actors.rst index f1cf49f7d1..40bc124ba0 100644 --- a/akka-docs/rst/java/untyped-actors.rst +++ b/akka-docs/rst/java/untyped-actors.rst @@ -200,8 +200,9 @@ Restart Hooks ------------- All actors are supervised, i.e. linked to another actor with a fault -handling strategy. Actors will be restarted in case an exception is thrown while -processing a message. This restart involves the hooks mentioned above: +handling strategy. Actors may be restarted in case an exception is thrown while +processing a message (see :ref:`supervision`). This restart involves the hooks +mentioned above: 1. The old actor is informed by calling :meth:`preRestart` with the exception which caused the restart and the message which triggered that exception; the diff --git a/akka-docs/rst/scala/actors.rst b/akka-docs/rst/scala/actors.rst index 914c899a77..cb97262329 100644 --- a/akka-docs/rst/scala/actors.rst +++ b/akka-docs/rst/scala/actors.rst @@ -162,7 +162,7 @@ infrastructure is bundled in the following import: .. includecode:: ../../../akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala#import -This import is assumed for all code samples throughout this section. To defined +This import is assumed for all code samples throughout this section. To define a simple actor, the following is sufficient: .. includecode:: ../../../akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala#simple-actor @@ -174,14 +174,16 @@ form of the ``implicit val context: ActorContext``. Outside of an actor, you have to either declare an implicit :class:`ActorSystem`, or you can give the factory explicitly (see further below). -Life-cycle hooks are also exposed as DSL elements, where later invocations of -the methods shown below will replace the contents of the respective hooks: +Life-cycle hooks are also exposed as DSL elements (see `Start Hook`_ and `Stop +Hook`_ below), where later invocations of the methods shown below will replace +the contents of the respective hooks: .. includecode:: ../../../akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala#simple-start-stop The above is enough if the logical life-cycle of the actor matches the restart cycles (i.e. ``whenStopping`` is executed before a restart and ``whenStarting`` -afterwards). If that is not desired, use the following two hooks: +afterwards). If that is not desired, use the following two hooks (see `Restart +Hooks`_ below): .. includecode:: ../../../akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala#failing-actor @@ -196,7 +198,8 @@ It is also possible to create nested actors, i.e. grand-children, like this: the compiler tells you about ambiguous implicits). The grand-child will be supervised by the child; the supervisor strategy for -this relationship can also be configured using a DSL element: +this relationship can also be configured using a DSL element (supervision +directives are part of the :class:`Act` trait): .. includecode:: ../../../akka-actor-tests/src/test/scala/akka/actor/ActorDSLSpec.scala#supervise-with @@ -301,8 +304,9 @@ Restart Hooks ------------- All actors are supervised, i.e. linked to another actor with a fault -handling strategy. Actors will be restarted in case an exception is thrown while -processing a message. This restart involves the hooks mentioned above: +handling strategy. Actors may be restarted in case an exception is thrown while +processing a message (see :ref:`supervision`). This restart involves the hooks +mentioned above: 1. The old actor is informed by calling :meth:`preRestart` with the exception which caused the restart and the message which triggered that exception; the diff --git a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala index 0ce5f87728..244ab5f136 100644 --- a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala @@ -406,4 +406,12 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) { lastSender must be === system.actorFor("/user") } + "using ActorDSL outside of akka.actor package" in { + import akka.actor.ActorDSL._ + actor(new Act { + superviseWith(OneForOneStrategy() { case _ ⇒ Stop; Restart; Resume; Escalate }) + superviseWith(AllForOneStrategy() { case _ ⇒ Stop; Restart; Resume; Escalate }) + }) + } + } diff --git a/akka-samples/akka-sample-multi-node/README.md b/akka-samples/akka-sample-multi-node/README.md index ed01383705..4a3149599f 100644 --- a/akka-samples/akka-sample-multi-node/README.md +++ b/akka-samples/akka-sample-multi-node/README.md @@ -8,7 +8,7 @@ with SBT](http://doc.akka.io/docs/akka/current/intro/getting-started.html). When you start SBT within the checked-out akka source directory, you can run this sample by typing - akka-sample-multi-node-experimental/test + akka-sample-multi-node-experimental/multi-jvm:test-only sample.multinode.MultiNodeSampleSpec (You might have to pass a system property containing `akka.test.tags.include=long-running`.)