How to pass parameters when using signal start event

2,085 views
Skip to first unread message

John Bucknam

unread,
Oct 9, 2014, 3:21:39 PM10/9/14
to jbpm-...@googlegroups.com
I am using jbpm 6.0.1 and created a process with a signal start event. I am using ksession.signalEvent(String eventType, Object myEvent) which indeed causes the process to start.
However I cannot figure out how to use the contents of the myEvent object to populate a process variable. To make things as simple as possible I am passing
an event object of type String. I want to map this string into a process variable name OID which is also of type String. I tried to follow the unit test code
that comes with the jbpm source code (at the very bottom of this post) but it doesn't seem to work. Looking at the jbpm source code it looks like dataOutput
elements are ignored on start events so my question is how does one access the event object in a process instance?

code:
ksession.signalEvent("mySignal", "1234567");

bpmn2 file:
  <bpmn2:itemDefinition id="_OIDItem" structureRef="String"/>
:
  <bpmn2:process id="foo" drools:version="1.0" drools:packageName="bar" drools:adHoc="false" name="blahl" isExecutable="true">
    <bpmn2:property id="OID" itemSubjectRef="_OIDItem"/>
:
    <bpmn2:startEvent id="_99" name="mySignal">
      <bpmn2:outgoing>_27</bpmn2:outgoing>
      <bpmn2:dataOutput id="DataOutput_1" itemSubjectRef="_OIDItem" name="_UE_Output"/>
      <bpmn2:dataOutputAssociation id="DataOutputAssociation_1">
        <bpmn2:sourceRef>DataOutput_1</bpmn2:sourceRef>
        <bpmn2:targetRef>OID</bpmn2:targetRef>
      </bpmn2:dataOutputAssociation>
      <bpmn2:outputSet id="OutputSet_1" name="Output Set 1">
        <bpmn2:dataOutputRefs>DataOutput_1</bpmn2:dataOutputRefs>
      </bpmn2:outputSet>
      <bpmn2:signalEventDefinition id="_UE" signalRef="mySignal"/>
    </bpmn2:startEvent>

Below is what I found in the unit tests that come with the jbpm source code.

    @Test
    public void testSignalStart() throws Exception {
        KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2");
        KieSession ksession = createKnowledgeSession(kbase);
        final List<Long> list = new ArrayList<Long>();
        ksession.addEventListener(new DefaultProcessEventListener() {
            public void afterProcessStarted(ProcessStartedEvent event) {
                list.add(event.getProcessInstance().getId());
            }
        });
        ksession.signalEvent("MySignal", "NewValue");
        assertEquals(1, list.size());
    }


    <itemDefinition id="_xItem" structureRef="String" />

<process processType="Private" isExecutable="true" id="Minimal" name="Minimal Process" tns:packageName="com.sample" >

    <!-- process variables -->
    <property id="x" itemSubjectRef="_xItem"/>

    <!-- nodes -->
    <startEvent id="_1" name="StartProcess" >
      <dataOutput id="_1_Output" />
      <dataOutputAssociation>
        <sourceRef>_1_Output</sourceRef>
        <targetRef>x</targetRef>
      </dataOutputAssociation>
      <outputSet>
        <dataOutputRefs>_1_Output</dataOutputRefs>
      </outputSet>
      <signalEventDefinition signalRef="MySignal" />
    </startEvent>
    <scriptTask id="_2" name="Hello" >
      <script>System.out.println("x = " + x);</script>
    </scriptTask>
    <endEvent id="_3" name="EndProcess" >
        <terminateEventDefinition/>
    </endEvent>



Maciej Swiderski

unread,
Oct 9, 2014, 3:25:41 PM10/9/14
to John Bucknam, jbpm-...@googlegroups.com
John,

you need to name your dataOutput with: event and that should recognize it and map to proper process variable

    <startEvent id="_1" name="StartProcess" >
      <dataOutput id="_1_Output" name="event" />
      <dataOutputAssociation>
        <sourceRef>_1_Output</sourceRef>
        <targetRef>x</targetRef>
      </dataOutputAssociation>
      <outputSet>
        <dataOutputRefs>_1_Output</dataOutputRefs>
      </outputSet>
      <signalEventDefinition signalRef="MySignal" />
    </startEvent>

Maciej
--
You received this message because you are subscribed to the Google Groups "jBPM Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-usage+...@googlegroups.com.
To post to this group, send email to jbpm-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-usage/e86579ad-c235-41ce-bbfe-caff2e3220c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Bucknam

unread,
Oct 10, 2014, 10:47:46 AM10/10/14
to jbpm-...@googlegroups.com, johnb...@gmail.com
Maciej-

Thank you very much for the tip. It worked like a charm!

I had looked through every document available and never found this information.

-John

Maciej Swiderski

unread,
Oct 10, 2014, 10:48:59 AM10/10/14
to John Bucknam, jbpm-...@googlegroups.com
John,

glad it worked. Feel free to drop a pull request for documentation so next time it will be easier to find :)

Maciej

José Cavieres

unread,
Oct 14, 2014, 5:36:53 PM10/14/14
to jbpm-...@googlegroups.com, johnb...@gmail.com
Hi,

I believe this is not something to write/clarify in the docs, but a already reported bug to fix:

Regards,
JCS

Robert Brodt

unread,
Nov 13, 2014, 4:55:19 PM11/13/14
to jbpm-...@googlegroups.com, johnb...@gmail.com
Hi Maciej,

Does the same constraint apply for ThrowEvents? In other words, does the DataInput name have to be "event" as well?

Thanks!
Bob

Maciej Swiderski

unread,
Nov 14, 2014, 4:57:30 AM11/14/14
to Robert Brodt, jbpm-...@googlegroups.com, johnb...@gmail.com
Bob,

this has been recently updated on runtime engine side to simplify it. So where there is only one data output defined it will use it regardless of its name.

When it comes to throwing events there is no such requirement.

Maciej
--
You received this message because you are subscribed to the Google Groups "jBPM Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-usage+...@googlegroups.com.
To post to this group, send email to jbpm-...@googlegroups.com.

Pantelis Natsiavas

unread,
Dec 12, 2014, 4:31:57 AM12/12/14
to jbpm-...@googlegroups.com, johnb...@gmail.com
Could you please suggest a tutorial or an example showing how to raise events and hande the data sent with it? I tried to reproduce your example, but I could not do it (obviously because you don't post your whole bpmn files).

Thank you in advance,
Pantelis Natsiavas

Reply all
Reply to author
Forward
0 new messages