1
class RulesFSMActor extends Actor with FSM[State, Data]{
  When(Rule1)
  {
    case Event(CASE_MSG1, Data) => 
      if (<someconditon>)
        goto(Rule2)
  }
  When(Rule2)
  {
    case Event(CASE_MSG2, Data) => 
    if (<someconditon>){
      sender ! MessgeBackToCaller"    // Is it allowed to use "sender" ?
      goto(Rule1)
  }
 }
//unhandled ,...etc
}

Assume my initial state is "Rule1" and it keeps toggling between states, If its in "Rule1" , it moves to "Rule2" and vice versa , based on some condition it has to send a message back to Caller(Sender).

Appreciate your help!

Avis
  • 496
  • 1
  • 5
  • 18

2 Answers2

0

Yes you can. FSMs are normal actors with the receive implemented to handle states.

Ravi Kiran
  • 1,139
  • 6
  • 10
0

Yes, of course! FSM's are only an extension (a "domain specific language") for defining Actors which have multiple states.

Konrad 'ktoso' Malawski
  • 13,102
  • 3
  • 47
  • 52