You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Fasih <fa...@baypackets.com> on 2006/04/03 00:43:04 UTC

[SCXML] Same event to multiple parallel states

Hi
I have a state m/c with multiple parallel states. A transition might 
result in one/all of the parallel state machines on a particular event. 
How do I accomplish this?
This might sound wierd, but let me elucidate my problem:

<state id="ua-ready">
    <parallel id="lines">
       <state id="line1">
          <transition event="connection.alerting" target="accept"/>
        </state>
       <state id="line2">
          <transition event="connection.alerting" target="reject"/>
        </state>
    </parallel>
</state>

Basically what I want to do is, for the different lines simulate a 
different behaviour depending on the line. There might be a better way 
to do this, I am new to this state machine concept. One alternative I 
thought of was to have events like line1.connection.alerting but that 
did not sound like a good idea, I also thought of having some indicator 
in the event as to which line it is meant for, but that does not sound 
too good either.

Any help would be appreciated.

+Fasih


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


Re: [SCXML] Same event to multiple parallel states

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/3/06, Rahul Akolkar <ra...@gmail.com> wrote:
> On 4/2/06, Fasih <fa...@baypackets.com> wrote:
<snip/>
>
> The latest SCXML WD also specifies that the special variable
> "_eventdata" may be used to access data contained within the
> triggering event (i.e. the payload). Thus, along the lines of the
> above example, a transition may look like:
>
> <transition event="connection.alerting"
>                cond="_eventdata.line eq 1"
>                target="..." />
>
> where the event payload defines a "line" property. This bit (exposing
> payload as "_eventdata") hasn't been done for Commons SCXML yet, but
> I'll do it now. Will ping this thread when am done.
>
<snap/>

Ping, "_eventdata" should be available in 20060404 nightlies here [1].

Here [2] is a sample based on your snippet, also illustrates using a
user-defined payload ("_eventdata.line" in the expressions under
state2 refers to line property of user-defined payload type [3]).

-Rahul

(long, possibly fragmented, URLs below)

[1] http://cvs.apache.org/builds/jakarta-commons/nightly/commons-scxml/
[2] http://svn.apache.org/viewcvs.cgi/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-02.xml?view=markup
[3] http://svn.apache.org/viewcvs.cgi/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java?view=markup
(see ConnectionAlertingPayload type towards end of file)

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


Re: [SCXML] Same event to multiple parallel states

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/2/06, Fasih <fa...@baypackets.com> wrote:
> Hi
> I have a state m/c with multiple parallel states. A transition might
> result in one/all of the parallel state machines on a particular event.
> How do I accomplish this?
> This might sound wierd, but let me elucidate my problem:
>
> <state id="ua-ready">
>    <parallel id="lines">
>       <state id="line1">
>          <transition event="connection.alerting" target="accept"/>
>        </state>
>       <state id="line2">
>          <transition event="connection.alerting" target="reject"/>
>        </state>
>    </parallel>
> </state>
>
> Basically what I want to do is, for the different lines simulate a
> different behaviour depending on the line. There might be a better way
> to do this, I am new to this state machine concept. One alternative I
> thought of was to have events like line1.connection.alerting but that
> did not sound like a good idea, I also thought of having some indicator
> in the event as to which line it is meant for, but that does not sound
> too good either.
<snip/>

I wouldn't recommend the first option either. But the second option is
actually widely used, and the concept is refered to as event payload.

If you take a look at the TriggerEvent class [1] in Commons SCXML, you
will indeed find a property "payload" that should be used for such
purposes. Ofcourse, what the payload consists of depends on the
particular environment and event semantics, therefore, the only
acceptable type for payload is java.lang.Object (i.e. you can assign
an object of any type, even a user-defined one, as the event payload).

The latest SCXML WD also specifies that the special variable
"_eventdata" may be used to access data contained within the
triggering event (i.e. the payload). Thus, along the lines of the
above example, a transition may look like:

<transition event="connection.alerting"
                cond="_eventdata.line eq 1"
                target="..." />

where the event payload defines a "line" property. This bit (exposing
payload as "_eventdata") hasn't been done for Commons SCXML yet, but
I'll do it now. Will ping this thread when am done.

There has been no mention of <parallel> yet, since the way you refer
to event payload does not depend on parallelism. The parallelism
construct implies the following basic premise (<state> children of
<parallel> are refered to as "regions"):

 * The state machine is "active" in all regions of a parallel, or none at all

That implies corollaries such as:

 * If a region transitions outside the parallel, all regions are exited
 * A region may not transition into another
 * Usage of the "In()" predicate is common to check the status of
sibling regions

Parallelism is a powerful construct for state machines, which also
requires due diligence from an authoring perspective.

For your snippet above, if state "accept" lies outside the parallel,
then following that transition will not only exit region "line1", but
also its sibling region "line2". That might as well be the desired
outcome, I'm simply using the snippet as an example.

-Rahul

[1] http://jakarta.apache.org/commons/sandbox/scxml/xref/org/apache/commons/scxml/TriggerEvent.html



>
> Any help would be appreciated.
>
> +Fasih
>
>

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