<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: Message Event (throw and catch problem)
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/krishanps">krishanps</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/643600#643600">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My implementation changes:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><table border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"><tbody><tr><th align="center" style="border:1px solid black;border: 1px solid #000000;background-color: #6690bc;" valign="middle"><span style="color: #ffffff;"><strong>*.java<br/></strong></span></th></tr><tr><td style="border:1px solid black;border: 1px solid #000000;"><p>public static final void main(String[] args) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // load up the knowledge base</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; KnowledgeBase kbase = readKnowledgeBase();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //creates an own SendTaskHandler to work on the same ksession to initiate a message event catch call</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff0000;">MessageSendTaskHandler msgSendTaskHandler = new MessageEventSendTaskHandler();</span></p><p><span style="color: #ff0000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgSendTaskHandler.setStatefulKnowledgeSession(ksession);</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ksession.getWorkItemManager().registerWorkItemHandler("Send Task", <span style="color: #ff0000;">msgSendTaskHandler</span>);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map&lt;String, Object&gt; params = new HashMap&lt;String, Object&gt;();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; params.put("x", "MyValue");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; params.put("y", "OtherValue");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // start a new process instance</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (Throwable t) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; t.printStackTrace();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private static KnowledgeBase readKnowledgeBase() throws Exception {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; kbuilder.add(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventMessage.bpmn2"), ResourceType.BPMN2);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return kbuilder.newKnowledgeBase();</p><p>&#160;&#160;&#160; }</p><p>}</p></td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The Implemented SendTaskHandler.java</p><table border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"><tbody><tr><th align="center" style="border:1px solid black;border: 1px solid #000000;background-color: #6690bc;" valign="middle"><span style="color: #ffffff;"><strong>MessageEventSendTaskHandler.java</strong></span></th></tr><tr><td style="border:1px solid black;border: 1px solid #000000;"><p>public class&#160; MessageEventSendTaskHandler implements WorkItemHandler {</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; private StatefulKnowledgeSession ksession;</p><p>&#160;&#160;&#160; private long processInstanceID;</p><p>&#160;&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; String message = (String) workItem.getParameter("Message");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Die gesendete Nachricht: " + message);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //starts Message Catch Event </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; getStatefulKnowledgeSession().signalEvent("Message-_8_Message", "hi",&#160;&#160; getStatefulKnowledgeSession().getProcessInstance(1).getId());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; manager.completeWorkItem(workItem.getId(), null);</p><p>&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; public void setStatefulKnowledgeSession(StatefulKnowledgeSession ksession){</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.ksession = ksession;</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public StatefulKnowledgeSession getStatefulKnowledgeSession(){</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return this.ksession;</p><p>&#160;&#160;&#160; }</p><p>}</p></td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>If you have questions feel free to post your questions :-)</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/643600#643600">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>