From fdd4a85ab0ec01d1e00f65c607a502acc0afdb1f Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Fri, 25 May 2012 00:49:45 +0200 Subject: [PATCH] Adding docs about creating TypedActor children --- .../src/main/scala/akka/camel/CamelMessage.scala | 2 +- .../code/docs/actor/TypedActorDocTestBase.java | 16 ++++++++++++++++ akka-docs/java/typed-actors.rst | 8 ++++++-- .../code/docs/actor/TypedActorDocSpec.scala | 12 ++++++++++++ .../serialization/SerializationDocSpec.scala | 2 +- akka-docs/scala/typed-actors.rst | 8 ++++++-- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/akka-camel/src/main/scala/akka/camel/CamelMessage.scala b/akka-camel/src/main/scala/akka/camel/CamelMessage.scala index 4f617c83a4..cb4121189d 100644 --- a/akka-camel/src/main/scala/akka/camel/CamelMessage.scala +++ b/akka-camel/src/main/scala/akka/camel/CamelMessage.scala @@ -200,7 +200,7 @@ object CamelMessage { * so that it can be correlated with an asynchronous response. Messages send to Consumer * actors have this header already set. */ - val MessageExchangeId = "MessageExchangeId".intern //Deliberately without type ascription to make it a constant + val MessageExchangeId = "MessageExchangeId" //Deliberately without type ascription to make it a constant /** * Creates a canonical form of the given message msg. If msg of type diff --git a/akka-docs/java/code/docs/actor/TypedActorDocTestBase.java b/akka-docs/java/code/docs/actor/TypedActorDocTestBase.java index 99dda513ab..fdd677c78b 100644 --- a/akka-docs/java/code/docs/actor/TypedActorDocTestBase.java +++ b/akka-docs/java/code/docs/actor/TypedActorDocTestBase.java @@ -5,6 +5,7 @@ package docs.actor; //#imports +import akka.actor.TypedActor; import akka.dispatch.*; import akka.actor.*; import akka.japi.*; @@ -151,6 +152,21 @@ public class TypedActorDocTestBase { } } + @Test public void createHierarchies() { + try { + //#typed-actor-hierarchy + Squarer childSquarer = + TypedActor.get(TypedActor.context()). + typedActorOf( + new TypedProps(Squarer.class, SquarerImpl.class) + ); + //Use "childSquarer" as a Squarer + //#typed-actor-hierarchy + } catch (Exception e) { + //dun care + } + } + @Test public void proxyAnyActorRef() { try { //#typed-actor-remote diff --git a/akka-docs/java/typed-actors.rst b/akka-docs/java/typed-actors.rst index 7ab2274425..7712622dfe 100644 --- a/akka-docs/java/typed-actors.rst +++ b/akka-docs/java/typed-actors.rst @@ -163,7 +163,11 @@ Typed Actor Hierarchies Since you can obtain a contextual Typed Actor Extension by passing in an ``ActorContext`` you can create child Typed Actors by invoking ``typedActorOf(..)`` on that. -This also works for creating child Typed Actors in regular Akka Actors. +.. includecode:: code/akka/docs/actor/TypedActorDocTestBase.java + :include: typed-actor-hierarchy + +You can also create a child Typed Actor in regular Akka Actors by giving the ``UntypedActorContext`` +as an input parameter to TypedActor.get(…). Supervisor Strategy ------------------- @@ -204,4 +208,4 @@ Lookup & Remoting Since ``TypedActors`` are backed by ``Akka Actors``, you can use ``actorFor`` together with ``typedActorOf`` to proxy ``ActorRefs`` potentially residing on remote nodes. -.. includecode:: code/docs/actor/TypedActorDocTestBase.java#typed-actor-remote \ No newline at end of file +.. includecode:: code/docs/actor/TypedActorDocTestBase.java#typed-actor-remote diff --git a/akka-docs/scala/code/docs/actor/TypedActorDocSpec.scala b/akka-docs/scala/code/docs/actor/TypedActorDocSpec.scala index e2c8db16a4..0c2f3bd5b8 100644 --- a/akka-docs/scala/code/docs/actor/TypedActorDocSpec.scala +++ b/akka-docs/scala/code/docs/actor/TypedActorDocSpec.scala @@ -151,6 +151,18 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) { //#typed-actor-remote } + "create hierarchies" in { + try { + //#typed-actor-hierarchy + //Inside your Typed Actor + val childSquarer: Squarer = TypedActor(TypedActor.context).typedActorOf(TypedProps[SquarerImpl]()) + //Use "childSquarer" as a Squarer + //#typed-actor-hierarchy + } catch { + case e: Exception ⇒ //ignore + } + } + "supercharge" in { //#typed-actor-supercharge-usage val awesomeFooBar: Foo with Bar = TypedActor(system).typedActorOf(TypedProps[FooBar]()) diff --git a/akka-docs/scala/code/docs/serialization/SerializationDocSpec.scala b/akka-docs/scala/code/docs/serialization/SerializationDocSpec.scala index 5fba0c4f97..9b222436da 100644 --- a/akka-docs/scala/code/docs/serialization/SerializationDocSpec.scala +++ b/akka-docs/scala/code/docs/serialization/SerializationDocSpec.scala @@ -54,7 +54,7 @@ package docs.serialization { // using the type hint (if any, see "includeManifest" above) // into the optionally provided classLoader. def fromBinary(bytes: Array[Byte], - clazz: Option[Class[_]]): AnyRef = { + clazz: Option[Class[_]]): AnyRef = { // Put your code that deserializes here //#... null diff --git a/akka-docs/scala/typed-actors.rst b/akka-docs/scala/typed-actors.rst index 694078a58d..7c039a1db6 100644 --- a/akka-docs/scala/typed-actors.rst +++ b/akka-docs/scala/typed-actors.rst @@ -161,9 +161,13 @@ Typed Actor Hierarchies ----------------------- Since you can obtain a contextual Typed Actor Extension by passing in an ``ActorContext`` -you can create child Typed Actors by invoking ``typedActorOf(..)`` on that. +you can create child Typed Actors by invoking ``typedActorOf(..)`` on that: -This also works for creating child Typed Actors in regular Akka Actors. +.. includecode:: code/akka/docs/actor/TypedActorDocSpec.scala + :include: typed-actor-hierarchy + +You can also create a child Typed Actor in regular Akka Actors by giving the ``ActorContext`` +as an input parameter to TypedActor.get(…). Supervisor Strategy -------------------