Considering an FSM actor that starts at state Idle
startWith(Idle, IdleData)
I'd like to monitor the transition to this first state (from no state?)
I tried
onTransition {
case _ -> Idle => // Wasn't called
}
According to the relevant FSM documentation:
It is also possible to pass a function object accepting two states to onTransition, in case your transition handling logic is implemented as a method:
onTransition(handler _)
def handler(from: StateType, to: StateType) {
// handle it here ...
}
Given that the from type is StateType and not Option[StateType] I think that it may not be possible, but maybe I'm missing something.
I was searching for something similar recently.
If I understand your question correctly, Here is one way to monitor when you start off your FSM from the initial state:
In the above example, When We instantiate the FSM pass-in the message
SetData(something)
, It starts at the stateIdle
and there is a transition that you can monitor which isIdle -> Idle
.In the above case when we start the FSM we can see an output
Initial transition
printed, you can leverage this to do more complex stuff as per your needsSo basically if you update your existing transition from
case _ => Idle
tocase Idle -> Idle
it should workNote: There might be more than one way to do this, I am also still exploring the power of Akka FSM so my answer is just having one possible way of getting this.