You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Thiébault Benoît <de...@artenum.com> on 2010/09/16 16:17:38 UTC

[scxml] How to retrieve the triggering event in a custom action

Hi everyone,

I'm using SCML with custom actions. I followed the Custom Actions tutorial successfully (http://commons.apache.org/scxml/guide/custom-actions.html), but the Hello action only uses parameters provided in the SCXML file.

What I want to do is to provide a payload to the triggering event and retrieve it in my custom action. Is this possible ?

// In the method firing the event
TriggerEvent[] evts = {new TriggerEvent(event.getId(),
           TriggerEvent.SIGNAL_EVENT, myPayload)};
       try {
           engine.triggerEvents(evts);
       } catch (ModelException me) {
           logError(me);
       }

// In the custom action class
public void execute(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Log appLog, Collection derivedEvents) throws ModelException, SCXMLExpressionException {
       // Here I want to retrieve myPayload
   }

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


Re: [scxml] How to retrieve the triggering event in a custom action

Posted by Rahul Akolkar <ra...@gmail.com>.
2010/9/16 Thiébault Benoît <de...@artenum.com>:
> Thank you, it works very well (the first option, because I don't know a priori the event name so it is hard to use the second).
>
> When you say "When using v0.9", is this API planned to change in future version or is it just to say "it works in 0.9 but might not work forever"
>
<snip/>

The latest draft includes more meta-data for events (in addition to
payload). Though the change hasn't been implemented yet, there will be
an _event variable and the payload will be at _event.data in
subsequent releases.

-Rahul


> Kind regards
> Ben
>
> Le 16 sept. 2010 à 16:38, Rahul Akolkar a écrit :
>
>> 2010/9/16 Thiébault Benoît <de...@artenum.com>:
>>> Hi everyone,
>>>
>>> I'm using SCML with custom actions. I followed the Custom Actions tutorial successfully (http://commons.apache.org/scxml/guide/custom-actions.html), but the Hello action only uses parameters provided in the SCXML file.
>>>
>>> What I want to do is to provide a payload to the triggering event and retrieve it in my custom action. Is this possible ?
>>>
>>> // In the method firing the event
>>> TriggerEvent[] evts = {new TriggerEvent(event.getId(),
>>>           TriggerEvent.SIGNAL_EVENT, myPayload)};
>>>       try {
>>>           engine.triggerEvents(evts);
>>>       } catch (ModelException me) {
>>>           logError(me);
>>>       }
>>>
>>> // In the custom action class
>>> public void execute(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Log appLog, Collection derivedEvents) throws ModelException, SCXMLExpressionException {
>>>       // Here I want to retrieve myPayload
>> <snip/>
>>
>> When using v0.9, for the above external trigger:
>>
>>  Object payload = scInstance.getRootContext().get("_eventdata");
>>
>> When processing internal / derived events, the following:
>>
>>  Object payload =
>> scInstance.getRootContext().get("_eventdatamap").get("my.event.name");
>>
>> For examples which may illustrate where the payload resides in the
>> root context, see the eventdata-*.xml files here (this may help to see
>> how the values may be retrieved programmatically within a custom
>> action):
>>
>>  http://svn.apache.org/repos/asf/commons/proper/scxml/tags/SCXML_0_9/src/test/java/org/apache/commons/scxml/env/jexl/
>>
>> -Rahul
>>
>>
>>>   }
>>>
>>> Kind regards
>>> Ben
>>>
>>

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


Re: [scxml] How to retrieve the triggering event in a custom action

Posted by Thiébault Benoît <de...@artenum.com>.
Thank you, it works very well (the first option, because I don't know a priori the event name so it is hard to use the second).

When you say "When using v0.9", is this API planned to change in future version or is it just to say "it works in 0.9 but might not work forever"

Kind regards
Ben

Le 16 sept. 2010 à 16:38, Rahul Akolkar a écrit :

> 2010/9/16 Thiébault Benoît <de...@artenum.com>:
>> Hi everyone,
>> 
>> I'm using SCML with custom actions. I followed the Custom Actions tutorial successfully (http://commons.apache.org/scxml/guide/custom-actions.html), but the Hello action only uses parameters provided in the SCXML file.
>> 
>> What I want to do is to provide a payload to the triggering event and retrieve it in my custom action. Is this possible ?
>> 
>> // In the method firing the event
>> TriggerEvent[] evts = {new TriggerEvent(event.getId(),
>>           TriggerEvent.SIGNAL_EVENT, myPayload)};
>>       try {
>>           engine.triggerEvents(evts);
>>       } catch (ModelException me) {
>>           logError(me);
>>       }
>> 
>> // In the custom action class
>> public void execute(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Log appLog, Collection derivedEvents) throws ModelException, SCXMLExpressionException {
>>       // Here I want to retrieve myPayload
> <snip/>
> 
> When using v0.9, for the above external trigger:
> 
>  Object payload = scInstance.getRootContext().get("_eventdata");
> 
> When processing internal / derived events, the following:
> 
>  Object payload =
> scInstance.getRootContext().get("_eventdatamap").get("my.event.name");
> 
> For examples which may illustrate where the payload resides in the
> root context, see the eventdata-*.xml files here (this may help to see
> how the values may be retrieved programmatically within a custom
> action):
> 
>  http://svn.apache.org/repos/asf/commons/proper/scxml/tags/SCXML_0_9/src/test/java/org/apache/commons/scxml/env/jexl/
> 
> -Rahul
> 
> 
>>   }
>> 
>> Kind regards
>> Ben
>> 
> 
> ---------------------------------------------------------------------
> 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


Re: [scxml] How to retrieve the triggering event in a custom action

Posted by Rahul Akolkar <ra...@gmail.com>.
2010/9/16 Thiébault Benoît <de...@artenum.com>:
> Hi everyone,
>
> I'm using SCML with custom actions. I followed the Custom Actions tutorial successfully (http://commons.apache.org/scxml/guide/custom-actions.html), but the Hello action only uses parameters provided in the SCXML file.
>
> What I want to do is to provide a payload to the triggering event and retrieve it in my custom action. Is this possible ?
>
> // In the method firing the event
> TriggerEvent[] evts = {new TriggerEvent(event.getId(),
>           TriggerEvent.SIGNAL_EVENT, myPayload)};
>       try {
>           engine.triggerEvents(evts);
>       } catch (ModelException me) {
>           logError(me);
>       }
>
> // In the custom action class
> public void execute(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Log appLog, Collection derivedEvents) throws ModelException, SCXMLExpressionException {
>       // Here I want to retrieve myPayload
<snip/>

When using v0.9, for the above external trigger:

  Object payload = scInstance.getRootContext().get("_eventdata");

When processing internal / derived events, the following:

  Object payload =
scInstance.getRootContext().get("_eventdatamap").get("my.event.name");

For examples which may illustrate where the payload resides in the
root context, see the eventdata-*.xml files here (this may help to see
how the values may be retrieved programmatically within a custom
action):

  http://svn.apache.org/repos/asf/commons/proper/scxml/tags/SCXML_0_9/src/test/java/org/apache/commons/scxml/env/jexl/

-Rahul


>   }
>
> Kind regards
> Ben
>

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