You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Ouyang, Landon - ES/RDR -Gil" <La...@itt.com> on 2008/04/14 19:24:10 UTC

[SCXML] State transitions from within handler

Rahul,

Thanks for your help, I was able to implement the state transition
method you had described earlier.

The reason for this investigation is that we intend to use the Commons
SCXML engine to implement highly complex systems by separating all the
"pieces" into atomic modules (states). However, we would like the
decision making for the transitions to be done within the application
code (state handlers) and not the state machine implementation (XML). We
foresee problems if the XML document must specifically reference the
attributes needed to decide which transitions occur (ie 'result.value'
in our earlier example).

The only way I can think around this problem is to create a custom
transition/event stack in which the next event gets pushed during the
state handler and popped once we are officially in the current state
(since the previous state is still being processed while we are in the
handler).

Is there a better way around this issue? If not, where in
AbstractStateMachine will I know for a fact that the previous state's
processing has been completed?

Thanks once again,
Landon Ouyang
Member Technical Staff
ITT Electronics Systems, Radar Systems - Gilfillan
7821 Orion Ave,
Van Nuys, CA 91406
(818) 901-2982


-----Original Message-----
From: Ouyang, Landon - ES/RDR -Gil [mailto:Landon.Ouyang@itt.com]
Sent: Monday, April 14, 2008 9:31 AM
To: Jakarta Commons Users List
Subject: RE: [SCXML] W3C specs compatibility and state transition issues

Hi Rahul,

My (limited) understand of JavaBeans is that a JavaBean object must
implement java.io.Serializable, has a public no argument constructor,
and contains set/get methods for properties. So I setup my result class
as follows:

    class result implements Serializable
        {
        public result() {}
        private int value;
        public int getValue()
            { return value; }
        public void setValue(int nNum)
            { value = nNum; }
        }

However, the state transition still does not work!

FYI, I was able to prove that the object is sent to the engine correctly
using:

result newResult = (result)getEngine().getRootContext().get("result");

But for some reason, I cannot retrieve/use "result.value" in my XML
file!

Any ideas what I'm missing here? Thanks for the help.

--
Landon Ouyang
Member Technical Staff
ITT Electronics Systems, Radar Systems - Gilfillan
7821 Orion Ave,
Van Nuys, CA 91406
(818) 901-2982

-----Original Message-----
From: Rahul Akolkar [mailto:rahul.akolkar@gmail.com]
Sent: Friday, April 11, 2008 6:56 PM
To: Jakarta Commons Users List
Subject: Re: [SCXML] W3C specs compatibility and state transition issues

On Fri, Apr 11, 2008 at 7:15 PM, Ouyang, Landon - ES/RDR -Gil
<La...@itt.com> wrote:
> Hmmm....
>
> Given your snippet, I assumed this would work:
>
> result aResult = new result();
>
> if(bIsTest)
>   aResult.value = 1;
> else
>   aResult.value = 0;
>
> getEngine().getRootContext().set("result", aResult);
>
> where the XML transition is conditional on "result.value eq 1". Why
> doesn't it work?
>
<snip/>

Try adding getter and setter methods, as I suggest below (for property
"value" in this example). Detailed discussion is in the JavaBeans
spec, which forms the basis of bean property access in most ELs we
use.

-Rahul


> --
> Landon Ouyang
> Member Technical Staff
> ITT Electronics Systems, Radar Systems - Gilfillan
> 7821 Orion Ave,
> Van Nuys, CA 91406
> (818) 901-2982
>
>
> -----Original Message-----
> From: Rahul Akolkar [mailto:rahul.akolkar@gmail.com]
>
> Sent: Friday, April 11, 2008 2:18 PM
> To: Jakarta Commons Users List
> Subject: Re: [SCXML] W3C specs compatibility and state transition
issues
>
> On Fri, Apr 11, 2008 at 5:01 PM, Ouyang, Landon - ES/RDR -Gil
> <La...@itt.com> wrote:
> > I figured out the solution:
> >
> > I needed to remove the event properties from the conditional
> > transitions. So if I change the state to:
> >
> > <state id="six">
> >        <datamodel>
> >                <data name="result">
> >                        <value>0</value>
> >                </data>
> >        </datamodel>
> >  <transition cond="result.value eq '1'" target="zero"/>
> >  <transition cond="result.value eq '0'" target="five"/>
> >  <transition target="three" event="display.prev"/>
> > </state>
> >
> > the code will work! Am I missing any other crucial details?
> >
> <snip/>
>
> Not really, but couple of comments:
>
>  * At a quick glance, I suspect you don't need the <datamodel>
> specified declaratively, so you can just remove the entire <datamodel>
> element (we are setting "result.value" via Java handlers). A brief
> discussion about datamodels is here:
>
>  http://commons.apache.org/scxml/guide/datamodel.html
>
>  * When I gave the example (below), I intended "fooresult.success" and
> "fooresult.numfailures" to be expressions of the flavor bean.property
> i.e. fooresult was an instance of:
>
> class FooResult {
>  get/setSuccess()
>  get/setNumfailures()
> }
>
> Generally better if you want to return a data structure, rather than
> multiple "flat variables" (your example is fine, for one value its
> much overhead).
>
> -Rahul
>

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


