Reputation: 81
I have a client server program written using 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:
remoteActor.tell(poisonPill());
In 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.
Can anyone help me on this? why the line is not executing at all?
Upvotes: 0
Views: 215
Reputation: 26579
PoisonPill is automatically handled by Akka. You shouldn't terminate the ActorSystem from within the Actor. It'd be equivalent of calling System.exit(0) inside a Business Object. If you want to stop the ServerActor, do: context.stop(self)
Upvotes: 3