added sample for new server-initated remote actors
This commit is contained in:
parent
ea6274b179
commit
d8636b46f7
2 changed files with 37 additions and 32 deletions
|
|
@ -0,0 +1,37 @@
|
||||||
|
package sample
|
||||||
|
|
||||||
|
import se.scalablesolutions.akka.actor.Actor
|
||||||
|
import se.scalablesolutions.akka.remote.{RemoteClient, RemoteServer}
|
||||||
|
import se.scalablesolutions.akka.util.Logging
|
||||||
|
|
||||||
|
class HelloWorldActor extends Actor {
|
||||||
|
start
|
||||||
|
def receive = {
|
||||||
|
case "Hello" => reply("World")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object ServerInitiatedRemoteActorServer {
|
||||||
|
|
||||||
|
def run = {
|
||||||
|
val server = new RemoteServer()
|
||||||
|
server.start("localhost", 9999)
|
||||||
|
server.register(new HelloWorldActor)
|
||||||
|
}
|
||||||
|
|
||||||
|
def main(args: Array[String]) = run
|
||||||
|
}
|
||||||
|
|
||||||
|
object ServerInitiatedRemoteActorClient extends Logging {
|
||||||
|
|
||||||
|
def run = {
|
||||||
|
val actor = RemoteClient.actorFor(
|
||||||
|
"sample.HelloWorldActor",
|
||||||
|
5000L, "localhost", 9999)
|
||||||
|
val result = actor !! "Hello"
|
||||||
|
log.info("Result from Remote Actor: %s", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
def main(args: Array[String]) = run
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -8,38 +8,6 @@ import org.junit.{Test, Before, After}
|
||||||
import se.scalablesolutions.akka.remote.{RemoteServer, RemoteClient}
|
import se.scalablesolutions.akka.remote.{RemoteServer, RemoteClient}
|
||||||
import se.scalablesolutions.akka.dispatch.Dispatchers
|
import se.scalablesolutions.akka.dispatch.Dispatchers
|
||||||
|
|
||||||
object ServerInitiatedRemoteActorServer {
|
|
||||||
|
|
||||||
class TestActor extends Actor {
|
|
||||||
start
|
|
||||||
def receive = {
|
|
||||||
case "Hello" =>
|
|
||||||
reply("World")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def main(args: Array[String]) = {
|
|
||||||
import ServerInitiatedRemoteActorTest._
|
|
||||||
|
|
||||||
server = new RemoteServer()
|
|
||||||
server.start(HOSTNAME, PORT)
|
|
||||||
|
|
||||||
server.register(new TestActor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object ServerInitiatedRemoteActorClient {
|
|
||||||
def main(args: Array[String]) = {
|
|
||||||
import ServerInitiatedRemoteActorTest._
|
|
||||||
val actor = RemoteClient.actorFor(
|
|
||||||
"se.scalablesolutions.akka.actor.ServerInitiatedRemoteActorServer$TestActor",
|
|
||||||
5000L,
|
|
||||||
HOSTNAME, PORT)
|
|
||||||
val result = actor !! "Hello"
|
|
||||||
println("======== RESULT: " + result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object ServerInitiatedRemoteActorTest {
|
object ServerInitiatedRemoteActorTest {
|
||||||
val HOSTNAME = "localhost"
|
val HOSTNAME = "localhost"
|
||||||
val PORT = 9990
|
val PORT = 9990
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue