The Artima Developer Community
Sponsored Link

Akka Concurrency Forum
FSM's onTransition, transform and using

1 reply on 1 page. Most recent reply: Jul 20, 2015 5:31 AM by Derek Wyatt

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Chifeng Chou

Posts: 2
Nickname: cfchou
Registered: Jul, 2013

FSM's onTransition, transform and using Posted: Feb 6, 2014 1:27 AM
Reply to this message Reply
Advertisement
I've been using Akka a bit but never tried FSM. Today I read section 9.3 which puzzles me a little.

As to "onTransition", I'm not sure it's the purpose but I find it may be useful in cases that the state machine is dealt with from transitions' perspective. But I'm not sure, "onTransition" an "when", which one is the better place to write corresponding actions.

In addtion, IMHO, "transform" and "using" don't seem be necessary as, I assume, everything can be boiled down to "when" and it probably will be clearer. I would like to know what you think.



cheers


Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: FSM's onTransition, transform and using Posted: Jul 20, 2015 5:31 AM
Reply to this message Reply
From what I can gather, you might be getting things a bit confused; the four different things you've mentioned have four very distinct and important differences.

when and onTransition are related, but distinct.

You use when to declare what the message handler should be when you're in that particular state. You can think of when as saying "When the FSM is in this state, the receive partial function should be what is declared here". But a very important point is that it is merely a receive handler, and does not imply that any event has taken, or ever will actually take place.

There is an event that does take place when you transition from one state to another (i.e. from one when to another when), which is fired by the FSM itself. To capture these events and operate on them, you use onTransition.

Now, you're correct by saying that you could run the same "on transition" code from a specific case in a when but you would have to do that in every case that transitions to that "important" state. That could get exceedingly ugly and prone to error.

using and transform are used to declare the data for the next state, although transform is a bit more intricate.

Again, you could cobble together something that might let you completely ignore onTransition, using and transform but your code would probably look horrendous. If you still wanted to avoid using those abstractions, and make your code understandable and not-so-prone to bugs, you'd probably end up writing those abstractions anyway :)

Flat View: This topic has 1 reply on 1 page
Topic: Ch 6.5 MyActorSpec Previous Topic   Next Topic Topic: Problem testing dead pilot

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use