Search code examples
scalaerlangstate-machinefsm

Finite State Machine and inter-FSM signaling


Recommendations for languages with native (so no FSM generation tools) support for state machine development and execution and passing of messages/signals. This is for telecoms, e.g implementation of FSMs of this level of complexity.

I have considered Erlang, but would love some feedback, suggestions, pointer to tutorials, alternatives, particularly Java based frameworks. Maybe Scala?

Open source only. I'm not looking for UML or regular expression related solutions.

As this is for the implementation of telecoms protocols the FSMs may be non-trivial. Many states, many transitions, signal based, input constraints/guards. Dynamic instantiation would be a plus. Switch statements are out of the question, it quickly nests to unusable. It's barely better that if/else.

I would prefer to not depend on graphical design; the format FSM description should be human readable/editable/manageable.

--

I have decided to focus on an Actor based solution for C++

For example, the Theron framework provides a starting point http://theron.ashtonmason.net/ and to avoid switch statements in the FSM based event handler this C++ FSM Template Framework looks useful http://satsky.spb.ru/articles/fsm/fsmEng.php


Solution

  • I agree that switch statements should be out of the question... they eventually lead to maintenance nightmares. Can't you use the State Pattern to implement your FSM? Depending on your actual implementation, you could use actors (if you have multiple FSM collaborating - hm... is that possible?). The nice thing about actors is that the framework for passing messages is already there.

    An example of using State would be:

    trait State {
      def changeState(message: Any): State
    }
    
    trait FSM extends Actor {
      var state: State
    
      def processMessage(message: Any) {
        state = state.changeState(message)
      }
    
      override def act() {
        loop {
          react {
            case m: Any => processMessage(m)
          }
        }
      }
    }
    

    This is very basic code, but as I don't know more of the requirements, that's the most I can think of. The advantage of State is that every state is self-contained in one class.