This e-mail and any files transmitted with it may be proprietary and are
intended solely for the use of the individual or entity to whom they are
addressed. If you have received this e-mail in error please notify the
sender. Please note that any views or opinions presented in this e-mail
are solely those of the author and do not necessarily represent those of
ITT Corporation. The recipient should check this e-mail and any
attachments for the presence of viruses. ITT accepts no liability for
any damage caused by any virus transmitted by this e-mail.

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


This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.

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


Re: [SCXML] _eventdata not included in collection events ?

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/30/08, Tony Seebregts <to...@iveri.com> wrote:
> Ah, of course ... thanks Rahul !
>
>  This exposes a problem with the Javascript evaluator though. The
>  Javascript engine (both JDK and JSR223) isn't able to apply the []
>  operator to a HashMap because its a Java object rather than a Javascript
>  object (using _eventdatamap.get('event.name') works fine).
>
>  Will file a bug...
>
<snip/>

Makes sense, will comment on SCXML-71.

-Rahul


>  regards
>
>
>  Tony
>
>
>
>  >> Hi,
>  >>
>  >>  I'm trying to pass information from a class that extends Action via a
>  >>  TriggerEvent payload but in the SCXML script the _eventdata value for
>  >>  the associated event transition seems to be null.
>  >>
>  >>  Any ideas ?
>  >>
>  >>  The payload works fine if I call triggerEvent but not if I just add the
>  >>  event to the events Collection and I can't figure out why (for various
>  >>  reasons triggerEvent doesn't work in the scenario).
>  >>
>  > <snip/>
>  >
>  > Yup, you shouldn't use triggerEvent here.
>  >
>  > The way derived events are handled is to process all of them in a
>  > microstep. Since there may be more than one event, _eventdata is
>  > ambigous, and _eventdatamap['event.name'] should be used instead for
>  > derived events.
>  >
>  > For example, see the eventdata_* test case documents in the JUnit test
>  > suite ... few of them are here:
>  >
>  > http://svn.apache.org/repos/asf/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/
>  >
>  > -Rahul
>
>

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


Re: [SCXML] _eventdata not included in collection events ?

Posted by Tony Seebregts <to...@iveri.com>.
Ah, of course ... thanks Rahul !

This exposes a problem with the Javascript evaluator though. The
Javascript engine (both JDK and JSR223) isn't able to apply the []
operator to a HashMap because its a Java object rather than a Javascript
object (using _eventdatamap.get('event.name') works fine).

Will file a bug...

regards

Tony


>> Hi,
>>
>>  I'm trying to pass information from a class that extends Action via a
>>  TriggerEvent payload but in the SCXML script the _eventdata value for
>>  the associated event transition seems to be null.
>>
>>  Any ideas ?
>>
>>  The payload works fine if I call triggerEvent but not if I just add the
>>  event to the events Collection and I can't figure out why (for various
>>  reasons triggerEvent doesn't work in the scenario).
>>
> <snip/>
> 
> Yup, you shouldn't use triggerEvent here.
> 
> The way derived events are handled is to process all of them in a
> microstep. Since there may be more than one event, _eventdata is
> ambigous, and _eventdatamap['event.name'] should be used instead for
> derived events.
> 
> For example, see the eventdata_* test case documents in the JUnit test
> suite ... few of them are here:
> 
> http://svn.apache.org/repos/asf/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/
> 
> -Rahul


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


