Staying in Contact with an Actor’s Acquaintances
- October 8, 2013
When an actor confers with another to use its services—most likely on a remote actor system—you will always have to handle the case that the other actor goes away. Either it terminates or the node crashes or the network connection fails, sooner or later something will go wrong. Instead of making dedicated network monitoring available, Akka follows a more general approach, focusing on the service you need instead of on the implementation details.
It is quite simple: when the service goes down it will stop responding. DeathWatch can be used to condense the various reasons why this may happen into a single Terminated message. The actor which wanted to talk to that other actor will then have to keep retrying until the manually handled restart has occurred. Here you can see a prototypical implementation of an actor providing this functionality:
Note how none of this is specific to remoting, this also applies when talking to a local actor which might terminate and be recreated. That is what we call Location Transparency.
A variant of this actor would not stash but simply drop all messages in the waiting state, or it could contain a bounded internal queue which drops the oldest message on overflow; the details are up to your specific use-cases.