[rules-users] "Exists" CE behaviour

Chivotario Martin chivotario at gmail.com
Mon Jul 13 04:41:44 EDT 2009


Hi ,

I'm trying to use the *Exists *keyword within my rules with the following
snippet :

// Create a session
KnowledgeBaseConfiguration config =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
((RuleBaseConfiguration)config).setRuleBaseUpdateHandler( null ); *
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();

// Add some objects
for (int i=0; i<5; i++) {
    session.insert(new Foo());
}

// Add a DRL to the kbase
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "test/existsTest.drl" ),
ResourceType.DRL);
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

// Fire rules
int fireCount = session.fireAllRules();


*existsTest.drl* :

rule "existsTest"
    when
        exists (Foo());
        //not ( not ( Foo() ) ); (2)
    then
        System.out.println("Rule fired...");
end

When launched , the rule is not fired (no messages , fireCount 0), but it is
when changing
exists with a double not condition (2).
If the working memory is populated after adding the rules file, the exists
CE works as expected.
* I've used no RuleBaseUpdateHandler preventing automatic activations to be
executed so fireAllRules can be used to get the fireCount, but commenting
this line out doesn't change the results.

Probably i'm doing something wrong so a little help would be very
appreciated.

Regards,
Manuel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090713/d4ba2b1b/attachment.html 


More information about the rules-users mailing list