Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AKKA: Painless Actor Error Notifications

Tags:

scala

akka

Beautiful People Lifestyle

  • A component BEAUTIFUL is using her internal akka.actor.Actor to do certain things.. ( such as "acting up" for example )

  • There are other MAN components that would really like to "interact" with the BEAUTIFUL

  • When the BEAUTIFUL finds a MAN worthy, before "interacting" with him, she agrees to take in his phone number ( let's call it an ErrorHandler ), you know just to give him a call in case he left in the morning and forgot his Rolex on her bed side table

  • The BEAUTIFUL though is "high maintenance" ( aren't they all.. ), and every time something bad happens inside the BEAUTIFUL's internal Actor ( e.g. an OmgBrokenNailException, UglyPurseThrowable, etc.. ), she goes nuts, needs to stop completely and to call a MAN using that phone number ( e.g. errorHandler.getOnItNowHoney( message, throwable ) )

Beautiful People Problem

AKKA supervisors allow to register two types of FaultHandlers => OneForOneStrategy and AllForOneStrategy, where if the underlying Actor overrides preRestart/postRestart, it gets access to an actual "throwable" e.g.:

override def preRestart( reason: Throwable ) { // do with throwable... }

The problem is both of these strategies will try to restart the Actor(s), which is not something that I am looking for. I am looking for the Actor to call an external ErrorHandler with the "throwable" and stop.

If I don't use these strategies, when exception is thrown from within the Actor, a postStop is called on the Actor, which is cool, but it does not take in a "throwable":

override def postStop() { // no access to "throwable"... }

Help the MAN to get that throwable

like image 739
Henry VIII Avatar asked Jan 05 '12 17:01

Henry VIII


1 Answers

In Akka 2 you should use DeathWatch

like image 54
Viktor Klang Avatar answered Sep 21 '22 11:09

Viktor Klang