Re: [SCXML] _eventdata not included in collection events ?

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/29/08, Tony Seebregts <to...@iveri.com> wrote:
> Hi,
>
>  I'm trying to pass information from a class that extends Action via a
>  TriggerEvent payload but in the SCXML script the _eventdata value for
>  the associated event transition seems to be null.
>
>  Any ideas ?
>
>  The payload works fine if I call triggerEvent but not if I just add the
>  event to the events Collection and I can't figure out why (for various
>  reasons triggerEvent doesn't work in the scenario).
>
<snip/>

Yup, you shouldn't use triggerEvent here.

The way derived events are handled is to process all of them in a
microstep. Since there may be more than one event, _eventdata is
ambigous, and _eventdatamap['event.name'] should be used instead for
derived events.

For example, see the eventdata_* test case documents in the JUnit test
suite ... few of them are here:

http://svn.apache.org/repos/asf/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/

-Rahul


>  The relevant code is:
>
>  public void execute(EventDispatcher dispatcher,
>                     ErrorReporter   reporter,
>                     SCInstance      instance,
>                     Log             log,
>                     Collection      events) throws
>  ModelException,SCXMLExpressionException
>        { Evaluator evaluator = instance.getEvaluator();
>          Context   context   = instance.getContext  (getParentState());
>          String    uidx      = null;
>          String    pinx      = null;
>          int       serviceID;
>          User      user;
>
>          try
>             { if (uid != null)
>                  uidx = (String) evaluator.eval(context,uid);
>
>               if (pin != null)
>                  pinx = (String) evaluator.eval(context,pin);
>
>               if ((user = login(uidx,pinx)) == null)
>                  { events.add(INVALID);
>                    return;
>                  }
>
>               events.add(new  TriggerEvent("ok",
>  TriggerEvent.SIGNAL_EVENT, user));
>                        return;
>             }
>          catch(Throwable x)
>             { log.error("Error logging in: " + x.toString());
>             }
>
>          instance.getExecutor().triggerEvent(ERROR);
>        }
>
>  regards
>
>  Tony Seebregts
>

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


[SCXML] _eventdata not included in collection events ?

Posted by Tony Seebregts <to...@iveri.com>.
Hi,

I'm trying to pass information from a class that extends Action via a
TriggerEvent payload but in the SCXML script the _eventdata value for
the associated event transition seems to be null.

Any ideas ?

The payload works fine if I call triggerEvent but not if I just add the
event to the events Collection and I can't figure out why (for various
reasons triggerEvent doesn't work in the scenario).

The relevant code is:

public void execute(EventDispatcher dispatcher,
                    ErrorReporter   reporter,
                    SCInstance      instance,
                    Log             log,
                    Collection      events) throws
ModelException,SCXMLExpressionException
       { Evaluator evaluator = instance.getEvaluator();
         Context   context   = instance.getContext  (getParentState());
         String    uidx      = null;
         String    pinx      = null;
         int       serviceID;
         User      user;

         try
            { if (uid != null)
                 uidx = (String) evaluator.eval(context,uid);

              if (pin != null)
                 pinx = (String) evaluator.eval(context,pin);

              if ((user = login(uidx,pinx)) == null)
                 { events.add(INVALID);
                   return;
                 }

              events.add(new  TriggerEvent("ok",
TriggerEvent.SIGNAL_EVENT, user));
                       return;
            }
         catch(Throwable x)
            { log.error("Error logging in: " + x.toString());
            }

         instance.getExecutor().triggerEvent(ERROR);
       }

regards

Tony Seebregts

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


Re: [SCXML] Rational Software Architect

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/23/08, Ouyang, Landon - ES/RDR -Gil <La...@itt.com> wrote:
> Hello,
>
>  According to the website, the Rational Software Architect could be used
>  to generate the XML files that run with the Commons SCXML engine.
>  However, there appears to be syntactical differences between what is
>  generated from the software and what actually works on the engine.
>
>  The following XML was generated for composite states by the software:
>
>  <state id="Region1">
>         <initial id="zero">
>                 <transition event="display.next">
>                         <target next="one" />
>                 </transition>
>         </initial>
>
>  This does not work (both the transition and the initial state).
<snip/>

Sure, I can see why.


