3 Replies Latest reply on Oct 30, 2006 9:56 AM by ayang

    Process-state: can't create a process instance when processD

    ayang

      I'm trying a very simple example of sub-processes up and running with the following definitions:

      <process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="sub">
       <start-state name="start">
       <transition name="" to="node"></transition>
       </start-state>
       <node name="node">
       <transition name="" to="wait-state"></transition>
       </node>
       <end-state name="end"></end-state>
       <state name="wait-state">
       <transition name="" to="end"></transition>
       </state>
      </process-definition>
      

      <process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="caller">
       <start-state name="start">
       <transition name="" to="node"></transition>
       </start-state>
       <end-state name="end"></end-state>
       <node name="node">
       <transition name="" to="call sub"></transition>
       </node>
       <process-state name="call sub">
       <sub-process name="sub"/>
       <transition name="" to="end"></transition>
       </process-state>
      </process-definition>
      

      Excerpted from my unit test code:

       context = _jbpmConfiguration.createJbpmContext();
      
       FileInputStream fis_sub = new FileInputStream("processes/sub/processdefinition.xml");
       FileInputStream fis_caller = new FileInputStream("processes/caller/processdefinition.xml");
      
       ProcessDefinition pdload_sub = ProcessDefinition.parseXmlInputStream(fis_sub);
       ProcessDefinition pdload_caller = ProcessDefinition.parseXmlInputStream(fis_caller);
      
       context.deployProcessDefinition(pdload_sub);
       context.deployProcessDefinition(pdload_caller);
      
       GraphSession gs_caller = context.getGraphSession();
      
       // don't think I necessarily need to reload the process definitions
       // from the session but it doesn't make a difference
       ProcessDefinition pd_sub = gs_caller.findLatestProcessDefinition("sub");
       ProcessDefinition pd_caller = gs_caller.findLatestProcessDefinition("caller");
      
       ProcessInstance inst = new ProcessInstance(pd_caller);
      
       // begin
       Token token = inst.getRootToken();
       ContextInstance contextInst = (ContextInstance) inst.getInstance(ContextInstance.class);
      
       System.out.println("getNode().getName(): " + token.getNode().getName());
      
       token.signal();
       System.out.println("getNode().getName(): " + token.getNode().getName());
       }
       finally
       {
       context.close();
       }
      

      The process runs successfully until it tries to invoke the sub-process (when I signal the calling process) at which point I get the NullPointerException

      I'm sure it's something very simple - any thoughts?

      Thanks,
      Andy

        • 1. Re: Process-state: can't create a process instance when proc
          saviola

          Hi, ayang!
          I think the problem arises from the fact that the subprocess is not actually in the database before you close the jbpmContext.
          Try and investigate in that direction.

          Regards,
          Saviola

          • 2. Re: Process-state: can't create a process instance when proc
            ayang

            I am deploying both processes (with the sub-process getting deployed first):

             context.deployProcessDefinition(pdload_sub);
             context.deployProcessDefinition(pdload_caller);
            


            Shouldn't deploying the processes put them into the "database"? Mind you, I'm using the in-memory HSQL db and a static JbpmConfiguration parsed from an XML string (cut and pasted from sample code). I'm not sure if there is something I have mis-configured?

            Thanks,
            Andy

            • 3. Re: Process-state: can't create a process instance when proc
              ayang

              Found the problem.

              The clue was after executing the following block:

              ProcessDefinition pdload_sub = ProcessDefinition.parseXmlInputStream(fis_sub);
              ProcessDefinition pdload_caller = ProcessDefinition.parseXmlInputStream(fis_caller);
              
              context.deployProcessDefinition(pdload_sub);
              context.deployProcessDefinition(pdload_caller);
              


              I saw the following message when parsing the process definition xml for the "caller" process.

              DEBUG ProcessState : subprocess for process-state 'call subby' not yet bound
              


              Looks like the process and sub-processes get bound at parse-time rather than deploy-time.

              This did the trick:

              ProcessDefinition pdload_sub = ProcessDefinition.parseXmlInputStream(fis_sub);
              context.deployProcessDefinition(pdload_sub);
              
              ProcessDefinition pdload_caller = ProcessDefinition.parseXmlInputStream(fis_caller);
              context.deployProcessDefinition(pdload_caller);