Hi Nicola,

PersistentMain doesn't work as you expect because the sequence of messages during "normal" operation and during replay differs:

- during normal operation your FSM receives non-persistent StateTimeout events and persistent Done messages. Both are necessary for your FSM to make the intended state transitions. - during replay, the FSM only persistent Done messages are received, and your FSM stays in the "waiting" state, unable to process the replayed Done messages. The StateTimeout messages are missing.

One way to solve this problem is to make state transitions only when having received a persistent message. For example, when receiving a StateTimeout, do not make a state change immediately but send a Persistent(StateTimeout) to self, and then make the state transition:

  when("waiting", stateTimeout = 1.second) {
    case Event(StateTimeout, _) if !recoveryRunning => {
      self ! Persistent(StateTimeout)
      stay()
    }
    case Event(Persistent(StateTimeout, _), _) => {
      println(stateData)
      goto("doingSomething")
    }
  }

This ensures that the timeout events are replayed as well. I recommend you also to add a !recoveryRunning guard when receiving a non-persistent StateTimeout.

Additionally, you should only send new persistent Done messages to self on transition to "doingSomething" if recovery is not currently running:

  onTransition {
    case _ -> "doingSomething" => {
      if (!recoveryRunning) self ! Persistent(Done(...))
    }
  }

Otherwise you generate new persistent messages during replay, which is probably not what you want. These changes should make your example working properly.

Cheers,
Martin


On 08.05.14 23:41, Nicola Piccinini wrote:
What about the second part of my email concerning the problem I have
recovering the PersistentFSM:

I think it might well be coupled with the other issue, it seems that the
TestFSMRef somehow mixes up the Processor internals.
but that should not be related in any way with the tests.

I am experiencing it while normally running PersistentMain class.
With no journal, when you run it the first time, everything is fine.
When you run the second time it should recover the processed
persistent event and restart with a List with some elements but that
does not work:

unhandled event:
Event(PersistentImpl(Done(List(゜⋓想춌鋋)),1

In fact the handled event is Persistent, not PersistentImpl.
Am I missing something here?

Regards


--
Martin Krasser

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

--
     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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to