[jboss-user] [jBPM] - Jbpm 3 jms state problem

Giovanni Marigi do-not-reply at jboss.com
Mon Nov 1 13:37:18 EDT 2010


Giovanni Marigi [http://community.jboss.org/people/hifly81] created the discussion

"Jbpm 3 jms state problem"

To view the discussion, visit: http://community.jboss.org/message/569174#569174

--------------------------------------------------------------
Hi,
I'm using jbpm 3 and I want to realize a state node as a jms topic subscriber.
Basically I want to call the *leaveNode()* inside my "jms handler" as soon as a message comes to the topic.
The problem is that I can't call the *leaveNode() *without hibernate exceptions** cause the *executionContext inside the onMessage method* is not the same
*executionContext inside the execute method.
*
I think beacuse they are running in separate threads?*
*

I'm not so good in jbpm and maybe my approach is completely wrong!

Thanks,
Giovanni


public class WaitForJmsHandler implements ActionHandler {  

    Context jndiContext = null;
    *ExecutionContext executionContext = null;*
    TopicConnectionFactory topicConnectionFactory = null;
    TopicConnection topicConnection = null;
    TopicSession topicSession = null;
    Topic topic = null;
    TopicSubscriber topicSubscriber = null;

    public void execute(ExecutionContext ctx) throws Exception {
        this.executionContext = ctx;

        Hashtable props = new Hashtable();
        props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
        props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
        props.put(javax.naming.Context.PROVIDER_URL, "127.0.0.1:1099");
        jndiContext = new InitialContext(props);

        topicConnectionFactory = (TopicConnectionFactory)
        jndiContext.lookup("ConnectionFactory");
        topic = (Topic) jndiContext.lookup("topic/testTopic");

        topicConnection = topicConnectionFactory.createTopicConnection();
        topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        topicSubscriber = topicSession.createSubscriber(topic);
        topicSubscriber.setMessageListener(new CustomJMSListener() {
            @Override
            public void onMessage(Message message) {
                try {
                    System.out.println("Received message:["+message+"]");
                    *executionContext.leaveNode();*
                    System.out.println("Leaving node....");
                }
                catch(Exception ex) {
                    try {
                        topicConnection.stop();
                    } catch (JMSException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        });

        topicConnection.start();
        JbpmContext jbpmContext = executionContext.getJbpmContext();
        jbpmContext.save(executionContext.getProcessInstance());

    }
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/569174#569174]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20101101/ef75775a/attachment.html 


More information about the jboss-user mailing list