You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Rahul Akolkar <ra...@gmail.com> on 2006/03/31 00:03:34 UTC

[SCXML] Commons Chain custom action (was: SCXMLListener Exception Handling Question)

On 3/29/06, Brule, Jon <Jo...@xerox.com> wrote:
> Rahul,
>
> Thank you very much for this excellent write-up contrasting listeners
> and custom actions!
>
> I think that I will move my efforts away from the SCXMLListener and
> toward the custom action as a way to kick-off my state-specific code.
> Incidentally, my intention is to have the custom action fire off a named
> chain using the Jakarta Commons Chain (Chain of Responsibility pattern)
> component. This way I can easily assemble / adjust the "actions" a
> particular state transition takes. It also allows me to draw from a set
> of existing common chain commands I have already written.
>
> Do you know if anyone has attempted this integration between the
> Commons/SCXML and the Commons/Chain components? If not, any thoughts or
> comments about doing it through the custom action interface?
>
<snip/>

Nice idea, the CoR pattern is useful on many occassions and having
existing code is ofcourse a big plus. I'm not aware of anyone who has
written such an action, but regardless, it should be fairly
straightforward.

In the simplest form, a custom "chain" action impl would merely
require accessible (public) getter/setters for the attributes on the
action element, and action's execute() method would lookup the chain /
command and delegate to its execute() method.

i.e. (being an action, must be inside an <onentry>, <transition> or <onexit>):

<my:chain config="/path/url" catalog="foo"
          command="bar" />

Some observations:
 * Those not using XML configurations can skip the config attribute,
there should be a way to initialize the custom action with existing
commands/chains/filters
 * Probably need to maintain a catalog factory
 * If no catalog is provided, the default one is used (think this is
done by chain itself)
 * Command must be provided
 * Exceptions thrown by the command's execution can map to a generic
"err.action.chain" (or some such) derived event
 * Possibly also define one event for successful command execution,
say "done.action.chain"

To sketch that out:

<state id="foo">
 <onentry>
  <!-- other stuff onentry -->
  <my:chain command="dofoo" />
 </onentry>
 <transition event="err.action.chain" target="errorstate" />
 <transition event="done.action.chain" cond="outcome eq 'bar1'"
             target="somestate" />
 <transition event="done.action.chain" cond="outcome eq 'bar2'"
             target="otherstate" />
 <!-- Other content for state foo -->
</state>

There can be multiple ways to do this, please don't let this example
constrain you. At some point, the addition of a
org.apache.commons.scxml.env.chain package to the Commons SCXML API
[1], which at the minimum contains a Chain Context impl which wraps a
SCXML Context and a suitable custom action seems justified. If you end
up writing it and are inclined to contribute it back, I'm sure it'd be
useful to others as well.

Interesting stuff.

-Rahul

[1] http://jakarta.apache.org/commons/sandbox/scxml/apidocs/index.html


> Thanks again.
>
> Regards,
> Jon Brule
>
<snap/>

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