Hi Andrey, the supervision mechanism (where I include the ability to stop for now) is a low-level facility for managing the lifecycle of those objects whose job it is to model your domain. Stopping an actor that way is the same as unplugging the power to your server: it will not gracefully shut down, it just stops functioning. Properly shutting down the server is done entirely differently: you ask it nicely (i.e. send a message) and it will do whatever is necessary to come to an orderly halt.
So, reacting with business-level actions should be reserved to business-level messages. Lifecycle hooks are just for plumbing (i.e. registering/unregistering from system services). You should be aware that your actor can always cease to exist without any hooks being called—when the power gets cut. As long as the actor system is running, it is important that the hooks function, but when it isn’t then you must not depend on them for the correctness of your distributed application. This means that all lifecycle changes you control should be done using normal user messages. As a rule of thumb, the only argument you ever pass to context.stop() is `self`, with the possible exception of stopping direct child actors. Terminating in response to a sibling’s failure can occur in two modes: if the error condition is fatal and not isolated between the siblings (i.e. they share something which fails for all of them simultaneously) then they must all abort in the power-cut sense, e.g. by applying an AllForOneStrategy; if the error condition is handled, then use a OneForOneStrategy, have the parent watch the children and send appropriate requests or notifications to siblings when receiving a Terminated message for one of them. Regards, Roland 28 mar 2014 kl. 23:03 skrev Andrey <[email protected]>: > Hello, > > In my actor's code, I'd like to know the reason why the postStop() hook is > called. In particular I'm interested in knowing whether the actor is being > terminated due to the supervision process (because one of the siblings has > failed -- in which case an instance of the original exception would be > fantastic!), or as result of somebody intentionally stopping it via a call to > the ActorContext.stop() on the self, or parent, or parent of parent... or > ActorSystem.stop() method. > > In case of the former the actor might choose to perform certain actions like > a transaction rollback, sending a NACK to a network connection, trigger a > compensation process, and stuff like that, whereas the latter would result in > a commit, or an ACK, or success message in the log file, or whatever else the > actors normally do in the postStop(). > > I'm wondering how can I implement something like that? Or, what's the > alternative? > > Thanks > Andrey > > PS. In general, I think it would sometimes be useful to able to pass along > with a stop() call some additional context for use in the postStop() hook of > the Actors being stopped. postStop() could take an Optional parameter similar > to how preRestart() does it. > > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: > >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. Dr. Roland Kuhn Akka Tech Lead Typesafe – Reactive apps on the JVM. twitter: @rolandkuhn -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
