commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Renaud, Martin" <Martin.Ren...@nuance.com>
Subject RE: SCXML: "external" vs. "internal" events
Date Thu, 06 Aug 2009 17:58:05 GMT
Thanks Rahul for the answers.

I did implements an "internal" event queue managed by a sub-class of AbstractMachine (but
a super-class of my actual business sm.).  It works well and I'm happy to see there is demand
for it. It is not very complex to do... at least for a POC!

I also use the "super state" trick successfully to trap and log irrelevant events being triggered.
It will help catch bug in application code.

In the process of doing this, I ran in a little issue, probably something the could be improved
in the next version (I fixed it in my base sm implementation): the event handler methods invoked
dynamically when entering a new state are required to be defined in the "leaf" implementation
of the sm. It makes sense for "business" state, but it could be convenient to defined "system"
state handlers in super class. It is the case for me "superstate" and "invalid_transition"
state added to handle invalid transition. Using "MethodUtils.getAccessibleMethod(...)" do
the trick perfectly (are there is already a dependency on beanutils). Let me know if it is
useful to make that suggestion in a more formal way.

Now... I have more questions...

1) Arguments to state handlers
In AbstractStateMachine code, I see private variables named SIGNATURE and PARAMETERS that
seems to be there to provide some arguments when calling the event handler methods. But they
are not used actually. Is there any plan (or way) to enable this features (having some object
being supplied to handlers) ?

2) Create a sm instance in set the current state.
We would like to be able to "save" the state of a sm and recreate it later in time, probable
on another machine, and continue where we were. But we do not want to persist the whole thing;
just the current state should suffice. In the spec, I saw the history state serve this purpose
to some extends, but can it be done for all the states without adding the <history />
tag everywhere in the sm definition?


That's it for now, thanks again for your support.

-Martin

 
-----Original Message-----
From: Rahul Akolkar [mailto:rahul.akolkar@gmail.com] 
Sent: Thursday, August 06, 2009 12:19 AM
To: Commons Users List
Subject: Re: SCXML: "external" vs. "internal" events

On Wed, Aug 5, 2009 at 5:41 PM, Renaud, Martin<Martin.Renaud@nuance.com> wrote:
> Hi (again...)
>
>
>
> In the examples/usecases provided on the scxml site, the events are
> fired from outside the state machine. I called them "external" events.
>
>
> Is it valid to trigger events from inside my state machine sub-class, in
> a state handler method?  As I understand it, those events should be
> queued after any pending events (if any). However, it seems that those
> "internal" events are not processed.
>
<snip/>

Actually, there are well-defined semantics for the phrases external
and internal WRT events when it comes to SCXML.

I think you're saying events are being triggered via state handlers
(which is Java code) while the existing event is being processed. In
the latest release of Commons SCXML (v0.9), the executor does not
maintain an external event queue. As application code, you'd have to
maintain an event queue and add events from the handlers to said
queue, and trigger these on the executor while the queue has elements.
There is an open ticket to add such a queue to the executor
implementation for the next release (no planned date yet).

If you want to consider triggering events using SCXML markup, you can
consider using the <send> element. For example, see this test case in
v0.9 (long URL, may get fragmented in email):

  http://svn.apache.org/repos/asf/commons/proper/scxml/tags/SCXML_0_9/src/test/java/org/apache/commons/scxml/send-02.xml



>
> Side question, if an event if fired but it is not
> relevant/applicable/configured for the machine current state, is there a
> way to have an exception to be thrown?
>
<snap/>

Strictly speaking, this is not an interesting case in state machine
theory (it simply gets ignored as no transitions take place), but I do
agree it may be useful information for certain applications. Theres
atleast a couple of ways to deal with this:

 * Add a wildcard transition at a common ancestor state like so:

 <scxml ... initial="main">
    <state id="main">
       <transition event="*">
          <!-- log as illustration, do whatever is needed here -->
          <log expr="Unmatched event"/>
       </transition>

       <!-- The rest of the original state machine -->

    </state>
 </scxml>

 * Register an SCXMLListener and check if any onTransition() callback
is received when an event is triggered.

-Rahul


>
>
> I can provide config + code to illustrate my point, but I'd like to be
> sure it suppose to work first.
>
>
> Thanks,
>
>
> Martin
>
>

---------------------------------------------------------------------
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