JBoss Community

Jbpm 3 jms state problem

created by Giovanni Marigi in jBPM - View the full discussion

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

Start a new discussion in jBPM at Community