> It must
>  be changed to this to work:
>
>  <state id="Region1">
>     <initial>
>         <transition target="zero"/>
>     </initial>
>  <state id="zero">
>     <transition event="display.next" target="one" />
>  </state>
>
>  Can you explain this discrepancy because I assumed that the Software
>  Architect adhered to the proper SCXML standards? Were there any settings
>  changes that you made to the software to generate the syntax-correct
>  files?
>
<snap/>

The plugin (note that its a prototype, hence on alphaWorks) was
originally authored for a previous release of Commons SCXML (IIRC,
v0.5). At that point, the Working Draft did have a slightly different
vocabulary for specifying transition targets (as evidenced above). I
don't think the plugin has been updated to work with v0.7. That
explains one part of the above discrepancy. I'm not sure about the
other error in generation (the transition for 'display.next'). Perhaps
you can try asking on the forum provided on alphaWorks, since you may
get a better answer there.

-Rahul


>  Thanks,
>  Landon
>
>

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


[SCXML] Rational Software Architect

Posted by "Ouyang, Landon - ES/RDR -Gil" <La...@itt.com>.
Hello,

According to the website, the Rational Software Architect could be used
to generate the XML files that run with the Commons SCXML engine.
However, there appears to be syntactical differences between what is
generated from the software and what actually works on the engine.

The following XML was generated for composite states by the software:

<state id="Region1">
        <initial id="zero">
                <transition event="display.next">
                        <target next="one" />
                </transition>
        </initial>

This does not work (both the transition and the initial state). It must
be changed to this to work:

<state id="Region1">
    <initial>
        <transition target="zero"/>
    </initial>
<state id="zero">
    <transition event="display.next" target="one" />
</state>

Can you explain this discrepancy because I assumed that the Software
Architect adhered to the proper SCXML standards? Were there any settings
changes that you made to the software to generate the syntax-correct
files?

Thanks,
Landon





--
Landon Ouyang
Member Technical Staff
ITT Electronics Systems, Radar Systems - Gilfillan
7821 Orion Ave,
Van Nuys, CA 91406
(818) 901-2982

This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.

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


Re: [SCXML] State transitions from within handler

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/17/08, Ouyang, Landon - ES/RDR -Gil <La...@itt.com> wrote:
> Hi Rahul,
>
>  Thanks for your informative response.
>
>  Using your suggestions I created my own state machine class that did not
>  utilize a listener. I overwrote the Initialize() and fireEvent()
>  routines to invoke the state methods and utilize an event stack to
>  process external events.
>
>  The only issue with my implementation is that an event must be fired for
>  a state method to be invoked. For example, if we make state 4
>  automatically (unconditionally) transition to state 5 in the SCXML file,
>  state5() will not be called. It will only be called if we fire an event
>  in state 4 to transition to state 5.
>
>  Is there a place where I can call invoke() in the state machine
>  implementation (without a listener) so that the state handler is called
>  on a transition regardless of whether an event was fired or not?
>
<snip/>

You could register a listener simply to track the progress, especially
when eventless transitions are involved as you describe (and refer to
this list to invoke state "handlers" in order). Alternatively, you
could guard the previously eventless transitions with a special event
(some event name TBD) that you fire at the end of the preceeding state
handler.

-Rahul



