You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Anna Södling <an...@passagen.se> on 2009/04/08 13:53:20 UTC

[SCXML] Timers in SCXML

Hello, 
 
I'm having a little problem regarding timers in SCXML. I have built a
simple statemachine with two states and a transition going from each
state to the other. The transitions should not be taken when a user
"orders" an event, but when a timer has timed out. The code I have
written for this (which obviously is incorrect since it doesn't solve my
problem, but it might give an idea of how I'm thinking) looks like this
(I've tried to implement the timers like in the examples on this page,
if that might be any hint to what may be wrong:
http://www.ling.gu.se/~lager/Labs/SCXML-Lab/ ):
 
<scxml version="1.0" initialstate="167" xmlns:cs="
http://commons.apache.org/scxml" xmlns="
http://www.w3.org/2005/07/scxml">
<state id = "167">
<transition target="StateA"/>
</state>
<state id ="StateA">
<onentry>
<send sendid="1" target="'StateA'" event="'ToB'" delay="'1000ms'" />
</onentry>
<transition event="ToB" target="StateB"/>
</state>
<state id="StateB">
<onentry>
<send sendid="2" target="'StateB'" event="'ToA'" delay="'2000ms'" />
</onentry>
<transition event="ToA" target="StateA"/>
</state>
</scxml>
 
I get complaints about my target and event parts. What I want is that
when you enter a state, a timer with the value of the delay attribute
should start ticking inside the current state and when the timer times
out, it should take the transition with the same event as the event in
the send tag. But when I do this, I get this warning:
VARNING: <send>: target expression "StateA" evaluated to null or empty
String
(I tried to write target="'Self'" instead, too, but that didn't help
either)
 
I also tried to remove the target attribute, but then I get this line:
INFO: send ( sendId: 1, target: null, targetType: scxml, event: ToB,
params: null, hints: null, delay: 1000)
and nothing else happens. 
 
If anyone has any ideas of what I might have done wrong and how I can
solve this problem (preferably without implementing any custom actions),
I would be really happy!
 
Sincerely,
Anna


<P><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR> </font>

Re: [SCXML] Timers in SCXML

Posted by Woonsan Ko <wo...@apache.org>.
Hi,

Which version of SCXML are you using? If you used a version older than
2.0-SNAPSHOT (sorry, 2.0 is still not released yet), could you try
with 2.0-SNAPSHOT by building locally by yourself from [1]?
Also, I wonder if you had a chance to follow Rahul's advice in the old
thread? I think he already gave good pointers.

Regards,

Woonsan

[1] https://github.com/apache/commons-scxml

On Thu, Sep 3, 2015 at 7:47 PM, giangttpham <gi...@gmail.com> wrote:
> I know this topic has been solved a long time ago but if anyone out there is
> listening, please help me. This is the scxml I have but the Timer delay
> doesn't work. I have the same problem as the person who started this post,
> after the send, the program just stops, it never goes to the next state.
>
> <scxml xmlns="http://www.w3.org/2005/07/scxml"
>               version="1.0"
>               initial="player">
>
>         <datamodel>
>                 <data id="segment" expr="0"/>
>                 <data id="segments" expr="10"/>
>         </datamodel>
>
>      <final id="stopped">
>       <onentry>
>        <log expr="'PLAYER_STOPPED'" />
>       </onentry>
>      </final>
>
>         <state id="player" initial="closed">
>
>             <state id="closed">
>                 <transition target="opened"/>
>                         <onexit><log expr="'Opening app...'"/></onexit>
>                 </state>
>
>             <state id="opened">
>                 <onentry>
>                                 <send event="'Timer'" delay="'2s'"/>
>                         </onentry>
>                         <transition event="Timer" target="playing" />
>                         <onexit>
>                                 <log expr="'Attempting to play...'"/>
>                                 <cancel sendid="delay"/>
>                         </onexit>
>             </state>
>
>             <state id="playing">
>                     <onentry><log expr="'STATE_PLAYING: ' + segment"/></onentry>
>                         <onexit>
>                                 <assign location="segment" expr="segment+1" />
>                         </onexit>
>                     <transition target="stopped" cond="segment == segments" />
>                     <transition target="playing"/>
>             </state>
>         </state>
> </scxml>
>
>
>
> --
> View this message in context: http://apache-commons.680414.n4.nabble.com/SCXML-Timers-in-SCXML-tp746934p4678456.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> 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] Timers in SCXML

Posted by giangttpham <gi...@gmail.com>.
I know this topic has been solved a long time ago but if anyone out there is
listening, please help me. This is the scxml I have but the Timer delay
doesn't work. I have the same problem as the person who started this post,
after the send, the program just stops, it never goes to the next state.

<scxml xmlns="http://www.w3.org/2005/07/scxml"
              version="1.0"
              initial="player">

	<datamodel>
		<data id="segment" expr="0"/>
		<data id="segments" expr="10"/>
	</datamodel>
	
     <final id="stopped">
      <onentry>
       <log expr="'PLAYER_STOPPED'" />
      </onentry>
     </final>

	<state id="player" initial="closed">
	
	    <state id="closed">
	    	<transition target="opened"/>
			<onexit><log expr="'Opening app...'"/></onexit>
		</state>
	    
	    <state id="opened">
	    	<onentry>
				<send event="'Timer'" delay="'2s'"/>				
			</onentry>
			<transition event="Timer" target="playing" />
			<onexit>
				<log expr="'Attempting to play...'"/>
				<cancel sendid="delay"/>
			</onexit>
	    </state>
	    
	    <state id="playing">
		    <onentry><log expr="'STATE_PLAYING: ' + segment"/></onentry>
			<onexit>
				<assign location="segment" expr="segment+1" />
			</onexit>
		    <transition target="stopped" cond="segment == segments" />
		    <transition target="playing"/>
	    </state>
	</state>
</scxml>



--
View this message in context: http://apache-commons.680414.n4.nabble.com/SCXML-Timers-in-SCXML-tp746934p4678456.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


Re: [SCXML] Timers in SCXML

Posted by Rahul Akolkar <ra...@gmail.com>.
On Wed, Apr 15, 2009 at 11:02 AM, Linda Erlenhov
<li...@gmail.com> wrote:
> Hello
> Sorry to mass-spam email you, but I solved the problem myself after a food
> break and some more thinking.  The problem was the way I was trying to solve
> the data requests i asked about in another mail. So this is not a problem
> anymore, thank you!
>
<snip/>

This isn't remotely close to spam, in fact its quite useful to know
when issues are resolved so thanks for following up.

-Rahul



> //Linda
>
> On Wed, Apr 15, 2009 at 2:16 PM, Linda Erlenhov <li...@gmail.com>wrote:
>
>> Hello again.
>> I run the standalone test and it looks like the timers work fine there (An
>> infinit loop between the two states, the logs, except for those that was
>> nested as you pointed out, are printed one or two seconds apart as specified
>> in the scxml ), so now I´m a bit clueless with how to proceed, any idéas? Is
>> there anything I might have forgotten in my java files since it doesn´t work
>> there?
>>
>> best regards
>> //Linda
>>
>> On Tue, Apr 14, 2009 at 9:11 PM, Rahul Akolkar <ra...@gmail.com>wrote:
>>
>>> On Tue, Apr 14, 2009 at 8:19 AM, Linda Erlenhov
>>> <li...@gmail.com> wrote:
>>> > Hello!
>>> >
>>> > This may be a stupid question but:
>>> > I have read through the code for the simple scheduler and I´m  not sure
>>> i
>>> > understand what happens.
>>> > We have written a simple scxml for a small statechart containing two
>>> states
>>> > with timers and used the simple scheduler as described in your previous
>>> > e-mail. As I understand the timers would make the machine just jump
>>> between
>>> > the two states. This doesn´t happen. Why?
>>> <snip/>
>>>
>>> The Commons SCXML version and the relevant driver (Java) code will
>>> help towards answering -- we know this works, so we'll need to know
>>> whats being done differently. Bear in mind that the timers execute as
>>> daemons.
>>>
>>> I suggest trying your example standalone [1] first, and we'll go from
>>> there.
>>>
>>> As an aside, in the markup below, <log> is nested in <send> which
>>> isn't legal, so the nested <log> will be ignored.
>>>
>>> -Rahul
>>>
>>> [1] http://commons.apache.org/scxml/guide/testing-standalone.html
>>>
>>>
>>>
>>> > ---------------------------
>>> > <scxml version="1.0" initialstate="167" xmlns:cs="
>>> > http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml
>>> ">
>>> > <state id = "167">
>>> > <transition target="StateA"/>
>>> > </state>
>>> > <state id ="StateA">
>>> > <onentry>
>>> > <log label="Renegade" expr="'Entering state: A'"/>
>>> > <send sendid="1" event="'ToB'" delay="'1000ms'">
>>> > <log label="Renegade" expr="'Timer starting...'"/>
>>> > </send>
>>> > </onentry>
>>> > <transition event="ToB" target="StateB"/>
>>> > </state>
>>> > <state id="StateB">
>>> > <onentry>
>>> > <log label="Renegade" expr="'Entering state: B'"/>
>>> > <send sendid="2" event="'ToA'" delay="'2000ms'">
>>> > <log label="Renegade" expr="'Timer starting...'"/>
>>> > </send>
>>> > </onentry>
>>> > <transition event="ToA" target="StateA"/>
>>> > </state>
>>> > </scxml>
>>> > ---------------------
>>> >
>>> > The output when this is run is simply:
>>> > 2009-apr-14 13:08:57 org.apache.commons.scxml.model.Log execute
>>> > INFO: Renegade: Entering state: A
>>> > 2009-apr-14 13:08:57 org.apache.commons.scxml.env.SimpleScheduler send
>>> > INFO: send ( sendId: 1, target: null, targetType: scxml, event: ToB,
>>> params:
>>> > null, hints: null, delay: 1000)
>>> >
>>> > best regards
>>> > //Linda
>>> >
>>>

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


Re: [SCXML] Timers in SCXML

Posted by Linda Erlenhov <li...@gmail.com>.
Hello
Sorry to mass-spam email you, but I solved the problem myself after a food
break and some more thinking.  The problem was the way I was trying to solve
the data requests i asked about in another mail. So this is not a problem
anymore, thank you!

//Linda

On Wed, Apr 15, 2009 at 2:16 PM, Linda Erlenhov <li...@gmail.com>wrote:

> Hello again.
> I run the standalone test and it looks like the timers work fine there (An
> infinit loop between the two states, the logs, except for those that was
> nested as you pointed out, are printed one or two seconds apart as specified
> in the scxml ), so now I´m a bit clueless with how to proceed, any idéas? Is
> there anything I might have forgotten in my java files since it doesn´t work
> there?
>
> best regards
> //Linda
>
> On Tue, Apr 14, 2009 at 9:11 PM, Rahul Akolkar <ra...@gmail.com>wrote:
>
>> On Tue, Apr 14, 2009 at 8:19 AM, Linda Erlenhov
>> <li...@gmail.com> wrote:
>> > Hello!
>> >
>> > This may be a stupid question but:
>> > I have read through the code for the simple scheduler and I´m  not sure
>> i
>> > understand what happens.
>> > We have written a simple scxml for a small statechart containing two
>> states
>> > with timers and used the simple scheduler as described in your previous
>> > e-mail. As I understand the timers would make the machine just jump
>> between
>> > the two states. This doesn´t happen. Why?
>> <snip/>
>>
>> The Commons SCXML version and the relevant driver (Java) code will
>> help towards answering -- we know this works, so we'll need to know
>> whats being done differently. Bear in mind that the timers execute as
>> daemons.
>>
>> I suggest trying your example standalone [1] first, and we'll go from
>> there.
>>
>> As an aside, in the markup below, <log> is nested in <send> which
>> isn't legal, so the nested <log> will be ignored.
>>
>> -Rahul
>>
>> [1] http://commons.apache.org/scxml/guide/testing-standalone.html
>>
>>
>>
>> > ---------------------------
>> > <scxml version="1.0" initialstate="167" xmlns:cs="
>> > http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml
>> ">
>> > <state id = "167">
>> > <transition target="StateA"/>
>> > </state>
>> > <state id ="StateA">
>> > <onentry>
>> > <log label="Renegade" expr="'Entering state: A'"/>
>> > <send sendid="1" event="'ToB'" delay="'1000ms'">
>> > <log label="Renegade" expr="'Timer starting...'"/>
>> > </send>
>> > </onentry>
>> > <transition event="ToB" target="StateB"/>
>> > </state>
>> > <state id="StateB">
>> > <onentry>
>> > <log label="Renegade" expr="'Entering state: B'"/>
>> > <send sendid="2" event="'ToA'" delay="'2000ms'">
>> > <log label="Renegade" expr="'Timer starting...'"/>
>> > </send>
>> > </onentry>
>> > <transition event="ToA" target="StateA"/>
>> > </state>
>> > </scxml>
>> > ---------------------
>> >
>> > The output when this is run is simply:
>> > 2009-apr-14 13:08:57 org.apache.commons.scxml.model.Log execute
>> > INFO: Renegade: Entering state: A
>> > 2009-apr-14 13:08:57 org.apache.commons.scxml.env.SimpleScheduler send
>> > INFO: send ( sendId: 1, target: null, targetType: scxml, event: ToB,
>> params:
>> > null, hints: null, delay: 1000)
>> >
>> > best regards
>> > //Linda
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>

Re: [SCXML] Timers in SCXML

Posted by Linda Erlenhov <li...@gmail.com>.
Hello again.
I run the standalone test and it looks like the timers work fine there (An
infinit loop between the two states, the logs, except for those that was
nested as you pointed out, are printed one or two seconds apart as specified
in the scxml ), so now I´m a bit clueless with how to proceed, any idéas? Is
there anything I might have forgotten in my java files since it doesn´t work
there?

best regards
//Linda

On Tue, Apr 14, 2009 at 9:11 PM, Rahul Akolkar <ra...@gmail.com>wrote:

> On Tue, Apr 14, 2009 at 8:19 AM, Linda Erlenhov
> <li...@gmail.com> wrote:
> > Hello!
> >
> > This may be a stupid question but:
> > I have read through the code for the simple scheduler and I´m  not sure i
> > understand what happens.
> > We have written a simple scxml for a small statechart containing two
> states
> > with timers and used the simple scheduler as described in your previous
> > e-mail. As I understand the timers would make the machine just jump
> between
> > the two states. This doesn´t happen. Why?
> <snip/>
>
> The Commons SCXML version and the relevant driver (Java) code will
> help towards answering -- we know this works, so we'll need to know
> whats being done differently. Bear in mind that the timers execute as
> daemons.
>
> I suggest trying your example standalone [1] first, and we'll go from
> there.
>
> As an aside, in the markup below, <log> is nested in <send> which
> isn't legal, so the nested <log> will be ignored.
>
> -Rahul
>
> [1] http://commons.apache.org/scxml/guide/testing-standalone.html
>
>
>
> > ---------------------------
> > <scxml version="1.0" initialstate="167" xmlns:cs="
> > http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml
> ">
> > <state id = "167">
> > <transition target="StateA"/>
> > </state>
> > <state id ="StateA">
> > <onentry>
> > <log label="Renegade" expr="'Entering state: A'"/>
> > <send sendid="1" event="'ToB'" delay="'1000ms'">
> > <log label="Renegade" expr="'Timer starting...'"/>
> > </send>
> > </onentry>
> > <transition event="ToB" target="StateB"/>
> > </state>
> > <state id="StateB">
> > <onentry>
> > <log label="Renegade" expr="'Entering state: B'"/>
> > <send sendid="2" event="'ToA'" delay="'2000ms'">
> > <log label="Renegade" expr="'Timer starting...'"/>
> > </send>
> > </onentry>
> > <transition event="ToA" target="StateA"/>
> > </state>
> > </scxml>
> > ---------------------
> >
> > The output when this is run is simply:
> > 2009-apr-14 13:08:57 org.apache.commons.scxml.model.Log execute
> > INFO: Renegade: Entering state: A
> > 2009-apr-14 13:08:57 org.apache.commons.scxml.env.SimpleScheduler send
> > INFO: send ( sendId: 1, target: null, targetType: scxml, event: ToB,
> params:
> > null, hints: null, delay: 1000)
> >
> > best regards
> > //Linda
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [SCXML] Timers in SCXML

Posted by Rahul Akolkar <ra...@gmail.com>.
On Tue, Apr 14, 2009 at 8:19 AM, Linda Erlenhov
<li...@gmail.com> wrote:
> Hello!
>
> This may be a stupid question but:
> I have read through the code for the simple scheduler and I´m  not sure i
> understand what happens.
> We have written a simple scxml for a small statechart containing two states
> with timers and used the simple scheduler as described in your previous
> e-mail. As I understand the timers would make the machine just jump between
> the two states. This doesn´t happen. Why?
<snip/>

The Commons SCXML version and the relevant driver (Java) code will
help towards answering -- we know this works, so we'll need to know
whats being done differently. Bear in mind that the timers execute as
daemons.

I suggest trying your example standalone [1] first, and we'll go from there.

As an aside, in the markup below, <log> is nested in <send> which
isn't legal, so the nested <log> will be ignored.

-Rahul

[1] http://commons.apache.org/scxml/guide/testing-standalone.html



> ---------------------------
> <scxml version="1.0" initialstate="167" xmlns:cs="
> http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml">
> <state id = "167">
> <transition target="StateA"/>
> </state>
> <state id ="StateA">
> <onentry>
> <log label="Renegade" expr="'Entering state: A'"/>
> <send sendid="1" event="'ToB'" delay="'1000ms'">
> <log label="Renegade" expr="'Timer starting...'"/>
> </send>
> </onentry>
> <transition event="ToB" target="StateB"/>
> </state>
> <state id="StateB">
> <onentry>
> <log label="Renegade" expr="'Entering state: B'"/>
> <send sendid="2" event="'ToA'" delay="'2000ms'">
> <log label="Renegade" expr="'Timer starting...'"/>
> </send>
> </onentry>
> <transition event="ToA" target="StateA"/>
> </state>
> </scxml>
> ---------------------
>
> The output when this is run is simply:
> 2009-apr-14 13:08:57 org.apache.commons.scxml.model.Log execute
> INFO: Renegade: Entering state: A
> 2009-apr-14 13:08:57 org.apache.commons.scxml.env.SimpleScheduler send
> INFO: send ( sendId: 1, target: null, targetType: scxml, event: ToB, params:
> null, hints: null, delay: 1000)
>
> best regards
> //Linda
>

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


Re: [SCXML] Timers in SCXML

Posted by Linda Erlenhov <li...@gmail.com>.
Hello!

This may be a stupid question but:
I have read through the code for the simple scheduler and I´m  not sure i
understand what happens.
We have written a simple scxml for a small statechart containing two states
with timers and used the simple scheduler as described in your previous
e-mail. As I understand the timers would make the machine just jump between
the two states. This doesn´t happen. Why?
---------------------------
<scxml version="1.0" initialstate="167" xmlns:cs="
http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml">
<state id = "167">
<transition target="StateA"/>
</state>
<state id ="StateA">
<onentry>
<log label="Renegade" expr="'Entering state: A'"/>
<send sendid="1" event="'ToB'" delay="'1000ms'">
<log label="Renegade" expr="'Timer starting...'"/>
</send>
</onentry>
<transition event="ToB" target="StateB"/>
</state>
<state id="StateB">
<onentry>
<log label="Renegade" expr="'Entering state: B'"/>
<send sendid="2" event="'ToA'" delay="'2000ms'">
<log label="Renegade" expr="'Timer starting...'"/>
</send>
</onentry>
<transition event="ToA" target="StateA"/>
</state>
</scxml>
---------------------

The output when this is run is simply:
2009-apr-14 13:08:57 org.apache.commons.scxml.model.Log execute
INFO: Renegade: Entering state: A
2009-apr-14 13:08:57 org.apache.commons.scxml.env.SimpleScheduler send
INFO: send ( sendId: 1, target: null, targetType: scxml, event: ToB, params:
null, hints: null, delay: 1000)

best regards
//Linda

Re: [SCXML] Timers in SCXML

Posted by Rahul Akolkar <ra...@gmail.com>.
On Wed, Apr 8, 2009 at 7:53 AM, Anna Södling <an...@passagen.se> wrote:
> Hello,
>
> I'm having a little problem regarding timers in SCXML. I have built a
> simple statemachine with two states and a transition going from each
> state to the other. The transitions should not be taken when a user
> "orders" an event, but when a timer has timed out. The code I have
> written for this (which obviously is incorrect since it doesn't solve my
> problem, but it might give an idea of how I'm thinking) looks like this
> (I've tried to implement the timers like in the examples on this page,
> if that might be any hint to what may be wrong:
> http://www.ling.gu.se/~lager/Labs/SCXML-Lab/ ):
>
> <scxml version="1.0" initialstate="167" xmlns:cs="
> http://commons.apache.org/scxml" xmlns="
> http://www.w3.org/2005/07/scxml">
> <state id = "167">
> <transition target="StateA"/>
> </state>
> <state id ="StateA">
> <onentry>
> <send sendid="1" target="'StateA'" event="'ToB'" delay="'1000ms'" />
> </onentry>
> <transition event="ToB" target="StateB"/>
> </state>
> <state id="StateB">
> <onentry>
> <send sendid="2" target="'StateB'" event="'ToA'" delay="'2000ms'" />
> </onentry>
> <transition event="ToA" target="StateA"/>
> </state>
> </scxml>
>
> I get complaints about my target and event parts. What I want is that
> when you enter a state, a timer with the value of the delay attribute
> should start ticking inside the current state and when the timer times
> out, it should take the transition with the same event as the event in
> the send tag. But when I do this, I get this warning:
> VARNING: <send>: target expression "StateA" evaluated to null or empty
> String
> (I tried to write target="'Self'" instead, too, but that didn't help
> either)
>
<snip/>

Targets cannot be states, only entire state machines. "Self" has no
associated semantics at all in SCXML.


> I also tried to remove the target attribute, but then I get this line:
<snap/>

Thats the right way to proceed. No target means current state machine.


> INFO: send ( sendId: 1, target: null, targetType: scxml, event: ToB,
> params: null, hints: null, delay: 1000)
> and nothing else happens.
>
> If anyone has any ideas of what I might have done wrong and how I can
> solve this problem (preferably without implementing any custom actions),
> I would be really happy!
>
<snip/>

Use an EventDispatcher that supports timers. Here is one that uses
Java SE timers:

  http://commons.apache.org/scxml/apidocs/org/apache/commons/scxml/env/SimpleScheduler.html

So, along these lines:

    SCXMLExecutor exec = new SCXMLExecutor();
    ...
    exec.setEventDispatcher(new SimpleScheduler(exec));
    ...

-Rahul


> Sincerely,
> Anna
>
>

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