Correction of Java doc Creating Actors Remotely, see #2537
This commit is contained in:
parent
c0f60da8cc
commit
ee65dbf184
5 changed files with 48 additions and 45 deletions
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -17,7 +17,17 @@ import akka.actor.ActorSystem;
|
||||||
import akka.remote.RemoteScope;
|
import akka.remote.RemoteScope;
|
||||||
//#import
|
//#import
|
||||||
|
|
||||||
|
import akka.actor.UntypedActor;
|
||||||
|
|
||||||
public class RemoteDeploymentDocTestBase {
|
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;
|
static ActorSystem system;
|
||||||
|
|
||||||
|
|
@ -38,9 +48,19 @@ public class RemoteDeploymentDocTestBase {
|
||||||
addr = AddressFromURIString.parse("akka://sys@host:1234"); // the same
|
addr = AddressFromURIString.parse("akka://sys@host:1234"); // the same
|
||||||
//#make-address
|
//#make-address
|
||||||
//#deploy
|
//#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
|
//#deploy
|
||||||
assert ref.path().address().equals(addr);
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -82,31 +82,30 @@ Once you obtained a reference to the actor you can interact with it they same wa
|
||||||
Creating Actors Remotely
|
Creating Actors Remotely
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
The configuration below instructs the system to deploy the actor "retrieval” on the specific host "app@10.0.0.1".
|
If you want to use the creation functionality in Akka remoting you have to further amend the
|
||||||
The "app" in this case refers to the name of the ``ActorSystem`` (only showing deployment section)::
|
``application.conf`` file in the following way (only showing deployment section)::
|
||||||
|
|
||||||
akka {
|
akka {
|
||||||
actor {
|
actor {
|
||||||
deployment {
|
deployment {
|
||||||
/serviceA/retrieval {
|
/sampleActor {
|
||||||
remote = "akka://app@10.0.0.1:2552"
|
remote = "akka://sampleActorSystem@127.0.0.1:2553"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logical path lookup is supported on the node you are on, i.e. to use the
|
The configuration above instructs Akka to react when an actor with path ``/sampleActor`` is created, i.e.
|
||||||
actor created above you would do the following:
|
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
|
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.
|
||||||
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>
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ import akka.remote.RemoteScope
|
||||||
|
|
||||||
object RemoteDeploymentDocSpec {
|
object RemoteDeploymentDocSpec {
|
||||||
|
|
||||||
|
//#sample-actor
|
||||||
class Echo extends Actor {
|
class Echo extends Actor {
|
||||||
def receive = {
|
def receive = { case _ ⇒ sender ! self }
|
||||||
case x ⇒ sender ! self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//#sample-actor
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,4 +49,12 @@ class RemoteDeploymentDocSpec extends AkkaSpec("""
|
||||||
one must be === two
|
one must be === two
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"demonstrate sampleActor" in {
|
||||||
|
//#sample-actor
|
||||||
|
|
||||||
|
val actor = system.actorOf(Props[Echo], "sampleActor")
|
||||||
|
actor ! "Pretty slick"
|
||||||
|
//#sample-actor
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -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.
|
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,
|
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``.
|
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")
|
The actor class ``Echo`` has to be available to the runtimes using it, i.e. the classloader of the
|
||||||
actor ! "Pretty slick"
|
|
||||||
|
|
||||||
``SampleActor`` 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.
|
actor systems has to have a JAR containing the class.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue