[rules-users] "Exists" CE behaviour
Viswanathan Nageswaran
visu.nageswaran at in.ibm.com
Mon Jul 13 05:06:19 EDT 2009
Chivotario,
>From what I understand, the activation of rules happen as facts are
inserted into the working memory; hence it is important for the session to
be begun against a knowledge base that has the rule packages loaded before
the facts are inserted.
-Visu
Chivotario Martin
<chivotario at gmail
.com> To
Sent by: rules-users at lists.jboss.org
rules-users-bounc cc
es at lists.jboss.or
g Subject
[rules-users] "Exists" CE behaviour
13/07/2009 14:11
Please respond to
Rules Users List
<rules-users at list
s.jboss.org>
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.
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list