2 Replies Latest reply on Apr 6, 2010 4:50 AM by herbst

    exception on fork getting all outgoing transitions

    herbst

      Hi,

      I'm still experimentig with jBPM 4.3 ran in som exeption. The goal is run the jpdl step by step, so i'm trying to get all transitions of the active nodes and signal each time which is taken. This works real good, as long i don't add concurrency. But with this diagramm i'm getting the exceptions org.jbpm.api.JbpmException: no environment to get org.jbpm.pvm.internal.session.RepositorySession.

       

      Here is the jpdl-file:

       

      <?xml version="1.0" encoding="UTF-8"?>
      
      <process name="eTestDoubleFork" xmlns="http://jbpm.org/4.3/jpdl">
      
          <start g="259,3,80,40" name="Start">
              <transition to="wait"/>
          </start>
      
          <state g="244,93,80,40" name="wait">
            <transition g="-39,-20" name="to fork" to="fork1"/>
          </state>
      
          <state g="462,191,80,40" name="park">
            <transition g="-46,-20" name="to fork2" to="fork2"/>
          </state>
          
         <state g="137,345,92,52" name="home">
            <transition g="-60,-12" name="to state 3" to="state3"/>
         </state>
          
         <end g="311,495,48,48" name="end1"/>
         <fork g="266,186,48,48" name="fork1">
            <transition g="-41,4" name="toHome" to="home"/>
            <transition g="-39,-20" name="toPark" to="park"/> 
         </fork>
       
      
        <fork g="478,343,48,48" name="fork2">
            <transition g="-50,-20" name="to state1" to="state1"/>
            <transition g="18,4" name="to state2" to="state2"/>
         </fork>
         <state g="290,343,92,52" name="state1">
            <transition g="-20,-14" name="to end state1" to="end1"/>
         </state>
         <state g="457,490,92,52" name="state2">
            <transition g="-45,-20" name="to end state2" to="end1"/>
         </state>
         <state name="state3" g="146,461,92,52">
            <transition name="to end state3" to="end1" g="-43,5"/>
         </state>
      
      </process>
      

       

      And here the code I'm running:

      Workflow.java

      public class Workflow implements Serializable
      {
          private static Configuration jbpmConfiguration = new Configuration().setResource("my.jbpm.cfg.xml");
          private Map<String, Object> variables = new HashMap<String, Object>();
          private ProcessEngine processEngine;    
          private RepositoryService repositoryService;
          private ExecutionService executionService;
          private NewDeployment newDeployment;
          private String deploymentDbid;
          private HistoryService historyService;
      
          
          public Workflow()
          {
              processEngine = jbpmConfiguration.buildProcessEngine();
              repositoryService = processEngine.getRepositoryService();
              executionService = processEngine.getExecutionService();
              deploymentDbid = addNewDeployment("test/eTestDoubleFork.jpdl.xml");
          }
          
          public String addNewDeployment(String jpdl_file)
          {
              NewDeployment newDeployment = repositoryService.createDeployment().addResourceFromClasspath(jpdl_file);
              String deploymentDbid = newDeployment.deploy();
                  
              return deploymentDbid;
          }
          
      
          public ProcessInstance startProcessInstance(String processInstanceKey)
          {
              System.out.println(repositoryService.getResourceNames(deploymentDbid));
              ProcessInstance processInstance = executionService.startProcessInstanceByKey(processInstanceKey, variables);        
              
              return processInstance;
          }
      
          public ProcessInstance nextState(ProcessInstance processInstance, Transition transition)
          {
              List<Transition> transitions = getTransitiones(processInstance);
              
              if(transitions.contains(transition))
              {
                  Execution execution = searchTransitionExecution(processInstance, transition);
                  processInstance = executionService.signalExecutionById(execution.getId(), transition.getName());
                  
              }
              return processInstance;
          }
      
          private Execution searchTransitionExecution(ProcessInstance processInstance, Transition transition)
          {
              Execution mainExecution = processInstance.getProcessInstance();
      
              if(!mainExecution.getExecutions().isEmpty())
              {    
                  for(Execution exe : mainExecution.getExecutions())
                  {
                      try
                      {
                          if(((ExecutionImpl)exe).getActivity().getOutgoingTransitions().contains(transition))
                          {
                              mainExecution = exe;
                              break;
                          }
                      }
                      catch(Exception e)
                      {
                          System.out.println(exe.getName() + ":" + e);
                      }
                  }
              }
              return mainExecution;
          }
      
          public Set<String> getStateName(ProcessInstance processInstance)
          {    
              if(processInstance.isEnded())
              {
                  return null;
              }
              else
              {
                  return processInstance.findActiveActivityNames();
              }
          }
      
           public List<Transition> getTransitiones(ProcessInstance processInstance)
          {    
               Execution execution;
               List<Transition> stateList = new ArrayList<Transition>();
               
              for(String exName : processInstance.findActiveActivityNames())
              {
                  execution = processInstance.findActiveExecutionIn(exName);
                  stateList.addAll(getTransitiones(execution));
              }
              
              return stateList;
          }
      
           public List<Transition> getTransitiones(Execution execution)
          {    
               List<Transition> list = new ArrayList<Transition>();
               ExecutionImpl exeImpl = (ExecutionImpl)execution;
       
               try
               {
                   ActivityImpl activImpl = exeImpl.getActivity();
                   list = activImpl.getOutgoingTransitions();
               }
               catch(Exception e)
               {
                   System.out.println(execution.getName() + ":" + e);
               }
                   
               
               return list;
          }
      }
      

       

      start.java

      public class Start 
      {
          public static void main(String[] args) 
          {
              // Setze Workflow-Engine auf
              Workflow wf = new Workflow();
              
              // Setze Workflow auf und starte eine Instanz
              wf.addNewDeployment("jBPM_to_W3LJ2/eTestDoubleFork.jpdl.xml");
              ProcessInstance processInstance = wf.startProcessInstance("eTestDoubleFork");
              String processInstanceId = processInstance.getId();
              
              
              String processDefinitionId = processInstance.getProcessDefinitionId();
              
              System.out.println("1------------------------------");
              System.out.println("Befinde mich in State : " + wf.getStateName(processInstance));
              List<Transition> transitions = wf.getTransitiones(processInstance);
              System.out.println("Ausgehenden Transitionen : " + transitions.toString());
              
              Transition trans = transitions.get(0);
              
              System.out.println("Wähle Transition : " + trans.getName());
              processInstance = wf.nextState(processInstance, trans);
              
      
              System.out.println("Befinde mich nun in State : " + wf.getStateName(processInstance));
          
              
              System.out.println("2------------------------------");
              transitions = wf.getTransitiones(processInstance);
              System.out.println("Ausgehenden Transitionen : " + transitions.toString());
              trans = transitions.get(0);
              
              System.out.println("Wähle Transition : " + trans.getName());
              processInstance = wf.nextState(processInstance, trans);
              System.out.println("Befinde mich nun in State : " + wf.getStateName(processInstance));
          
          
              System.out.println("3------------------------------");
              transitions = wf.getTransitiones(processInstance);
              System.out.println("Ausgehenden Transitionen : " + transitions.toString());
              trans = transitions.get(0);
              
              System.out.println("Wähle Transition : " + trans.getName());
              processInstance = wf.nextState(processInstance, trans);
              System.out.println("Befinde mich nun in State : " + wf.getStateName(processInstance));
         
              System.out.println("History States : " + wf.getHistoryToString(processInstanceId, processDefinitionId));
          }
      
      }
      

       

      It works until

      System.out.println("3------------------------------");
      After that line I'm getting not all transitions.

      Can anyone hlep me ?
      Thanks
      Sebastian

        • 1. Re: exception on fork getting all outgoing transitions
          swiderski.maciej

          Hi,

           

          I ran into similar problem and unfortunately I don't have explanation why it happens like that.

           

          I pretty sure what is the reason of the problem - process definition is not loaded for the process instance (Execution) that you are examining. I would suggest a workaround to get it working. Check if process definition is present on your execution and if note use ProcessDefinitionQuery

           

          repositoryService.createProcessDefinitionQyery().processDefinitionId(processInstance.getProcessDefinitionId()).uniqueResult()
          

          and set returned object on your execution.

           

          That should solve the problem.

           

          You can as well do it manually by checking process definition your self to find correct node by its name (currently executing one).

           

          HTH

          Maciej

          • 2. Re: exception on fork getting all outgoing transitions
            herbst

            Hi,

            maybe i didn't made it clear.

             

            eTestDoubleFork.png

            I'm trying to get the outgoing nodes in the order:

             

            Active Node: [wait] ->  'to fork'

            Active Node: [home, park] ->  'to state 3' or 'to fork2' (*) (for the further text I assume I took 'to fork2')

             

            ok until here it works without any problems.

             

            Next I request

            processInstance.findActiveActivityNames()  <- works fine

            this gets me [home,state1,state2]

             

            Now I'm trying to get the outgoing transitions, by finding the execution with the given names.

            It works for the state the last transition went to, so for example I took 'to fork2' at (*) I'm able to get the outgoing transitions of state1 and state2, but not the transitions of home. In debug the 'activity' of  home is null at that moment.

             

            The same happens for 'park' if I take the other transition in (*).

             

            Any suggestions to get this fixed ?

            Thanks

            Sebastian