commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rahul Akolkar" <>
Subject [SCXML] Commons Chain custom action (was: SCXMLListener Exception Handling Question)
Date Thu, 30 Mar 2006 22:03:34 GMT
On 3/29/06, Brule, Jon <> 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?

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

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
 * 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">
  <!-- other stuff onentry -->
  <my:chain command="dofoo" />
 <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 -->

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.



> Thanks again.
> Regards,
> Jon Brule

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message