commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Akolkar <rahul.akol...@gmail.com>
Subject Re: [scxml] call external actions
Date Wed, 12 May 2010 22:24:59 GMT
On Wed, May 12, 2010 at 4:54 PM, Fabrizio Morbini <fmorbini@gmail.com> wrote:
> Hi, i need to associate some executable action to each scxml state.
> These executable actions need to access objects available at the
> moment the scxml executor is started.
> I looked at the following options:
> 1) event (btw, i haven't found this in the scxml standard, why is it
> in Apache commons scxml?),
<snip/>

We support <event> because at some point it was in the specification
(note that following link points to an old working draft):

  http://www.w3.org/TR/2008/WD-scxml-20080516/#event

We are generally backwards compatible across minor releases. The next
major release Commons SCXML v1.0 (whenever it happens, no concrete
date yet) will not support it, but we don't want to break existing
code in the v0.x line that may be using it.


> invoke, send and custom actions: i haven't
> found a way to access the executor using these methods.
<snap/>

While there isn't a provided API, it can be accomplished quite easily
since the associated communication channels (be it EventDispatcher or
Invoker or SCXMLListener) may be set on the SCXMLExecutor after its
instantiation and thereby, can store a handle to the associated
SCXMLExecutor. The Commons SCXML APIs are minimal in this regard.
Concretely, say you want <send> processing to have access to the
executor instance and thereby, its root context which stores data
(such that a reference to some socket). A pattern like the following
may be used:

  SCXMLExecutor exec = new SCXMLExecutor();
  // set state machine, set root context containing a reference to socket etc.

  EventDispatcher dispatcher = new MyEventDispatcher(exec);
  // store executor handle in MyEventDispatcher instance

  exec.setEventDispatcher(dispatcher);

Then, in MyEventDispatcher#onSend(...) you may retrieve the reference
to the socket (or whatever is needed) via the root context of the
executor.


> 2) through a listener (SCXMLListener): this works (in a way similar to
> the stopwatch example) but going this way i need to store a mapping
> between actions and scxml states in the code (i.e. for every scxml
> state, a corresponding java method is executed). So, in the listener,
> every time the onEntry method is called, i need to check if for that
> state there is an associated action and execute it.
>
<snip/>

Yes, would need checking.


> to give a concrete example, is there a good way to associate to each
> scxml state a method that sends some data (that is state specific)
> through a network socket that had been opened when the scxml executor
> was started?
>
> is going through the SCXMLListener the best/only option?
>
<snap/>

If you wanted to use the SCXMLListener, you could apply a pattern
similar to the one depicted above with the MyEventDispatcher to obtain
any data (state specific or not) from the root context.

But that is not your only option and in fact, using <send> may
actually be better since it captures the semantics in SCXML (rather
than some implied behavior like the stopwatch example has).

-Rahul


> thanks
>

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


Mime
View raw message