views:

314

answers:

1

Hello
I'm attempting to define a state machine for a Java application using Apache SCXML. However, I've run into a problem and I'm not sure if this is due to the SCXML framework or me doing something wrong.
I'm basing my test application on the following example (without the android bit):
http://commons.apache.org/scxml/usecases/scxml-stopwatch-on-android.html

The file StopWatch.java (http://commons.apache.org/scxml/xref-test/org/apache/commons/scxml/env/StopWatch.html)

public class StopWatch extends AbstractStateMachine {
    public void reset() {

    }

    public void running() {
    }

    public void paused() {
    }

    public void stopped() {
    }
}

The problem is the above states are only called once per transition. Is this correct? Shouldn't the state function be called continuously as long as the state machine remains in the given state?

Thanks!

A: 

Why would you expect this behavior? Your state class only needs to know about the transition. Once you've transitioned, you're in a steady state.

Jim Barrows
Hi - thanks for your answer. I've always thought of a state machine as being composed of a while loop and a switch statement i.e. i expect the current state to be executed as long as it's valid - see the answer to http://stackoverflow.com/questions/133214/is-there-a-typical-state-machine-implementation-patterni could of course have a while loop inside the states above, but i don't think this is the correct thing to do, I think the framework probably expects the state functions to return after handling the transition events.
leftbrainlogic