13 Replies Latest reply on Sep 7, 2009 6:41 AM by thirumalvishnu

    jbpm 4.0 creating and running processes without persistence

    thirumalvishnu

      Hi ,

      I am new to JBPM and need some help .
      In the devguide document it was mentioned as

      "To execute processes without persistence, the client API can be used to work with process and execution objects directly. The client API expose the methods of the core model objects.".

      We are in need of creating and running a process without persistence .

      I tried going throught the client API javadocs and was not able to figure out a way to create and execute a process .

      Can anybody point me out the proper direction to look for the samples / documents regarding this.

      Thanks for the help



        • 1. Re: jbpm 4.0 creating and running processes without persiste
          oxelad
          • 2. Re: jbpm 4.0 creating and running processes without persiste
            thirumalvishnu

            Hi,

            Thanks for the info. I tried with that section . But it seems in background it uses hibernate to deploy the process .

            During run time I get the following log

            [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)

            Is there any way to remove persistence dependency compeletly and is there any Client API samples which works with process and execution objects directly

            • 3. Re: jbpm 4.0 creating and running processes without persiste
              thirumalvishnu

              Hi,
              I am still stuck with this . Can anybody help me ?

              • 4. Re: jbpm 4.0 creating and running processes without persiste
                kukeltje

                not yet, planned for a future (minor) release, e.g. jbpm 4.1 or 4.2. See the jira

                • 5. Re: jbpm 4.0 creating and running processes without persiste
                  thirumalvishnu

                  Hi Roland,
                  Can you give any additional info ?(like JIRA ref url. I tried searching JIRA but was not able to find requiremtns specific to my need) that would be of much helpful to me.

                  • 6. Re: jbpm 4.0 creating and running processes without persiste
                    mihail

                    I managed to run a process without persistence.

                    Here is the code:

                    import junit.framework.TestCase;
                    import org.jbpm.jpdl.internal.model.JpdlProcessDefinition;
                    import org.jbpm.jpdl.internal.xml.JpdlParser;
                    import org.jbpm.jpdl.internal.activity.StartActivity;
                    import org.jbpm.jpdl.internal.activity.StateActivity;
                    import org.jbpm.jpdl.internal.activity.EndActivity;
                    import org.jbpm.pvm.internal.model.ActivityImpl;
                    import org.jbpm.pvm.internal.model.TransitionImpl;
                    import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
                    import org.jbpm.pvm.internal.client.ClientExecution;
                    import org.jbpm.pvm.internal.xml.Parse;
                    import org.jbpm.api.activity.ActivityExecution;
                    import org.jbpm.api.activity.ExternalActivityBehaviour;
                    
                    import java.io.FileInputStream;
                    import java.io.IOException;
                    import java.util.Map;
                    
                    public class HelloWorldTest extends TestCase {
                     public void test_helloWorldProcess() throws IOException {
                     ProcessDefinitionImpl processDefinition = createProcessDefinition();
                     ClientExecution execution = processDefinition.startProcessInstance();
                     System.out.println("State After start : " + execution.findActiveActivityNames());
                     execution.signal();
                     System.out.println("State after signal: " + execution.findActiveActivityNames());
                    
                     }
                    
                     private ProcessDefinitionImpl createProcessDefinition() {
                     ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
                     processDefinition.setName("hello");
                     //define states
                     ActivityImpl start = processDefinition.createActivity("start");
                     start.setBehaviour(new StartActivity());
                     //it turns out is very important to call this since it says where the process starts
                     processDefinition.setInitial(start);
                     ActivityImpl state1 = processDefinition.createActivity("state1");
                     state1.setBehaviour(new HelloActivity());
                     ActivityImpl state2 = processDefinition.createActivity("state2");
                     state2.setBehaviour(new StateActivity());
                     ActivityImpl end = processDefinition.createActivity("end");
                     end.setBehaviour(new EndActivity());
                     //define transitions
                     TransitionImpl transition = start.createOutgoingTransition();
                     transition.setDestination(state1);
                     TransitionImpl transition2 = state1.createOutgoingTransition();
                     transition2.setDestination(state2);
                     TransitionImpl endTransition = state2.createOutgoingTransition();
                     endTransition.setDestination(end);
                     return processDefinition;
                     }
                    
                    
                    private JpdlProcessDefinition loadProcessDefinition() throws IOException {
                     JpdlParser jpdlParser = new JpdlParser();
                     Parse parse = jpdlParser.createParse();
                     FileInputStream inputStream = new FileInputStream("process.jpdl.xml");
                     parse.setInputStream(inputStream);
                     parse.execute();
                     return (JpdlProcessDefinition) parse.getDocumentObject();
                     }
                    
                     class HelloActivity implements ExternalActivityBehaviour {
                     public void signal(ActivityExecution activityExecution, String signalName, Map<String, ?> stringMap) throws Exception {
                     activityExecution.take(signalName);
                     }
                    
                     public void execute(ActivityExecution activityExecution) throws Exception {
                     System.out.println("=================Hello there===========");
                     activityExecution.waitForSignal();
                     }
                     }
                    }
                    
                    

                    As you can see it uses the internal API quite a bit.


                    Mihail

                    • 7. Re: jbpm 4.0 creating and running processes without persiste
                      kukeltje

                      I thought there already was a jira entry for this, but there isn't. A wiki page does exist: http://www.jboss.org/community/wiki/jBPM4ExecutionModes

                      • 8. Re: jbpm 4.0 creating and running processes without persiste
                        thirumalvishnu

                        Hi,
                        Thanks mihailrc and kukeltje for the solutions. They almost solved my problem except following one issue .

                        In the JBPM sample project we pass the variable to the execution time like .

                        Map<String, Object> variables = new HashMap<String, Object>();
                        .........
                        ............
                        ProcessInstance processInstance = process.executionService
                         .startProcessInstanceByKey("flow_name", variables);



                        Similarly I have to pass variable while creating the process.

                        Any idea how to achieve this with the given code by mihailrc ?

                        • 9. Re: jbpm 4.0 creating and running processes without persiste
                          thirumalvishnu

                          For the above scenario I tried following

                          private JpdlProcessDefinition loadProcessDefinition() throws IOException {
                          JpdlParser jpdlParser = new JpdlParser();
                          Parse parse = jpdlParser.createParse();
                          String fileLocation ="*****.jpdl.xml";
                          FileInputStream inputStream = new FileInputStream(fileLocation);
                          parse.setInputStream(inputStream);
                          parse.execute();
                          return (JpdlProcessDefinition ) parse.getDocumentObject();
                          }

                          and from calling section had this block

                          ProcessDefinitionImpl processDefinition = loadProcessDefinition();
                           ClientProcessInstance ci = processDefinition.createProcessInstance();
                           ci.createVariable("arg", publishArgs);
                           ci.createVariable("fc", fc);
                           ci.start();



                          But I get the exception ,

                          org.jbpm.pvm.internal.wire.WireException: couldn't invoke method execute: couldn't create argument 1: null
                          at org.jbpm.jpdl.internal.activity.JavaActivity.perform(JavaActivity.java:97)
                          at org.jbpm.jpdl.internal.activity.JpdlAutomaticActivity.execute(JpdlAutomaticActivity.java:14)
                          at org.jbpm.pvm.internal.model.op.ExecuteActivity.perform(ExecuteActivity.java:60)
                          at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperationSync(ExecutionImpl.java:625)
                          at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperation(ExecutionImpl.java:585)
                          at org.jbpm.pvm.internal.model.ExecutionImpl.start(ExecutionImpl.java:198)
                          at com.test.flow.FlowController$1.run(FlowController.java:90)
                          at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
                          Caused by: java.lang.Exception: couldn't create argument 1: null
                          at org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor.getArgs(ObjectDescriptor.java:348)
                          at org.jbpm.jpdl.internal.activity.JavaActivity.perform(JavaActivity.java:79)
                          ... 7 more
                          Caused by: java.lang.NullPointerException
                          at org.jbpm.pvm.internal.script.EnvironmentBindings.getReadContext(EnvironmentBindings.java:61)
                          at org.jbpm.pvm.internal.script.EnvironmentBindings.containsKey(EnvironmentBindings.java:72)
                          at javax.script.SimpleScriptContext.getAttribute(SimpleScriptContext.java:143)
                          at org.jbpm.pvm.internal.script.JuelScriptEngine.toELContext(JuelScriptEngine.java:94)
                          at org.jbpm.pvm.internal.script.JuelScriptEngine.parse(JuelScriptEngine.java:162)
                          at org.jbpm.pvm.internal.script.JuelScriptEngine.eval(JuelScriptEngine.java:62)
                          at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:84)
                          at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:116)
                          at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:108)
                          at org.jbpm.pvm.internal.script.ScriptManager.evaluateExpression(ScriptManager.java:80)
                          at org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor.construct(ObjectDescriptor.java:180)
                          at org.jbpm.pvm.internal.wire.WireContext.construct(WireContext.java:473)
                          at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:452)
                          at org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor.getArgs(ObjectDescriptor.java:343)
                          ... 8 more


                          Any help on how to resolve this ....


                          • 10. Re: jbpm 4.0 creating and running processes without persiste
                            thirumalvishnu

                            Hi ,
                            Still stuck in this ... any help is appreciated ..
                            Thanks

                            • 11. Re: jbpm 4.0 creating and running processes without persiste
                              kukeltje

                              Look at the testcases of jBPM4 and the api. There is a method where you pass on variables while starting/creating the processinstance.

                              • 12. Re: jbpm 4.0 creating and running processes without persiste
                                kukeltje
                                • 13. Re: jbpm 4.0 creating and running processes without persiste
                                  thirumalvishnu

                                  Hi ,

                                  Finally got it resolved . Adding the following line before

                                  Environment.pushEnvironment(new BasicEnvironment());

                                  the line

                                  ProcessDefinitionImpl processDefinition = loadProcessDefinition();

                                  solves the issue . Not sure whether this is the perfect solution. But process creation and execution happens without any issue

                                  Thanks
                                  Thirumal