Hi,
The message you actually get in onTermination is StopEvent(Shutdown, state,
data). The reason you do not get the exception in this case is that the
exception will go to the supervisor which makes a decision what happens
with the actor lifecycle. This does not inform the child actor about why it
got stopped, restarted etc.
If you want a graceful stop because of logic inside your FSM actor you
would do that with the stop method which allows you to specify a
FSM.Reason. Like this:
class FSMActor extends FSM[String, String] {
startWith("S", "D")
when("S") {
case Event("E", _) =>
stop(Failure(new Exception("to much E")))
}
onTermination {
case StopEvent(why, state, data) => println("Oops: " + why)
}
initialize()
}
--
Johan Andrén
Typesafe - Reactive apps on the JVM
Twitter: @apnylle
On Thursday, August 13, 2015 at 6:12:30 PM UTC+2, Jacool wrote:
>
> Hello,
> I am trying to understand why in an FSM the onTermination handler is not
> called with StopEvent(FSM.Failure,_,_) upon a failure in an event handler.
> And in general what are the semantics of FSM.Failure?
> I run a test like this:
>
> class AMachine extends FSM[String, String] {
> startWith("S", "D")
>
> when("S") {
> case Event("E", _) =>
> throw new Exception("Arrgh")
> }
>
> onTermination {
> case StopEvent(FSM.Failure(cause), state, data) => println("Oops") //
> NEVER COMES HERE
> }
>
> initialize()
> }
>
> ActorSystem().actorOf(Props[AMachine]) ! "E"
>
> I expected the "Oops" statement to execute in this case, however it doesn't
> (in Akka 2.3.12)
>
>
--
>>>>>>>>>> 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.