>
>  --
>  Landon Ouyang
>  Member Technical Staff
>  ITT Electronics Systems, Radar Systems - Gilfillan
>  7821 Orion Ave,
>  Van Nuys, CA 91406
>  (818) 901-2982
>
>  -----Original Message-----
>  From: Rahul Akolkar [mailto:rahul.akolkar@gmail.com]
>
> Sent: Monday, April 14, 2008 12:19 PM
>  To: Jakarta Commons Users List
>
> Subject: Re: [SCXML] State transitions from within handler
>
>  On 4/14/08, Ouyang, Landon - ES/RDR -Gil <La...@itt.com> wrote:
>  > Rahul,
>  >
>  >  Thanks for your help, I was able to implement the state transition
>  >  method you had described earlier.
>  >
>  >  The reason for this investigation is that we intend to use the
>  Commons
>  >  SCXML engine to implement highly complex systems by separating all
>  the
>  >  "pieces" into atomic modules (states).
>  <snip/>
>
>  Makes sense, for very simple systems [scxml] may even be overkill.
>
>
>  >  However, we would like the
>  >  decision making for the transitions to be done within the application
>  >  code (state handlers) and not the state machine implementation (XML).
>  We
>  >  foresee problems if the XML document must specifically reference the
>  >  attributes needed to decide which transitions occur (ie
>  'result.value'
>  >  in our earlier example).
>  >
>  <snap/>
>
>  OK, though I don't necessarily agree. Couple of points:
>
>   * IMO, in highly complex systems the declarative vocabulary (be it
>  XML or otherwise) can be thought of as merely a serialization of some
>  model (such as the domain UML2 state charts) which the developer(s)
>  maintain.
>
>   * The [scxml] library can be the basis of building components that
>  serve to wrapper certain conventions in place over the state machine
>  implementation -- conventions that mitigate problems in having to
>  "specifically reference the attributes needed". The
>  AbstractStateMachine is one such simple example (uses a convention to
>  call "state handlers"). However, it has drawbacks (such as invoking
>  handlers synchronously while processing events) and is not fit for
>  complex systems.
>
>
>  >  The only way I can think around this problem is to create a custom
>  >  transition/event stack in which the next event gets pushed during the
>  >  state handler and popped once we are officially in the current state
>  >  (since the previous state is still being processed while we are in
>  the
>  >  handler).
>  >
>  <snip/>
>
>  May not be necessary. The following suggested replacements is how I
>  have understood the sentences in the above paragraph:
>
>  s/officially in a state/at rest in a state/
>  s/previous state is being processed/previous event is being processed/
>
>
>  >  Is there a better way around this issue? If not, where in
>  >  AbstractStateMachine will I know for a fact that the previous state's
>  >  processing has been completed?
>  >
>  <snap/>
>
>  See this page:
>
>   http://commons.apache.org/scxml/guide/using-commons-scxml.html
>
>  The AbstractStateMachine uses the second pattern. One of the ways to
>  achieve what you want is using the first pattern, "Mapping states to
>  activities" (current state --> state handler).
>
>  Create a variant that bootstraps similar to the AbstractStateMachine
>  class, waits for state machine to come to rest (initially, and when
>  any subsequent event is triggered on it), looks up current state
>  (rather than registering a listener that gets called synchronously),
>  and calls the corresponding state handler. Maintain a queue for
>  external events, have state handlers add to that queue, trigger events
>  in order while queue not empty. Adjustments necessary per taste etc.
>  :-)
>
>  -Rahul
>

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


RE: [SCXML] State transitions from within handler

Posted by "Ouyang, Landon - ES/RDR -Gil" <La...@itt.com>.
Hi Rahul,

Thanks for your informative response.

Using your suggestions I created my own state machine class that did not
utilize a listener. I overwrote the Initialize() and fireEvent()
routines to invoke the state methods and utilize an event stack to
process external events.

The only issue with my implementation is that an event must be fired for
a state method to be invoked. For example, if we make state 4
automatically (unconditionally) transition to state 5 in the SCXML file,
state5() will not be called. It will only be called if we fire an event
in state 4 to transition to state 5.

Is there a place where I can call invoke() in the state machine
implementation (without a listener) so that the state handler is called
on a transition regardless of whether an event was fired or not?

--
Landon Ouyang
Member Technical Staff
ITT Electronics Systems, Radar Systems - Gilfillan
7821 Orion Ave,
Van Nuys, CA 91406
(818) 901-2982

-----Original Message-----
From: Rahul Akolkar [mailto:rahul.akolkar@gmail.com]
Sent: Monday, April 14, 2008 12:19 PM
To: Jakarta Commons Users List
Subject: Re: [SCXML] State transitions from within handler

On 4/14/08, Ouyang, Landon - ES/RDR -Gil <La...@itt.com> wrote:
> Rahul,
>
>  Thanks for your help, I was able to implement the state transition
>  method you had described earlier.
>
>  The reason for this investigation is that we intend to use the
Commons
>  SCXML engine to implement highly complex systems by separating all
the
>  "pieces" into atomic modules (states).
<snip/>

Makes sense, for very simple systems [scxml] may even be overkill.


>  However, we would like the
>  decision making for the transitions to be done within the application
>  code (state handlers) and not the state machine implementation (XML).
We
>  foresee problems if the XML document must specifically reference the
>  attributes needed to decide which transitions occur (ie
'result.value'
>  in our earlier example).
>
<snap/>

