You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Artem Vovk <vo...@googlemail.com> on 2011/06/13 16:50:46 UTC
[jexl][scxml] Change values of map in scxml
Hi,
I have a data model in my scxml file, that defined as map:
<datamodel>
<data id="event" expr="{'key1' : 'value1', 'key2', 'value2'}">
</datamodel>
I want to use this data as a constructor for sending data, but I need to change values in this data:
something like that
<data id="event_new" expr="event_new = event, but change event[key1] to new_value ">
Is this possible within scxml using jexl?
Another question, that may replace this functionality, is using functions: can I define function in scxml using jexl?
Cheers Artem
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [scxml] Target of transition as variable?
Posted by Rahul Akolkar <ra...@gmail.com>.
On Thu, Jun 23, 2011 at 6:46 PM, Artem Vovk <vo...@googlemail.com> wrote:
> Thanks for the answer! I have also implemented on this way, but I think it makes all complicated and I see no benefits from static states
> I give an example where dyn states are useful and much less verbose:
>
> I have 10 basic_states that under some condition(internet is not available) can be transitioned to another special_state(NoInternetConnection), but this state must know the basic_state from which it receives the event, to go back under another condition(internet is available). With dynamic states it takes only one assign per basic_state and one transition in special_state and I does not need to change special_state each time when I want to add a new basic_state
>
<snip/>
Use history states (see mention in previous email).
-Rahul
> On Jun 23, 2011, at 11:54 PM, Rahul Akolkar wrote:
>
>> On Tue, Jun 21, 2011 at 3:42 PM, Artem Vovk <vo...@googlemail.com> wrote:
>>> Can I use dynamic transition targets? Something like this?
>>>
>>> <datamodel>
>>> <data id="dyn_state" expr="State1">
>>> </datamodel>
>>>
>>> ...
>>>
>>> <transition ... target="dyn_state"/>
>>>
>>> If I use it on this way, I receive an exception: Transition target with ID "dyn_state" not found -> Interpreter thinks that it is a name of the state, but not the variable... Is there a way to define such transitions?
>>>
>> <snip/>
>>
>> Not directly as you are illustrating above. Most state machines in
>> general, and SCXML in particular, requires you specify fixed target(s)
>> for each transition. This is actually quite useful because it allows
>> static analysis to determine whether all transition targets are legal
>> even before the state machine is executed. It is also not as limiting
>> as it may seem at first, because of the existence of things like guard
>> conditions on transitions and history states.
>>
>> For the above, a literal translation may appear to be as follows
>> (replacing dynamic target with static ones):
>>
>> <transition cond="dyn_state eq 'State1'" target="State1"/>
>> <transition cond="dyn_state eq 'State2'" target="State2"/>
>> ...
>>
>> The above pattern can certainly be used, and may seem more verbose.
>> But note that there are usually two <assign> or similar statements
>> elsewhere that are updating the data 'dyn_state'. Often, these can
>> instead be replaced as appropriate guard conditions on the two
>> transitions above so the net effect is no change in verbosity.
>>
>> -Rahul
>>
>> ---------------------------------------------------------------------
>> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [scxml] Target of transition as variable?
Posted by Artem Vovk <vo...@googlemail.com>.
Thanks for the answer! I have also implemented on this way, but I think it makes all complicated and I see no benefits from static states
I give an example where dyn states are useful and much less verbose:
I have 10 basic_states that under some condition(internet is not available) can be transitioned to another special_state(NoInternetConnection), but this state must know the basic_state from which it receives the event, to go back under another condition(internet is available). With dynamic states it takes only one assign per basic_state and one transition in special_state and I does not need to change special_state each time when I want to add a new basic_state
On Jun 23, 2011, at 11:54 PM, Rahul Akolkar wrote:
> On Tue, Jun 21, 2011 at 3:42 PM, Artem Vovk <vo...@googlemail.com> wrote:
>> Can I use dynamic transition targets? Something like this?
>>
>> <datamodel>
>> <data id="dyn_state" expr="State1">
>> </datamodel>
>>
>> ...
>>
>> <transition ... target="dyn_state"/>
>>
>> If I use it on this way, I receive an exception: Transition target with ID "dyn_state" not found -> Interpreter thinks that it is a name of the state, but not the variable... Is there a way to define such transitions?
>>
> <snip/>
>
> Not directly as you are illustrating above. Most state machines in
> general, and SCXML in particular, requires you specify fixed target(s)
> for each transition. This is actually quite useful because it allows
> static analysis to determine whether all transition targets are legal
> even before the state machine is executed. It is also not as limiting
> as it may seem at first, because of the existence of things like guard
> conditions on transitions and history states.
>
> For the above, a literal translation may appear to be as follows
> (replacing dynamic target with static ones):
>
> <transition cond="dyn_state eq 'State1'" target="State1"/>
> <transition cond="dyn_state eq 'State2'" target="State2"/>
> ...
>
> The above pattern can certainly be used, and may seem more verbose.
> But note that there are usually two <assign> or similar statements
> elsewhere that are updating the data 'dyn_state'. Often, these can
> instead be replaced as appropriate guard conditions on the two
> transitions above so the net effect is no change in verbosity.
>
> -Rahul
>
> ---------------------------------------------------------------------
> 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] Target of transition as variable?
Posted by Rahul Akolkar <ra...@gmail.com>.
On Tue, Jun 21, 2011 at 3:42 PM, Artem Vovk <vo...@googlemail.com> wrote:
> Can I use dynamic transition targets? Something like this?
>
> <datamodel>
> <data id="dyn_state" expr="State1">
> </datamodel>
>
> ...
>
> <transition ... target="dyn_state"/>
>
> If I use it on this way, I receive an exception: Transition target with ID "dyn_state" not found -> Interpreter thinks that it is a name of the state, but not the variable... Is there a way to define such transitions?
>
<snip/>
Not directly as you are illustrating above. Most state machines in
general, and SCXML in particular, requires you specify fixed target(s)
for each transition. This is actually quite useful because it allows
static analysis to determine whether all transition targets are legal
even before the state machine is executed. It is also not as limiting
as it may seem at first, because of the existence of things like guard
conditions on transitions and history states.
For the above, a literal translation may appear to be as follows
(replacing dynamic target with static ones):
<transition cond="dyn_state eq 'State1'" target="State1"/>
<transition cond="dyn_state eq 'State2'" target="State2"/>
...
The above pattern can certainly be used, and may seem more verbose.
But note that there are usually two <assign> or similar statements
elsewhere that are updating the data 'dyn_state'. Often, these can
instead be replaced as appropriate guard conditions on the two
transitions above so the net effect is no change in verbosity.
-Rahul
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
[scxml] Target of transition as variable?
Posted by Artem Vovk <vo...@googlemail.com>.
Can I use dynamic transition targets? Something like this?
<datamodel>
<data id="dyn_state" expr="State1">
</datamodel>
...
<transition ... target="dyn_state"/>
If I use it on this way, I receive an exception: Transition target with ID "dyn_state" not found -> Interpreter thinks that it is a name of the state, but not the variable... Is there a way to define such transitions?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [scxml] Transition without changing a state
Posted by Rahul Akolkar <ra...@gmail.com>.
On Sat, Jun 18, 2011 at 2:13 PM, Artem Vovk <vo...@googlemail.com> wrote:
> I have already found a solution, for triggering i have used type TriggerEvent.SIGNAL_EVENT with it, it doesn't work, but if I use TriggerEvent.CALL_EVENT it works. In the description of TriggerEvent class I have found : Specific event types have been defined in reference to SCXML, where can I find this reference?
<snip/>
The types above should not make any difference, they should really be
treated as an implementation detail at this point (SIGNAL is
recommended). A test case showing the difference in behavior above
will be useful.
> Which working draft was used for commons scxml?
>
<snap/>
Commons SCXML v0.9 is closest (there are some missing pieces --
especially optional ones like anchor which were later removed) to this
Working Draft:
http://www.w3.org/TR/2008/WD-scxml-20080516/
-Rahul
> On Jun 18, 2011, at 6:53 PM, Rahul Akolkar wrote:
>
>> On Sat, Jun 18, 2011 at 9:39 AM, Artem Vovk <vo...@googlemail.com> wrote:
>>> Hi,
>>>
>>> Is it a valid scxml expression in apache commons?
>>>
>> <snip/>
>>
>> If you mean transition, yes, target-less transitions are valid (a.k.a.
>> stay transitions).
>>
>>
>>> <transition event="internal" cond="_eventdata['name'] eq 'cancelclick'">
>>> <send event="'send_event'" targettype="'outside'" namelist="cancel" />
>>> </transition>
>>>
>>> Because I trigger this event, but send does not works.
>>>
>> <snap/>
>>
>> You should see the EventDispatcher#send() call if the transition is
>> indeed followed (event triggered and guard condition is true).
>>
>> -Rahul
>>
>>
>>>
>>> Cheers Artem
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [scxml] Transition without changing a state
Posted by Artem Vovk <vo...@googlemail.com>.
I have already found a solution, for triggering i have used type TriggerEvent.SIGNAL_EVENT with it, it doesn't work, but if I use TriggerEvent.CALL_EVENT it works. In the description of TriggerEvent class I have found : Specific event types have been defined in reference to SCXML, where can I find this reference? Which working draft was used for commons scxml?
On Jun 18, 2011, at 6:53 PM, Rahul Akolkar wrote:
> On Sat, Jun 18, 2011 at 9:39 AM, Artem Vovk <vo...@googlemail.com> wrote:
>> Hi,
>>
>> Is it a valid scxml expression in apache commons?
>>
> <snip/>
>
> If you mean transition, yes, target-less transitions are valid (a.k.a.
> stay transitions).
>
>
>> <transition event="internal" cond="_eventdata['name'] eq 'cancelclick'">
>> <send event="'send_event'" targettype="'outside'" namelist="cancel" />
>> </transition>
>>
>> Because I trigger this event, but send does not works.
>>
> <snap/>
>
> You should see the EventDispatcher#send() call if the transition is
> indeed followed (event triggered and guard condition is true).
>
> -Rahul
>
>
>>
>> Cheers Artem
>>
>
> ---------------------------------------------------------------------
> 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] Transition without changing a state
Posted by Rahul Akolkar <ra...@gmail.com>.
On Sat, Jun 18, 2011 at 9:39 AM, Artem Vovk <vo...@googlemail.com> wrote:
> Hi,
>
> Is it a valid scxml expression in apache commons?
>
<snip/>
If you mean transition, yes, target-less transitions are valid (a.k.a.
stay transitions).
> <transition event="internal" cond="_eventdata['name'] eq 'cancelclick'">
> <send event="'send_event'" targettype="'outside'" namelist="cancel" />
> </transition>
>
> Because I trigger this event, but send does not works.
>
<snap/>
You should see the EventDispatcher#send() call if the transition is
indeed followed (event triggered and guard condition is true).
-Rahul
>
> Cheers Artem
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
[scxml] Transition without changing a state
Posted by Artem Vovk <vo...@googlemail.com>.
Hi,
Is it a valid scxml expression in apache commons?
<transition event="internal" cond="_eventdata['name'] eq 'cancelclick'">
<send event="'send_event'" targettype="'outside'" namelist="cancel" />
</transition>
Because I trigger this event, but send does not works.
Cheers Artem
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [jexl][scxml] Change values of map in scxml
Posted by Rahul Akolkar <ra...@gmail.com>.
On Wed, Jun 15, 2011 at 12:25 PM, Artem Vovk <vo...@googlemail.com> wrote:
> Second method works pretty good, Thanks!
>
> One more question, is there in scxml version using in apache commons a time out functionality?
> I need something like:
> <state id="Awaiting">
> <onentry>
> Wait 5 sec than go to state "end"
> </onentry>
> </state>
>
<snip/>
Sure, use <send> with delay attribute and use the SimpleScheduler [1]
as the EventDispatcher implementation (or write similar if you want
something other than java.util.Timer).
-Rahul
[1] http://commons.apache.org/scxml/0.9/apidocs/org/apache/commons/scxml/env/SimpleScheduler.html
>
> On Jun 14, 2011, at 12:45 AM, Rahul Akolkar wrote:
>
>> On Mon, Jun 13, 2011 at 10:50 AM, Artem Vovk <vo...@googlemail.com> wrote:
>>> Hi,
>>>
>>> I have a data model in my scxml file, that defined as map:
>>> <datamodel>
>>> <data id="event" expr="{'key1' : 'value1', 'key2', 'value2'}">
>>> </datamodel>
>>>
>>> I want to use this data as a constructor for sending data, but I need to change values in this data:
>>> something like that
>>> <data id="event_new" expr="event_new = event, but change event[key1] to new_value ">
>>> Is this possible within scxml using jexl?
>>>
>> <snip/>
>>
>> Either using a <script> tag (unreleased, see J6 branch in SVN) or a
>> custom function as you mention below.
>>
>>
>>> Another question, that may replace this functionality, is using functions: can I define function in scxml using jexl?
>>>
>> <snap/>
>>
>> Yes, see bottom of this page, section on "Method invocation in expressions":
>>
>> http://commons.apache.org/scxml/guide/contexts-evaluators.html
>>
>> -Rahul
>>
>>
>>>
>>> Cheers Artem
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [jexl][scxml] Change values of map in scxml
Posted by Artem Vovk <vo...@googlemail.com>.
Second method works pretty good, Thanks!
One more question, is there in scxml version using in apache commons a time out functionality?
I need something like:
<state id="Awaiting">
<onentry>
Wait 5 sec than go to state "end"
</onentry>
</state>
On Jun 14, 2011, at 12:45 AM, Rahul Akolkar wrote:
> On Mon, Jun 13, 2011 at 10:50 AM, Artem Vovk <vo...@googlemail.com> wrote:
>> Hi,
>>
>> I have a data model in my scxml file, that defined as map:
>> <datamodel>
>> <data id="event" expr="{'key1' : 'value1', 'key2', 'value2'}">
>> </datamodel>
>>
>> I want to use this data as a constructor for sending data, but I need to change values in this data:
>> something like that
>> <data id="event_new" expr="event_new = event, but change event[key1] to new_value ">
>> Is this possible within scxml using jexl?
>>
> <snip/>
>
> Either using a <script> tag (unreleased, see J6 branch in SVN) or a
> custom function as you mention below.
>
>
>> Another question, that may replace this functionality, is using functions: can I define function in scxml using jexl?
>>
> <snap/>
>
> Yes, see bottom of this page, section on "Method invocation in expressions":
>
> http://commons.apache.org/scxml/guide/contexts-evaluators.html
>
> -Rahul
>
>
>>
>> Cheers Artem
>
> ---------------------------------------------------------------------
> 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: [jexl][scxml] Change values of map in scxml
Posted by Rahul Akolkar <ra...@gmail.com>.
On Mon, Jun 13, 2011 at 10:50 AM, Artem Vovk <vo...@googlemail.com> wrote:
> Hi,
>
> I have a data model in my scxml file, that defined as map:
> <datamodel>
> <data id="event" expr="{'key1' : 'value1', 'key2', 'value2'}">
> </datamodel>
>
> I want to use this data as a constructor for sending data, but I need to change values in this data:
> something like that
> <data id="event_new" expr="event_new = event, but change event[key1] to new_value ">
> Is this possible within scxml using jexl?
>
<snip/>
Either using a <script> tag (unreleased, see J6 branch in SVN) or a
custom function as you mention below.
> Another question, that may replace this functionality, is using functions: can I define function in scxml using jexl?
>
<snap/>
Yes, see bottom of this page, section on "Method invocation in expressions":
http://commons.apache.org/scxml/guide/contexts-evaluators.html
-Rahul
>
> Cheers Artem
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org