Adding docs about creating TypedActor children
This commit is contained in:
parent
681ccc6153
commit
fdd4a85ab0
6 changed files with 42 additions and 6 deletions
|
|
@ -200,7 +200,7 @@ object CamelMessage {
|
||||||
* so that it can be correlated with an asynchronous response. Messages send to Consumer
|
* so that it can be correlated with an asynchronous response. Messages send to Consumer
|
||||||
* actors have this header already set.
|
* 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 <code>msg</code>. If <code>msg</code> of type
|
* Creates a canonical form of the given message <code>msg</code>. If <code>msg</code> of type
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package docs.actor;
|
||||||
|
|
||||||
//#imports
|
//#imports
|
||||||
|
|
||||||
|
import akka.actor.TypedActor;
|
||||||
import akka.dispatch.*;
|
import akka.dispatch.*;
|
||||||
import akka.actor.*;
|
import akka.actor.*;
|
||||||
import akka.japi.*;
|
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<SquarerImpl>(Squarer.class, SquarerImpl.class)
|
||||||
|
);
|
||||||
|
//Use "childSquarer" as a Squarer
|
||||||
|
//#typed-actor-hierarchy
|
||||||
|
} catch (Exception e) {
|
||||||
|
//dun care
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void proxyAnyActorRef() {
|
@Test public void proxyAnyActorRef() {
|
||||||
try {
|
try {
|
||||||
//#typed-actor-remote
|
//#typed-actor-remote
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,11 @@ Typed Actor Hierarchies
|
||||||
Since you can obtain a contextual Typed Actor Extension by passing in an ``ActorContext``
|
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/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
|
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.
|
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
|
.. includecode:: code/docs/actor/TypedActorDocTestBase.java#typed-actor-remote
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,18 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
||||||
//#typed-actor-remote
|
//#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 {
|
"supercharge" in {
|
||||||
//#typed-actor-supercharge-usage
|
//#typed-actor-supercharge-usage
|
||||||
val awesomeFooBar: Foo with Bar = TypedActor(system).typedActorOf(TypedProps[FooBar]())
|
val awesomeFooBar: Foo with Bar = TypedActor(system).typedActorOf(TypedProps[FooBar]())
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ package docs.serialization {
|
||||||
// using the type hint (if any, see "includeManifest" above)
|
// using the type hint (if any, see "includeManifest" above)
|
||||||
// into the optionally provided classLoader.
|
// into the optionally provided classLoader.
|
||||||
def fromBinary(bytes: Array[Byte],
|
def fromBinary(bytes: Array[Byte],
|
||||||
clazz: Option[Class[_]]): AnyRef = {
|
clazz: Option[Class[_]]): AnyRef = {
|
||||||
// Put your code that deserializes here
|
// Put your code that deserializes here
|
||||||
//#...
|
//#...
|
||||||
null
|
null
|
||||||
|
|
|
||||||
|
|
@ -161,9 +161,13 @@ Typed Actor Hierarchies
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
Since you can obtain a contextual Typed Actor Extension by passing in an ``ActorContext``
|
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
|
Supervisor Strategy
|
||||||
-------------------
|
-------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue