commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rahul Akolkar" <rahul.akol...@gmail.com>
Subject Re: [SCXML] State traceability
Date Thu, 11 Dec 2008 21:29:53 GMT
On Thu, Dec 11, 2008 at 1:50 PM, Ouyang, Landon - ES/RDR -Gil
<Landon.Ouyang@itt.com> wrote:
> Hello,
>
> I have written an application utilizing Apache Commons SCXML and JNI to add a state machine
to an application written in C++. Each state in my state machine executes a custom action
that will run a C++ routine.
>
> I need to add traceability to my application so that a history log containing what states
and triggers were used during the traversal of the state machine can be created. The state
machine I am using is based off of AbstractStateMachine and I am using the following code
to get the current state's ID:
>
>    public String getCurrentState()
>    {
>      Set states = getEngine().getCurrentStatus().getStates();
>      return ((org.apache.commons.scxml.model.State) states.iterator().
>          next()).getId();
>    }
>
> I call this Java routine from within the C++ routine executed by the custom action of
that state. The problem is this: it appears that the returning state ID of the routine is
always one state "behind" the state in which the custom action is run. It appears there is
a timing issue.
>
<snip/>

Until all the <onentry> actions in the transition target are executed,
the transition is not complete (hence, the status will reveal the
prior state).


> How would I fix this? Better yet, is there a different approach to this problem I should
be using?
>
<snap/>

You can use the information in the model itself to ascertain the id of
the parent state for each action. So, in your custom action's execute
method:

public class MyAction extends Action {

    ...

    public void execute(...) throws ... {

        String currentStateId = getParentTransitionTarget().getId();

        // call native method, you might as well pass the currentStateId here
        // rather than making another call out of the native code
    }

}

Finally, the AbstractStateMachine class is fairly limiting (its meant
to address a subset of simple usecases). If you need more, best to use
the basic Commons SCXML APIs (parser, executor etc.) and design an
appropriate solution.

-Rahul


> Thanks,
> --
> Landon Ouyang
> Senior Design Engineer
> ITT Electronics Systems, Radar Systems - Gilfillan
> 7821 Orion Ave,
> Van Nuys, CA 91406
> (818) 901-2982
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message