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() を呼び出してリモート サービス (サーバー アプリ) をシャットダウンしないことです。アクターのサーバー アプリを停止したい場合はどうすればよいですか?