diff --git a/akka-samples/akka-sample-remote/README b/akka-samples/akka-sample-remote/README new file mode 100644 index 0000000000..052e79a37c --- /dev/null +++ b/akka-samples/akka-sample-remote/README @@ -0,0 +1,57 @@ +--------------------------------------------------------- +== Akka Remote Sample Application == + +This sample has two different samples: + - Server Managed Remote Actors Sample + - Client Managed Remote Actors Sample + +--------------------------------------------------------- += Server Managed Remote Actors Sample = + +To run the sample: + +1. Fire up two shells. For each of them: + - Step down into to the root of the Akka distribution. + - Set 'export AKKA_HOME=. + - Run 'sbt' + - Run 'project akka-sample-remote' + - Run 'console' to start up a REPL (interpreter). +2. In the first REPL you get execute: + - scala> import sample.remote._ + - scala> ServerManagedRemoteActorServer.run + This starts up the RemoteNode and registers the remote actor +3. In the second REPL you get execute: + - scala> import sample.remote._ + - scala> ServerManagedRemoteActorClient.run +4. See the actor conversation. +5. Run it again to see full speed after first initialization. + +Now you could test client reconnect by killing the console running the ServerManagedRemoteActorClient and start it up again. See the client reconnect take place in the REPL shell. + +That’s it. Have fun. + +--------------------------------------------------------- += Client Managed Remote Actors Sample = + +To run the sample: + +1. Fire up two shells. For each of them: + - Step down into to the root of the Akka distribution. + - Set 'export AKKA_HOME=. + - Run 'sbt' + - Run 'project akka-sample-remote' + - Run 'console' to start up a REPL (interpreter). +2. In the first REPL you get execute: + - scala> import sample.remote._ + - scala> ClientManagedRemoteActorServer.run + This starts up the RemoteNode and registers the remote actor +3. In the second REPL you get execute: + - scala> import sample.remote._ + - scala> ClientManagedRemoteActorClient.run +4. See the actor conversation. +5. Run it again to see full speed after first initialization. + +Now you could test client reconnect by killing the console running the ClientManagedRemoteActorClient and start it up again. See the client reconnect take place in the REPL shell. + +That’s it. Have fun. + diff --git a/akka-samples/akka-sample-remote/src/main/scala/ClientManagedRemoteActorSample.scala b/akka-samples/akka-sample-remote/src/main/scala/ClientManagedRemoteActorSample.scala new file mode 100644 index 0000000000..e26b54e00e --- /dev/null +++ b/akka-samples/akka-sample-remote/src/main/scala/ClientManagedRemoteActorSample.scala @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2009-2010 Scalable Solutions AB + */ + +package sample.remote + +import se.scalablesolutions.akka.actor.RemoteActor +import se.scalablesolutions.akka.remote.RemoteNode +import se.scalablesolutions.akka.util.Logging + +class RemoteHelloWorldActor extends RemoteActor("localhost", 9999) { + start + def receive = { + case "Hello" => + log.info("Received 'Hello'") + reply("World") + } +} + +object ClientManagedRemoteActorServer extends Logging { + + def run = { + RemoteNode.start("localhost", 9999) + log.info("Remote node started") + } + + def main(args: Array[String]) = run +} + +object ClientManagedRemoteActorClient extends Logging { + + def run = { + val actor = new RemoteHelloWorldActor + log.info("Remote actor created, moved to the server") + log.info("Sending 'Hello' to remote actor") + val result = actor !! "Hello" + log.info("Result from Remote Actor: '%s'", result.get) + } + + def main(args: Array[String]) = run +} + diff --git a/akka-samples/akka-sample-remote/src/main/scala/ServerManagedRemoteActorSample.scala b/akka-samples/akka-sample-remote/src/main/scala/ServerManagedRemoteActorSample.scala new file mode 100644 index 0000000000..9eb83816bc --- /dev/null +++ b/akka-samples/akka-sample-remote/src/main/scala/ServerManagedRemoteActorSample.scala @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2009-2010 Scalable Solutions AB + */ + +package sample.remote + +import se.scalablesolutions.akka.actor.Actor +import se.scalablesolutions.akka.remote.{RemoteClient, RemoteNode} +import se.scalablesolutions.akka.util.Logging + +class HelloWorldActor extends Actor { + start + def receive = { + case "Hello" => + log.info("Received 'Hello'") + reply("World") + } +} + +object ServerManagedRemoteActorServer extends Logging { + + def run = { + RemoteNode.start("localhost", 9999) + log.info("Remote node started") + RemoteNode.register("hello-service", new HelloWorldActor) + log.info("Remote actor registered and started") + } + + def main(args: Array[String]) = run +} + +object ServerManagedRemoteActorClient extends Logging { + + def run = { + val actor = RemoteClient.actorFor("hello-service", "localhost", 9999) + log.info("Remote client created") + log.info("Sending 'Hello' to remote actor") + val result = actor !! "Hello" + log.info("Result from Remote Actor: '%s'", result.get) + } + + def main(args: Array[String]) = run +} + diff --git a/project/build/AkkaProject.scala b/project/build/AkkaProject.scala index b78926e482..5623f110bb 100644 --- a/project/build/AkkaProject.scala +++ b/project/build/AkkaProject.scala @@ -290,6 +290,8 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { class AkkaSampleRestJavaProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) + class AkkaSampleRemoteProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) + class AkkaSampleRestScalaProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) { val jsr311 = "javax.ws.rs" % "jsr311-api" % "1.1.1" % "compile" } @@ -323,6 +325,8 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { new AkkaSampleCamelProject(_), akka_kernel) lazy val akka_sample_security = project("akka-sample-security", "akka-sample-security", new AkkaSampleSecurityProject(_), akka_kernel) + lazy val akka_sample_remote = project("akka-sample-remote", "akka-sample-remote", + new AkkaSampleRemoteProject(_), akka_kernel) } // ------------------------------------------------------------