简体   繁体   English

从Akka的客户端向服务器发送毒药

[英]Sending poisonpill to Server from Client in Akka

I have a client server program written using Java API. 我有一个使用Java API编写的客户端服务器程序。 There am trying to send a message to server then server will send some reply message to Client.Then Client sending a poisonPill to Server. 尝试向服务器发送消息,然后服务器将向客户端发送一些回复消息。然后客户端向服务器发送毒药。 If server receives poisonpill message it has to shutdown.Below the code snippents for the same. 如果服务器收到中毒药消息,则必须关闭它。 In ClientActor: 在ClientActor中:

remoteActor.tell(poisonPill());

In ServerActor: 在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();       
  } 
}

But the message instanceof PoisonPill line is not executing, so that the server is always running. 但是, message instanceof PoisonPill没有执行,因此服务器始终在运行。

Can anyone help me on this? 谁可以帮我这个事? why the line is not executing at all? 为什么该行根本不执行?

PoisonPill is automatically handled by Akka. PoisonPill由Akka自动处理。 You shouldn't terminate the ActorSystem from within the Actor. 您不应该从Actor内部终止ActorSystem。 It'd be equivalent of calling System.exit(0) inside a Business Object. 这等效于在业务对象内调用System.exit(0)。 If you want to stop the ServerActor, do: context.stop(self) 如果要停止ServerActor,请执行以下操作:context.stop(self)

不是吗

remoteActor.tell(new PoisonPill());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM