Added sample module for remote actors

This commit is contained in:
Jonas Bonér 2010-05-04 10:40:58 +02:00
parent 3c6e17a691
commit c38d293521
4 changed files with 147 additions and 0 deletions

View file

@ -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=<root of distribution>.
- 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.
Thats 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=<root of distribution>.
- 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.
Thats it. Have fun.

View file

@ -0,0 +1,42 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
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
}

View file

@ -0,0 +1,44 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
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
}

View file

@ -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)
}
// ------------------------------------------------------------