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] Timers in SCXML
Date Wed, 08 Apr 2009 20:19:17 GMT
On Wed, Apr 8, 2009 at 7:53 AM, Anna Södling <anna.sodling@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


Mime
View raw message