You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Ouyang, Landon - ES/RDR -Gil" <La...@itt.com> on 2008/12/11 19:50:41 UTC

[SCXML] State traceability

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.

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

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


________________________________
This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender.
Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.

Re: [SCXML] State traceability

Posted by Rahul Akolkar <ra...@gmail.com>.
On Thu, Dec 11, 2008 at 1:50 PM, Ouyang, Landon - ES/RDR -Gil
<La...@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