10

I am using Akka FSM for handling state in my Actor. I want some actions to be performed every time a transition to a certain state occurs, no matter which state the transition was made from. After reading the docs, I felt certain that this could be resolved like this:

onTransition({
  case (_, ToState) => performAction(stateData)
})

...

when(FromState){
  case "changestate" => goto(ToState) using NewStateData
}

However, when the transition occurs, stateData is not yet updated to NewStateData.

What is the recommended way to perform actions on entering a certain state?

eirirlar
  • 814
  • 6
  • 24

1 Answers1

7

Thanks for bringing this to my attention, that was indeed an oversight, which I fixed immediately (see the ticket). Unfortunately there is not much you can do (apart from merging in the tiny patch yourself) until 1.3 is out, which should be next week; if you are particularly impatient, I would appreciate if you could try out RC2 with the fix which will be released this week.

Roland Kuhn
  • 15,412
  • 2
  • 36
  • 45
  • it took two days longer, but RC2 is out now. – Roland Kuhn Dec 05 '11 at 21:59
  • I appear to have come across this problem in akka 2.3.12. Can you confirm whether new state set using `using` is available in the respective case of the partial function passed to `onTransition()`? – Mullefa Nov 23 '15 at 17:57
  • 1
    It should be available as `nextStateData`. – Roland Kuhn Nov 24 '15 at 07:01
  • Looking at the Javadoc at https://doc.akka.io/japi/akka/2.4/index.html, it looks like `nextStateData` is static. Maybe there is some scala magic that happens, but that is concerning at the least. Does that method work from Java, especially if you have multiple FSM actors? – Troy Daniels Jan 11 '18 at 22:06