OK, though I don't necessarily agree. Couple of points:

 * IMO, in highly complex systems the declarative vocabulary (be it
XML or otherwise) can be thought of as merely a serialization of some
model (such as the domain UML2 state charts) which the developer(s)
maintain.

 * The [scxml] library can be the basis of building components that
serve to wrapper certain conventions in place over the state machine
implementation -- conventions that mitigate problems in having to
"specifically reference the attributes needed". The
AbstractStateMachine is one such simple example (uses a convention to
call "state handlers"). However, it has drawbacks (such as invoking
handlers synchronously while processing events) and is not fit for
complex systems.


>  The only way I can think around this problem is to create a custom
>  transition/event stack in which the next event gets pushed during the
>  state handler and popped once we are officially in the current state
>  (since the previous state is still being processed while we are in
the
>  handler).
>
<snip/>

May not be necessary. The following suggested replacements is how I
have understood the sentences in the above paragraph:

s/officially in a state/at rest in a state/
s/previous state is being processed/previous event is being processed/


>  Is there a better way around this issue? If not, where in
>  AbstractStateMachine will I know for a fact that the previous state's
>  processing has been completed?
>
<snap/>

See this page:

  http://commons.apache.org/scxml/guide/using-commons-scxml.html

The AbstractStateMachine uses the second pattern. One of the ways to
achieve what you want is using the first pattern, "Mapping states to
activities" (current state --> state handler).

Create a variant that bootstraps similar to the AbstractStateMachine
class, waits for state machine to come to rest (initially, and when
any subsequent event is triggered on it), looks up current state
(rather than registering a listener that gets called synchronously),
and calls the corresponding state handler. Maintain a queue for
external events, have state handlers add to that queue, trigger events
in order while queue not empty. Adjustments necessary per taste etc.
:-)

-Rahul

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


This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.

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


Re: [SCXML] State transitions from within handler

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/14/08, Ouyang, Landon - ES/RDR -Gil <La...@itt.com> wrote:
> Rahul,
>
>  Thanks for your help, I was able to implement the state transition
>  method you had described earlier.
>
>  The reason for this investigation is that we intend to use the Commons
>  SCXML engine to implement highly complex systems by separating all the
>  "pieces" into atomic modules (states).
<snip/>

Makes sense, for very simple systems [scxml] may even be overkill.


>  However, we would like the
>  decision making for the transitions to be done within the application
>  code (state handlers) and not the state machine implementation (XML). We
>  foresee problems if the XML document must specifically reference the
>  attributes needed to decide which transitions occur (ie 'result.value'
>  in our earlier example).
>
<snap/>

OK, though I don't necessarily agree. Couple of points:

 * IMO, in highly complex systems the declarative vocabulary (be it
XML or otherwise) can be thought of as merely a serialization of some
model (such as the domain UML2 state charts) which the developer(s)
maintain.

 * The [scxml] library can be the basis of building components that
serve to wrapper certain conventions in place over the state machine
implementation -- conventions that mitigate problems in having to
"specifically reference the attributes needed". The
AbstractStateMachine is one such simple example (uses a convention to
call "state handlers"). However, it has drawbacks (such as invoking
handlers synchronously while processing events) and is not fit for
complex systems.


>  The only way I can think around this problem is to create a custom
>  transition/event stack in which the next event gets pushed during the
>  state handler and popped once we are officially in the current state
>  (since the previous state is still being processed while we are in the
>  handler).
>
<snip/>

May not be necessary. The following suggested replacements is how I
have understood the sentences in the above paragraph:

s/officially in a state/at rest in a state/
s/previous state is being processed/previous event is being processed/


>  Is there a better way around this issue? If not, where in
>  AbstractStateMachine will I know for a fact that the previous state's
>  processing has been completed?
>
<snap/>

See this page:

  http://commons.apache.org/scxml/guide/using-commons-scxml.html

The AbstractStateMachine uses the second pattern. One of the ways to
achieve what you want is using the first pattern, "Mapping states to
activities" (current state --> state handler).

Create a variant that bootstraps similar to the AbstractStateMachine
class, waits for state machine to come to rest (initially, and when
any subsequent event is triggered on it), looks up current state
(rather than registering a listener that gets called synchronously),
and calls the corresponding state handler. Maintain a queue for
external events, have state handlers add to that queue, trigger events
in order while queue not empty. Adjustments necessary per taste etc.
:-)

-Rahul

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