Correction of Java doc Creating Actors Remotely, see #2537

This commit is contained in:
Patrik Nordwall 2012-09-21 15:08:56 +02:00
parent c0f60da8cc
commit ee65dbf184
5 changed files with 48 additions and 45 deletions

View file

@ -1,21 +0,0 @@
/**
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
*/
package docs.remoting;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
public class RemoteActorExample extends UntypedActor {
//#localNodeActor
ActorRef a1 = getContext().actorFor("/serviceA/retrieval");
//#localNodeActor
//#remoteNodeActor
ActorRef a2 = getContext().actorFor("akka://app@10.0.0.1:2552/user/serviceA/retrieval");
//#remoteNodeActor
public void onReceive(Object message) throws Exception {
// Do something
}
}

View file

@ -17,8 +17,18 @@ import akka.actor.ActorSystem;
import akka.remote.RemoteScope;
//#import
import akka.actor.UntypedActor;
public class RemoteDeploymentDocTestBase {
//#sample-actor
public static class Echo extends UntypedActor {
public void onReceive(Object message) {
getSender().tell(getSelf(), getSelf());
}
}
//#sample-actor
static ActorSystem system;
@BeforeClass
@ -38,9 +48,19 @@ public class RemoteDeploymentDocTestBase {
addr = AddressFromURIString.parse("akka://sys@host:1234"); // the same
//#make-address
//#deploy
ActorRef ref = system.actorOf(new Props(RemoteDeploymentDocSpec.Echo.class).withDeploy(new Deploy(new RemoteScope(addr))));
ActorRef ref = system.actorOf(new Props(Echo.class).withDeploy(new Deploy(new RemoteScope(addr))));
//#deploy
assert ref.path().address().equals(addr);
}
@Test
public void demonstrateSampleActor() {
//#sample-actor
ActorRef actor = system.actorOf(new Props(Echo.class), "sampleActor");
actor.tell("Pretty slick", null);
//#sample-actor
}
}

View file

@ -82,31 +82,30 @@ Once you obtained a reference to the actor you can interact with it they same wa
Creating Actors Remotely
^^^^^^^^^^^^^^^^^^^^^^^^
The configuration below instructs the system to deploy the actor "retrieval” on the specific host "app@10.0.0.1".
The "app" in this case refers to the name of the ``ActorSystem`` (only showing deployment section)::
If you want to use the creation functionality in Akka remoting you have to further amend the
``application.conf`` file in the following way (only showing deployment section)::
akka {
actor {
deployment {
/serviceA/retrieval {
remote = "akka://app@10.0.0.1:2552"
/sampleActor {
remote = "akka://sampleActorSystem@127.0.0.1:2553"
}
}
}
}
Logical path lookup is supported on the node you are on, i.e. to use the
actor created above you would do the following:
The configuration above instructs Akka to react when an actor with path ``/sampleActor`` is created, i.e.
using ``system.actorOf(new Props(...), "sampleActor")``. This specific actor will not be directly instantiated,
but instead the remote daemon of the remote system will be asked to create the actor,
which in this sample corresponds to ``sampleActorSystem@127.0.0.1:2553``.
.. includecode:: code/docs/remoting/RemoteActorExample.java#localNodeActor
Once you have configured the properties above you would do the following in code:
This will obtain an ``ActorRef`` on a remote node:
.. includecode:: code/docs/remoting/RemoteDeploymentDocTestBase.java#sample-actor
.. includecode:: code/docs/remoting/RemoteActorExample.java#remoteNodeActor
As you can see from the example above the following pattern is used to find an ``ActorRef`` on a remote node::
akka://<actorsystemname>@<hostname>:<port>/<actor path>
The actor class ``Echo`` has to be available to the runtimes using it, i.e. the classloader of the
actor systems has to have a JAR containing the class.
.. note::

View file

@ -12,11 +12,11 @@ import akka.remote.RemoteScope
object RemoteDeploymentDocSpec {
//#sample-actor
class Echo extends Actor {
def receive = {
case x sender ! self
}
def receive = { case _ sender ! self }
}
//#sample-actor
}
@ -49,4 +49,12 @@ class RemoteDeploymentDocSpec extends AkkaSpec("""
one must be === two
}
"demonstrate sampleActor" in {
//#sample-actor
val actor = system.actorOf(Props[Echo], "sampleActor")
actor ! "Pretty slick"
//#sample-actor
}
}

View file

@ -103,18 +103,15 @@ If you want to use the creation functionality in Akka remoting you have to furth
}
The configuration above instructs Akka to react when an actor with path ``/sampleActor`` is created, i.e.
using ``system.actorOf(Props(...)`, sampleActor)``. This specific actor will not be directly instantiated,
using ``system.actorOf(Props(...), "sampleActor")``. This specific actor will not be directly instantiated,
but instead the remote daemon of the remote system will be asked to create the actor,
which in this sample corresponds to ``sampleActorSystem@127.0.0.1:2553``.
Once you have configured the properties above you would do the following in code::
Once you have configured the properties above you would do the following in code:
class SampleActor extends Actor { def receive = { case _ => println("Got something") } }
.. includecode:: code/docs/remoting/RemoteDeploymentDocSpec.scala#sample-actor
val actor = context.actorOf(Props[SampleActor], "sampleActor")
actor ! "Pretty slick"
``SampleActor`` has to be available to the runtimes using it, i.e. the classloader of the
The actor class ``Echo`` has to be available to the runtimes using it, i.e. the classloader of the
actor systems has to have a JAR containing the class.
.. note::