<!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;">
    Jbpm 3 jms state problem
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/hifly81">Giovanni Marigi</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/569174#569174">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p>I'm using jbpm 3 and I want to realize a state node as a jms topic subscriber.</p><p>Basically I want to call the<strong> leaveNode() </strong>inside my "jms handler" as soon as a message comes to the topic.</p><p>The problem is that I can't call the <strong>leaveNode() <strong>without hibernate exceptions</strong></strong> cause the <strong>executionContext inside the onMessage method </strong>is not the same</p><p><strong>executionContext inside the execute method.<br/></strong></p><p>I think beacuse they are running in separate threads?<strong><br/></strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'm not so good in jbpm and maybe my approach is completely wrong!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks,</p><p>Giovanni</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class WaitForJmsHandler implements ActionHandler {&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; Context jndiContext = null;<br/>&#160;&#160;&#160; <strong>ExecutionContext executionContext = null;</strong><br/>&#160;&#160;&#160; TopicConnectionFactory topicConnectionFactory = null;<br/>&#160;&#160;&#160; TopicConnection topicConnection = null;<br/>&#160;&#160;&#160; TopicSession topicSession = null;<br/>&#160;&#160;&#160; Topic topic = null;<br/>&#160;&#160;&#160; TopicSubscriber topicSubscriber = null;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public void execute(ExecutionContext ctx) throws Exception {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.executionContext = ctx;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Hashtable props = new Hashtable();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; props.put(javax.naming.Context.PROVIDER_URL, "127.0.0.1:1099");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; jndiContext = new InitialContext(props);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topicConnectionFactory = (TopicConnectionFactory)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; jndiContext.lookup("ConnectionFactory");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topic = (Topic) jndiContext.lookup("topic/testTopic");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topicConnection = topicConnectionFactory.createTopicConnection();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topicSubscriber = topicSession.createSubscriber(topic);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topicSubscriber.setMessageListener(new CustomJMSListener() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @Override<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void onMessage(Message message) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Received message:["+message+"]");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <strong>executionContext.leaveNode();</strong><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Leaving node....");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch(Exception ex) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; topicConnection.stop();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (JMSException e) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO Auto-generated catch block<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.printStackTrace();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; });</p><p><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topicConnection.start();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; JbpmContext jbpmContext = executionContext.getJbpmContext();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; jbpmContext.save(executionContext.getProcessInstance());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; }</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/569174#569174">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>