1) In order to set the value of a
global from a rule's RHS, you have to do somehting like this
drools.getKnowledgeRuntime().setGlobal( "RULES_MATCHED",
newValue );
The reason is that the rule's RHS sees a reference to the
original global... a local variable with the
same name initialized appropriately. Something like
RULES_MATCHED = 0 will only change the local
reference, not modify the global.
2) The KnowledgeAgent supports declared types incrementally..
(Esteban and I spent a lot of time to make
that work), but you have to set a flag in the KA's
configuration:
KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty(
"drools.agent.useKBaseClassLoaderForCompiling", true );
The "incremental" mode (newInstance=false) only ensures that the
existing KnowlegeBase is updated,
tue "useKBaseClassLoaderForCompiling" will ALSO make sure that,
as the new resources are compiled
by a KnowledgeBuilder, this is initialized with the KB's
classloader, which has the classes for the declared types.
3) I have proposed a fix for the issue you reported the other
day... actually two in one.
- 3a ) Runtime exceptions will be catched,
- 3b ) you **WILL NOT** be able to use primitive types with
globals anymore.. (which would result in a RTE anyway)
Hope this help
Best
Davide
On 09/20/2013 02:18 AM, De Rooms Brecht wrote:
Dear Drools Users,
I am building a network server for drools since the existing
drools-server did not meet my requirements. Since I recently
found a bug and find the people here very helpful I'll try to
explain another issue I encountered in the hope that it improves
drools 5.6 and 6.0.
I noticed that declared types and globals don't seem to be found
when you access them from a rule that was written in a different
file. For the declared types I hacked around this issue by
preprocessing the files and placing every declared type at the
top of each file that needs it. For globals this is of course
not possible.
An example is shown below. File1 is loaded from the moment the
agent starts up, then file2 is loaded.
There is a difference when the knowledgeAgent detects the two
files at once or one by one. In this case the KnowledgeAgent
detects one file and then a few minutes later the other file and
compiles them completely separately.
The idea is to keep how many rules are matched of a certain type
in a global.
FILE1: global_rules_matches.drl
----------------------------------------------
package ellipsoidfacts
// declare
global Integer RULES_MATCHED;
// initialize global
rule "initRULESMATCHED"
salience 999
when
then
RULES_MATCHED = 0;
end
FILE2: testrule.drl
----------------------------------------------
package ellipsoidfacts
rule "Gesture_lefthook"
when
// ... any precedent rules ...
then
System.out.println("matched gesture: lefthook"+
RULES_MATCHED);
end
In this particular case, my rule is not matched. I load these
rules using a changeset xml, my knowledgeagent is set to
incremental (but either doesnt work).
The same happens when I declare types in FILE1 and use them in
FILE2. When I write the type declaration in both files it works
perfectly.
Being the same package I assumed that these two scenarios should
work. Am I doing something wrong or is the agent not supposed to
work like this and should a package be in one file?
Kind Regards,
De Rooms Brecht
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users