You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Thiébault Benoît <de...@artenum.com> on 2010/09/20 12:04:21 UTC

[scxml] How to retrieve the transition target in a custom action

Hi everyone,

I would like to retrieve the transition target (if there is one) in my custom action.
How can I do this?

My need is more to know if there is a transition than to know what the target is.
I need this info to know if it is possible to launch a long computation in a different thread:
- if there is a transition target, the state machine will go to the new state and my computation will be started in one state and continue in another one, which I want to avoid.
- if there is no transition target, it means that my computation is performed within the original state (internal transition) and I can use my computation without fearing an undetermined state machine.

Kind regards,

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


Re: [scxml] How to retrieve the transition target in a custom action

Posted by Rahul Akolkar <ra...@gmail.com>.
2010/9/21 Thiébault Benoît <de...@artenum.com>:
>
> Le 21 sept. 2010 à 00:12, Rahul Akolkar a écrit :
>
>> <snip/>
>>
>> I believe you mean a transition thats not a stay nor self transition,
>> since the only way a custom action will ever execute is if some
>> transiton is being followed (in order for SCXML executable content to
>> execute).
>
> Thank you Rahul for your answer.
> Indeed I want to know wether I'm in a stay or self transition. I confirm that my custom action is within a transition (or onentry/onexit).
>>
>> There isn't a direct way to access information about the transition
>> target. I imagine your custom action is within a transition element.
>> If so, you could walk up the SCXML object model and check whether the
>> parent transition has a target attribute and whether it is the parent
>> state id itself.
>
> How can you do this from within a custom action?
>
<snip/>

See class Javadocs [1] for details, but briefly:

  Action#getParent() gives you the parent Executable container (such
as transition object)

  Action#getParentTransitionTarget() gives you the parent state (or
parallel etc.)

With a handle to those two, it should be possible to figure out
whether its a stay or self transition.

-Rahul

[1] http://commons.apache.org/scxml/0.9/apidocs/org/apache/commons/scxml/model/Action.html


>> It may also be possible to infer whether a (non-stay)
>> transition is being followed and what the target is, by using a
>> suitable SCXMLListener impl.
>>
>> For long computations, you should consider using the external
>> communications module (either <send> or <invoke>) to send an event to
>> (or invoke) some external process which manages the computation and
>> fires a completion event on the state machine when done.
>
> I quickly looked at the invoke examples provided in SCXML tests and they seem less appropriate than using custom actions, which make the XML file more readable IMHO.
>
>>
>> -Rahul
>>
>>
>>> I need this info to know if it is possible to launch a long computation in a different thread:
>>> - if there is a transition target, the state machine will go to the new state and my computation will be started in one state and continue in another one, which I want to avoid.
>>> - if there is no transition target, it means that my computation is performed within the original state (internal transition) and I can use my computation without fearing an undetermined state machine.
>>>
>>> Kind regards,
>>>
>>> Ben
>>

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


Re: [scxml] How to retrieve the transition target in a custom action

Posted by Thiébault Benoît <de...@artenum.com>.
Le 21 sept. 2010 à 00:12, Rahul Akolkar a écrit :

> <snip/>
> 
> I believe you mean a transition thats not a stay nor self transition,
> since the only way a custom action will ever execute is if some
> transiton is being followed (in order for SCXML executable content to
> execute).

Thank you Rahul for your answer.
Indeed I want to know wether I'm in a stay or self transition. I confirm that my custom action is within a transition (or onentry/onexit).
> 
> There isn't a direct way to access information about the transition
> target. I imagine your custom action is within a transition element.
> If so, you could walk up the SCXML object model and check whether the
> parent transition has a target attribute and whether it is the parent
> state id itself.

How can you do this from within a custom action?

> It may also be possible to infer whether a (non-stay)
> transition is being followed and what the target is, by using a
> suitable SCXMLListener impl.
> 
> For long computations, you should consider using the external
> communications module (either <send> or <invoke>) to send an event to
> (or invoke) some external process which manages the computation and
> fires a completion event on the state machine when done.

I quickly looked at the invoke examples provided in SCXML tests and they seem less appropriate than using custom actions, which make the XML file more readable IMHO.

> 
> -Rahul
> 
> 
>> I need this info to know if it is possible to launch a long computation in a different thread:
>> - if there is a transition target, the state machine will go to the new state and my computation will be started in one state and continue in another one, which I want to avoid.
>> - if there is no transition target, it means that my computation is performed within the original state (internal transition) and I can use my computation without fearing an undetermined state machine.
>> 
>> Kind regards,
>> 
>> Ben
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 


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


Re: [scxml] How to retrieve the transition target in a custom action

Posted by Rahul Akolkar <ra...@gmail.com>.
2010/9/20 Thiébault Benoît <de...@artenum.com>:
> Hi everyone,
>
> I would like to retrieve the transition target (if there is one) in my custom action.
> How can I do this?
>
> My need is more to know if there is a transition than to know what the target is.
<snip/>

I believe you mean a transition thats not a stay nor self transition,
since the only way a custom action will ever execute is if some
transiton is being followed (in order for SCXML executable content to
execute).

There isn't a direct way to access information about the transition
target. I imagine your custom action is within a transition element.
If so, you could walk up the SCXML object model and check whether the
parent transition has a target attribute and whether it is the parent
state id itself. It may also be possible to infer whether a (non-stay)
transition is being followed and what the target is, by using a
suitable SCXMLListener impl.

For long computations, you should consider using the external
communications module (either <send> or <invoke>) to send an event to
(or invoke) some external process which manages the computation and
fires a completion event on the state machine when done.

-Rahul


> I need this info to know if it is possible to launch a long computation in a different thread:
> - if there is a transition target, the state machine will go to the new state and my computation will be started in one state and continue in another one, which I want to avoid.
> - if there is no transition target, it means that my computation is performed within the original state (internal transition) and I can use my computation without fearing an undetermined state machine.
>
> Kind regards,
>
> Ben

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