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] use the send action.
Date Wed, 05 May 2010 21:24:15 GMT
On Wed, May 5, 2010 at 2:23 AM, jocke eriksson <jocke29@gmail.com> wrote:
> namelist would be one option, this  is how it works now I create new
> dispatcher for every state machine and that dispatcher has a SCXMLExector
> field and a Context field so the context is available for every dispatcher.
> And when the dispatcher is called, the derived events are retrieved from the
> context.
>
> like this
>
<snip/>

Following code implies synchronous behavior, which may be OK depending
on your usecase (if the sender receives the event in relative quick
time and not many events other than said response event are expected
in that duration).

-Rahul


>
>
>  ScxmlEventDispatcher(SenderFactory senderFactory, Context ctx) {
>        this.factory = senderFactory;
>        this.context = ctx;
>    }
>
>    /**
>     * Set the executor.
>     *
>     * @param exe The executor.
>     */
>    void setExecutor(SCXMLExecutor exe) {
>        this.executor = exe;
>    }
>
>    @Override
>    public void cancel(String sendId) {
>        throw new UnsupportedOperationException("Not implemented");
>    }
>
>    @Override
>    @SuppressWarnings("unchecked")
>    public void send(String sendId,
>            String target,
>            String targetType,
>            String event,
>            Map params,
>            Object hints,
>            long delay,
>            List externalNodes) {
>
>        Sender sender = factory.getSender(targetType);
>
>        if (sender == null) {
>            LOG.error("Target type '{}' is not supported ", targetType);
>
>        } else {
>
>            sender.setExecutor(executor);
>            sender.setContext(context);
>            sender.send(sendId, target, params);
>
>        }
>
>
> and when sender has event it fires it like this
>
>    private void fireEvent(String event) {
>
>        @SuppressWarnings("unchecked")
>        Collection<TriggerEvent> collection = (Collection<TriggerEvent>)
>                context.get(SendAction.DERIVED_EVENTS);
>
>        if (collection == null) {
>            LOG.warn("You must use the Send in MS namespace to be "
>                    + "able to fire events with send");
>
>        } else {
>              collection.add(new TriggerEvent(event,
> TriggerEvent.SIGNAL_EVENT));
>        }
>
>    }
>
> 2010/5/5 Rahul Akolkar <rahul.akolkar@gmail.com>
>
>> On Tue, May 4, 2010 at 2:23 AM, jocke eriksson <jocke29@gmail.com> wrote:
>> > Ok here is the scenario, send html request to a server, fire event found
>> in
>> > a http response header. What is the recommended way of solving that using
>> > the send tag in scxml. This ugly solution is what i have now.
>> >
>> >
>> > public final class SendAction extends Send {
>> >
>> >    private static final long serialVersionUID = 1L;
>> >
>> >    @Override
>> >    public void execute(EventDispatcher evtDispatcher, ErrorReporter
>> errRep,
>> >            SCInstance scInstance, Log appLog, Collection derivedEvents)
>> >            throws ModelException, SCXMLExpressionException {
>> >        scInstance.getRootContext().set("derivedEvents", derivedEvents);
>> >        super.execute(evtDispatcher, errRep, scInstance, appLog,
>> > derivedEvents);
>> >    }
>> >
>> <snip/>
>>
>> If you're working with the v0.9 release, this may be your best bet.
>> However, before that -- how is the "derivedEvents" variable used? I
>> don't see it below (say, in the namelist would've been one option).
>>
>> -Rahul
>>
>>
>> > The state is this
>> >
>> >    <sc:state id="auth">
>> >
>> >        <sc:onentry>
>> >            <ms:send
>> >                namelist="uid pin action"
>> >                targettype="'basichttp'"
>> >                target="'
>> > http://localhost:8080/tms-web-1.3.3/ivr/mediaserver.action'" />
>> >        </sc:onentry>
>> >
>> >        <sc:transition event="auth.success" target="vm-play"  />
>> >
>> >        <sc:transition event="auth.fail" target="exit" >
>> >            <ms:playaudio value="sp + 'vm-fail_auth.wav'" />
>> >        </sc:transition>
>> >
>> >    </sc:state>
>> >
>> >
>> > But please give me an better option :). If possible without AsyncTrigger
>> >
>> >
>> > 2010/5/3 Rahul Akolkar <rahul.akolkar@gmail.com>
>> >
>> >> On Mon, May 3, 2010 at 9:12 AM, jocke eriksson <jocke29@gmail.com>
>> wrote:
>> >> > I have an application that uses many custom actions, but now I'm
>> trying
>> >> to
>> >> > use the dispatchers Send method.
>> >> > My problem is that when I use the executor to trigger events, the
>> machine
>> >> > ends up in an loop.
>> >> > How could one get a reference to the derived events collection from
>> the
>> >> send
>> >> > action, to add events that way.
>> >> <snip/>
>> >>
>> >> The EventDispatcher is meant for <send> and <cancel>, which
are part
>> >> of the external communications module. It does not provide ready
>> >> access to the derived events collections, which is the internal state
>> >> of the executing state machine. As you note above, that collection is
>> >> available to custom actions.
>> >>
>> >> However, in v0.9, the semantics of skipping the 'target' and
>> >> 'targettype' (latest WD: now known as 'type') attributes for a <send>
>> >> has the effect of adding the event to the internal events collection
>> >> (latest WD: the type has to be '#_internal' instead of empty or
>> >> missing).
>> >>
>> >> -Rahul
>> >>

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


Mime
View raw message