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] Question save/restore state of FSM
Date Tue, 01 Jul 2008 03:46:31 GMT
On 6/30/08, Daniel Schwager <Daniel.Schwager@dtnet.de> wrote:
> Hi Rahul,
>
>  i'm testing/learning/playing around SCXML for about 2 days now. First
>  of all - great work of this java port (-:
>
>  There are two questions i can't find an answer to:
>
>  a) Could I realize a transition guarded with a condition checking
>    a substate of a parallel state ?
>         <parallel>
>                 <state 1>
>                         <state11/>
>                         <state12/>
>                         <state13/>
>                 </state1>
>                 <state2>
>                         <transition event="a" target="state2"
>  cond="statemachine is in state state1.state12"/>
>                 <state2/>
>         <parallel/>
>
<snip/>

Use the In() predicate like so:

... cond="In('state12')" ...




>
>  B) i would like to save/restore my FSM (using the SCXML in
>  EJB3-container with session beans)
>  Therefore I look around (found also SCXML-19 ..). I realized another
>  way, but this one
>  does not work correctly - there's a problem restoring the state ...
>  maybe you can help me ?
>
>
>  --------------------------------------------------------------------
>
>  //Each trigger instances a new Executor, load the old context to it and
>  fire the event:
>
>  Public void myOwnTrigger(Object sm, Trigger evt) {
>                         // Object sm is persistent (loadding before
>  calling myOwnTrigger() ans saveing after calling ..)
>
<snap/>

In order of preference:

1) Persist the SCXMLExecutor instance below, instead of merely the root context.

2) Correctly set the states collection of the current executor status
[ exec.getCurrentStatus().getStates() ] along with its root context

-Rahul


>                         SCXMLExecutor exec = new SCXMLExecutor();
>                         exec.setStateMachine(static-scxml-strng);
>                         exec.setRootContext(sm.getRootContext);
>  // !! I use a "persistente" root context
>                         exec.setEvaluator(new evaluator);
>                         exec.setErrorReporter(new errReporter);
>                         exec.setEventdispatcher(new
>  StateMachineEventDispatcher(sm));
>
>  // After this, i only added the Listeners immediately, if the FSM never
>  runs before
>                         if (!sm.isInitialized()) {
>                                 // First time - invoke Listener also
>                                 exec.addListener(scxml, new
>  SimpleSCXMLListener());
>                                 exec.addListener(scxml, new
>  StateMachineEntryListener(sm));
>                                 sm.setInitialized(true);
>                                 exec.go();
>
>  // Else, I installed the listeners AFTER exec.go() to prevent to
>  re-invocations of business method's still done
>                         } else {
>                                 // still initialized - involke listener
>  after FSM is initialized
>                                 // (going through all states ..)
>                                 exec.go();
>                                 exec.addListener(scxml, new
>  SimpleSCXMLListener());
>                                 exec.addListener(scxml, new
>  StateMachineEntryListener(sm));
>                         }
>
>  // Finally, trigger the event
>                         exec.trigger(evt)
>                         return;
>
>  --------------------------------------------------------------------
>
>  But if i fire _TWO_ "watch.start" to the model
>         <state id="stopwatch">
>                 <initial>
>                         <transition target="reset" />
>                 </initial>
>
>                 <state id="reset" final="true">
>                         <onentry/>
>                         <transition event="watch.start" target="running"
>  />
>                 </state>
>
>                 <state id="running">
>                         <onentry/>
>                 </state>
>         </state>
>
>
>  my solution results in
>         ****************** FIRE EVENT 1
>         I'm in stopwatch
>         I'm reset
>         I'm running
>         INFO: State(reset) State(stopwatch)
>         ****************** FIRE EVENT 2
>         I'm running
>         INFO: State(reset) State(stopwatch)
>
>  The correct solution (with the normal way using exec.go() and 2 x
>  exec.trigger(evt) results in
>         I'm in stopwatch
>         I'm reset
>         I'm running
>         INFO: State(stopwatch) State(running)
>
>  --> My solution enters the "running" state twice, because the state does
>  not
>     change from reset->running.... (printed after a new instance of
>  exec, after exec.go() loaded with the "persistent" context)
>
>     Why ? Is there more to save beside of exec.getRootContext() ???
>
>  Best regards
>  Danny
>
>
>
>
>  ---------------------------------------------------------------------
>  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


Mime
View raw message