0 Replies Latest reply on Feb 24, 2012 8:26 PM by espinosa_cz

    How to actually run process defined by Process API?

      Manual chapter 5.1.3. Defining Processes Using the Process API is an exciting reading cut short. There is no hint how to run just defined process, how to add the process to Knowledge API.

      I rummaged forums and mail list I found this two approaches, both works me, but both have issues.

       

      Way 1 – casting to inner implementations

      Casting KnowledgeBase and RulesBase to their particular implementations. This does no good to design. What is the point to have all nice and tidy interfaces like KnowledgeBuilder, KnowledgeBase, KnowledgeSession, when you have to cast to their particular impelementations in one crucial step.

       

      Code snipplet:

       

      RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
      factory.name("HelloWorldProcess").packageName("org.jbpm").startNode(1).... //finish definition
      // add process definition to KnowledgeBase
      RuleFlowProcess processDef1 = factory.validate().getProcess();
      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
      KnowledgeBase kbase = kbuilder.newKnowledgeBase();
      ((AbstractRuleBase)((InternalKnowledgeBase)kbase).getRuleBase()).addProcess(processDef1);
      // run the process
      StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
      ksession.startProcess("org.jbpm.HelloWorld");
      

       

       

      Way 2 -  XmlBPMNProcessDumper

      Using XmlBPMNProcessDumper is better on design side but (unnecessary) subsequent marshalling and unmarshalling making it not very effective variant.

       

      Code snipplet:

       

      RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
      factory.name("My process").packageName("org.jbpm").startNode(1).... //finish definition
      // add process definition to KnowledgeBuilder
      RuleFlowProcess process = factory.validate().getProcess();
      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
      kbuilder.add(
       ResourceFactory.newByteArrayResource(
       XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes()),
       ResourceType.BPMN2);
      KnowledgeBase kbase = kbuilder.newKnowledgeBase();
      // run the process
      StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
      ksession.startProcess("org.jbpm.process");
      

      Source: https://community.jboss.org/message/644606

       

      Is there another, official, better way?

      Whatever way, please amend the documentation and include some.

       

      Underline notes

       

      I also checked original Drools Flow documentation - 4.1.3. Defining Processes Using the Process API. It contains 3 examples how to define process, an abundance compared to jBPM manual, but any hint how to add it to KnowledgeBase and run it.

       

      In the jBPM chapter – 5.1.3. - RuleFlowProcessFactory, creating RuleFlowProcess. All of sudden, from jBPM API back to Drools Flow API. Is this area of jBPM under development? Is this going to change? Covered by jBPM only APIs?