Drools 6.1 rule flow usage (rules not triggered at teh right ruleflow-group

822 views
Skip to first unread message

yan...@inventsolv.com

unread,
Sep 18, 2014, 6:40:54 PM9/18/14
to drools...@googlegroups.com
All, I am learning Drools 6.1 and I need to use rule flow.  I have the Drools 6.1 distribution final installed and installed Eclipse Drools plugin.

I created sample rules and tests, everything worked fine.  Then I added a rule flow, which is a file ending with "bpmn".  So I think this is a drools jbpm artifact.  I configured the right "ruleflow-group" value in my rules.  When I run the test, I got exception like below:

java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.compiler.compiler.BPMN2ProcessProvider'

THen I added 4 JARs from the droolsjbpm-integration-distribution-6.1.0.Final zip file to the drools project:
    <classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-bpmn2-6.1.0.Final.jar"/>
    <classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-flow-builder-6.1.0.Final.jar"/>
    <classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-workitems-6.1.0.Final.jar"/>
    <classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-flow-6.1.0.Final.jar"/>

no more runtime exception.  I was able to invoke the rule flow from Java code but none of the rules in the ruleflow-group was triggered.  If I use kSession.fireAllRules() to skip rule flow, the rules were executed.  I wonder if there is anything missing.   Below are sections of my code.

Thanks.

Daniel

Sample.drl

rule "AnyTime"
    ruleflow-group "ruleTask1"
    salience 10000

    then
        System.out.println( "Rule Flow Triggered");
        System.out.println( "Output Size is " + list.size());
end

Java code:

            KieServices ks = KieServices.Factory.get();
            KieContainer kContainer = ks.getKieClasspathContainer();
            KieSession kSession = kContainer.newKieSession("ksession-rules-stateful");
            List list = new ArrayList();
            kSession.setGlobal("list", list);
           
            kSession.addEventListener( new DefaultAgendaEventListener() {
                public void afterMatchFired(AfterMatchFiredEvent event) {
                    super.afterMatchFired( event );
                    System.out.println( event );
                    }
                });
            kSession.addEventListener( new DebugRuleRuntimeEventListener() );
           
            Message message = new Message();
            message.setMessage("Hello World");
            message.setStatus(Message.HELLO);
            FactHandle messageHandle = kSession.insert(message);
           
            //int ruleFired = kSession.fireAllRules();
            kSession.startProcess("mainFlow1");
            System.out.println("rules fired and In the output, the list size is " + list.size());
            System.out.println("Message status is " + message.getStatus() + message.getMessage());
            kSession.delete(messageHandle);
            kSession.dispose();



DINGQIANG YANG

unread,
Sep 19, 2014, 12:15:44 AM9/19/14
to drools...@googlegroups.com
I resolved it.  Besides calling Session.startProcess("mainFlow1"), I also need to call kSession.fireAllRules(). 


--
You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/866akUb-mr8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/4269a59d-0d5b-41ab-8dd5-b036a5e4d76a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages