krishanps [
http://community.jboss.org/people/krishanps] created the discussion
"Re: Message Event (throw and catch problem)"
To view the discussion, visit:
http://community.jboss.org/message/643600#643600
--------------------------------------------------------------
Yes, of course. So I just give a reference to ksession from the main-method to the
implemented MessageEventSendTaskHandler.java. So I can use it to call a signalEvent to
initiate the message catch event.
My implementation changes:
|| **.java
* ||
| public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
//creates an own SendTaskHandler to work on the same ksession to initiate a
message event catch call
MessageSendTaskHandler msgSendTaskHandler = new MessageEventSendTaskHandler();
msgSendTaskHandler.setStatefulKnowledgeSession(ksession);
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
new DoNothingWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Send Task",
msgSendTaskHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "MyValue");
params.put("y", "OtherValue");
// start a new process instance
ProcessInstance processInstance =
ksession.startProcess("IntermediateCatchEvent", params);
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventMessage.bpmn2"),
ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
} |
The Implemented SendTaskHandler.java
|| *MessageEventSendTaskHandler.java* ||
| public class MessageEventSendTaskHandler implements WorkItemHandler {
private StatefulKnowledgeSession ksession;
private long processInstanceID;
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
String message = (String) workItem.getParameter("Message");
System.out.println("Die gesendete Nachricht: " +
message);
//starts Message Catch Event
getStatefulKnowledgeSession().signalEvent("Message-_8_Message",
"hi", getStatefulKnowledgeSession().getProcessInstance(1).getId());
manager.completeWorkItem(workItem.getId(), null);
}
public void setStatefulKnowledgeSession(StatefulKnowledgeSession ksession){
this.ksession = ksession;
}
public StatefulKnowledgeSession getStatefulKnowledgeSession(){
return this.ksession;
}
} |
If you have questions feel free to post your questions :-)
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/643600#643600]
Start a new discussion in jBPM at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]