1 Reply Latest reply on Jul 16, 2014 7:50 AM by akoskm

    Retrieving current node of a process instance while using persistence

    akoskm Newbie

      I'm trying to achieve this simple task, my code which worked just fine before persistence mode is:

       

          public Node getCurrentNodeName(Long appId) {
              Node currentNode = null;
              AppSession appSess = sessions.get(appId);
              if (appSess != null) {
                  org.jbpm.workflow.instance.WorkflowProcessInstance pi = appSess.getProcessInstance();
                  if (pi != null) {
                      try {
                          Collection<NodeInstance> nodes = pi.getNodeInstances();
                          NodeInstance nodeInstance = nodes.iterator().next();
                          currentNode = nodeInstance.getNode();
                      } catch (NoSuchElementException ex) {
                          // array has no more elements, next() throws OK
                      }
                  }
              }
              return currentNode;
          }
      
      

      However with persistence mode enable I'm getting the following error:

       

      Caused by: ! java.lang.RuntimeException: Process instance 14[com.mycompany.sample] is disconnected.
      ! at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:90) ~[jbpm-flow-6.0.0.Final.jar:6.0.0.Final]
      ! at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.getWorkflowProcess(WorkflowProcessInstanceImpl.java:211) ~[jbpm-flow-6.0.0.Final.jar:6.0.0.Final]
      ! at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.getNodeContainer(WorkflowProcessInstanceImpl.java:80) ~[jbpm-flow-6.0.0.Final.jar:6.0.0.Final]
      ! at org.jbpm.workflow.instance.impl.NodeInstanceImpl.getNode(NodeInstanceImpl.java:120) ~[jbpm-flow-6.0.0.Final.jar:6.0.0.Final]
      ! at org.mycompany.business.BpmAppManager.getCurrentNodeName(BpmAppManager.java:101) ~[classes/:na]
      ! at org.mycompany.resources.atmosphere.NodeTriggeredResource.subscribeWithInitialResponse(NodeTriggeredResource.java:85) ~[classes/:na]
      ! at org.mycompany.resources.atmosphere.NodeTriggeredResource.subscribeToStatus(NodeTriggeredResource.java:70) ~[classes/:na]
      ! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_55]
      ! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_55]
      ! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_55]
      ! at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_55]
      ! at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$JResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:236) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381) ~[jersey-server-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-servlet-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) ~[jersey-servlet-1.17.1.jar:1.17.1]
      ! at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) ~[jersey-servlet-1.17.1.jar:1.17.1]
      ! at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) [javax.servlet-3.0.0.v201112011016.jar:na]
      ! at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:135) ~[atmosphere-runtime-2.1.4.jar:2.1.4]
      ! at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:96) ~[atmosphere-runtime-2.1.4.jar:2.1.4]
      ! at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.java:320) ~[atmosphere-runtime-2.1.4.jar:2.1.4]
      ! at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:163) ~[atmosphere-runtime-2.1.4.jar:2.1.4]
      !... 46 common frames omitted
      
      

      Any ideas why this is happening?

        • 1. Re: Retrieving current node of a process instance while using persistence
          akoskm Newbie

          Seem that retrieving the current node with the help of GenericCommand works:

           

                      currentNode = appSess.getKsession().execute(new GenericCommand<Node>() { 
          
                          @Override
                          public Node execute(Context context) { 
                              KieSession ksession = ((KnowledgeCommandContext) context).getKieSession(); 
                              org.jbpm.workflow.instance.WorkflowProcessInstance pi = (org.jbpm.workflow.instance.WorkflowProcessInstance) (ProcessInstance) ksession.getProcessInstance(pid);
                              Collection<NodeInstance> nodes = pi.getNodeInstances();
                              NodeInstance nodeInstance = nodes.iterator().next();
                              return nodeInstance.getNode();
                          } 
                      });