Community

exception on fork getting all outgoing transitions

created by Sebastian Herbst in jBPM - View the full discussion

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

Reply to this message by going to Community

Start a new discussion in jBPM at Community