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?
<bpmn2:process id="foo" drools:version="1.0" drools:packageName="bar" drools:adHoc="false" name="blahl" isExecutable="true">
<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>