Reputation: 5763
object RemoteEchoServer extends App {
remote.start("localhost", 1111)
remote.register("hello-service", actorOf[HelloWorldActor])
}
object RemoteEchoClient extends App {
val actor = remote.actorFor("hello-service", "localhost", 1111)
val reply = actor !! "Hello"
println(reply)
actor ! "Stop"
actor ! PoisonPill
}
/**
* a remote actor servers for message "Hello" and response with a message "World"
* it is silly
*/
class HelloWorldActor extends Actor {
def receive = {
case "Hello" =>
println("receiving a Hello message,and a World message will rply")
self.reply("World")
case "Stop" =>
println("stopping...")
remote.shutdown()
}
}
The client send a PoisonPill as well as a "Stop" signal ,but the remote never terminate itself. I must kill the remote actor in object RemoteEchoServer by invoke remote.shutdown(). How to shutdown the remote actor by receiving a "Stop" message ?
I know exit() will probably exit the server app directly, but what if there are still request needs to process.
The key point is invoking remote.shutdown() never shutdown the remote service(server app), so what should i do if i want to stop the server app for the actor
Upvotes: 3
Views: 1412
Reputation: 40461
An actor can kill itself by invoking self.stop
. So forget the PoisonPill and just use the Stop
message:
case "Stop" => {
println("stopping...")
self.stop
remote.shutdown()
}
Upvotes: 4