[英]Sending poisonpill to Server from Client in Akka
我有一個使用Java API編寫的客戶端服務器程序。 嘗試向服務器發送消息,然后服務器將向客戶端發送一些回復消息。然后客戶端向服務器發送毒葯。 如果服務器收到中毒葯消息,則必須關閉它。 在ClientActor中:
remoteActor.tell(poisonPill());
在ServerActor中:
public void onReceive(Object message) throws Exception {
if (message instanceof String) {
getSender().tell(message + " got something");
} else if (message instanceof PoisonPill) {
getContext().system().shutdown();
}
}
但是, message instanceof PoisonPill
沒有執行,因此服務器始終在運行。
誰可以幫我這個事? 為什么該行根本不執行?
PoisonPill由Akka自動處理。 您不應該從Actor內部終止ActorSystem。 這等效於在業務對象內調用System.exit(0)。 如果要停止ServerActor,請執行以下操作:context.stop(self)
不是嗎
remoteActor.tell(new PoisonPill());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.