1 Reply Latest reply on Nov 1, 2010 2:04 PM by hifly81

    Jbpm 3 jms state problem

    hifly81

      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());

       

          }

        • 1. Re: Jbpm 3 jms state problem
          hifly81

          If I will delegate it to an external mdb, how can I signal the leaveNode to the bpm wait state? I've only founded piece of code to call a bpm start node from an external app.

          Giovanni