processorOf FSM with Timer states

19 views
Skip to first unread message

Stas Shevchenko

unread,
Nov 13, 2013, 10:04:24 AM11/13/13
to events...@googlegroups.com
Hi All,

Probably there are some best practices for my case:

There is an Actor that implements State Machine, in some moment of time it has defined State and react according to it. 
It is well mapped to Processor while sequence of Messages leads his States.

When I do 
extension.recover
It's predictable and reliable to return it to the last state. But in my State Machine there is side effect - it has Timers Inside, for example it can stay in some Stay for limited period of Time, and then it doesn't accept messages of some type
for example Akka's FSM:

class MyFSM extends Actor with FSM[State, Data] {

  when(NormalState) {
    case Event(DoIt(sDuration), _) =>
      goto(TimerState) forMax  (sDuration seconds)
  }

  when(TimerState) {
    case Event(StateTimeout, _) =>
      goto(NormalState)
    case Event(otherMessages, _) =>
      stay forMax  (...)
  }

  ....
}


Recovering is impossible because of dependencies from Time. Is there any good way how to put MyFSM into Processor rails? Probably making snapshots after each time depended state?

Stas

Martin Krasser

unread,
Nov 14, 2013, 3:42:51 AM11/14/13
to events...@googlegroups.com
Hi Stas,

In general, you can approach problems of this kind by journaling timer
events. This ensures that the sequence of all messages/events incl.
timer events are the same on replay. Since the timer events sent by FSM
are not wrapped into Message, you'll need to do that yourself using an
additional stackable trait (TimerEventInterceptor) that intercepts timer
events and then wraps them into Message. Important is that this
interceptor is mixed in after Eventsourced.

class MyFSM extends ... with Eventsourced with MyTimerEventInterceptor

Cheers,
Martin
> --
> You received this message because you are subscribed to the Google
> Groups "Eventsourced User List" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to eventsourced...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Martin Krasser

blog: http://krasserm.blogspot.com
code: http://github.com/krasserm
twitter: http://twitter.com/mrt1nz

Reply all
Reply to author
Forward
0 new messages