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()
}
}
客户端发送PoisonPill和“停止”信号,但遥控器永远不会自行终止。我必须通过调用 remote.shutdown() 来杀死对象 RemoteEchoServer 中的远程参与者。如何通过接收“停止”消息来关闭远程演员?
我知道 exit() 可能会直接退出服务器应用程序,但如果仍有请求需要处理怎么办。
关键是调用 remote.shutdown() 永远不会关闭远程服务(服务器应用程序),所以如果我想为演员停止服务器应用程序该怎么办