AgendaFilter not working as expected
by Brian Enderle
I have many rules in which I have named the various rules by the level at
which the rules are to be fired, for instance:
rule "LevelOne: Name cannot be null"
when
Person(firstNm == null)
then
<log an error>
end
rule "LevelTwo: Street cannot be null"
when
Person(street== null)
then
<log an error>
end
Within my Java code I first insert all objects into a statefulSession, then
add all my globals. I then use a switch statement to call different methods
to perform the various levels of validation (ie: performLevelOneValidation(),
performLevelTwoValidation(), etc.). Each of these methods calls a common
method, performValidation(String validationLevel) which I want to use to fire
the rules of just the validation level supplied. I am doing this with:
statefulSession.fireAllRules(new RuleNameStartsWithAgendaFilter
(validationLevel));
In some cases I need to perform multiple levels of validation (if anything
over Level One validation is called, all preceding levels also need to be
validated) and need to perform them in order for reporting purposes. My code
correctly calls my performaValidation() method with the correct
validationLevel but the only rules that fire are those with "LevelOne" in the
rule name.
I know the data, the rules, the globals, etc are all present for firing rules
in a level other than level one and that I should get some mathces to my rules
but I am not getting anything to match outside of Level One.
I can only assume that the rules other than Level One are not firing and that
I am missing something within my code that fires the rules for other levels.
Am I misunderstanding how the AgendaFilter works? Should I be using something
else like agenda-group to accomplish this segregation of rules?
Also, my rules and data objects do not change as the rules are run. I simply
display a list of errors found. Would it benefit me to use sequential mode
and would this help me in trying to segerate the rules into various levels?
Thanks in advance,
Brian Enderle
17 years, 3 months
Rule compilation errors under heavy load
by Dean Jones
Hello folks,
I'm experiencing some odd behaviour from Drools (or maybe the Eclipse
compiler) when load-testing my application, and wondered if anyone
else had experienced the same issue. I have a web service which, for
every request, loads in rules from the database, creates a
org.drools.lang.descr.PackageDescr and then uses this to create a
org.drools.rule.Package. The code is something like:
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
PackageBuilder builder = new PackageBuilder(conf);
PackageDescr packageDescr = new PackageDescr("MyRulebaseName");
populatePackageDescr(packageDescr);
builder.addPackage(packageDescr);
Package _package = builder.getPackage();
return _package;
This code gets run every request. The populatePackageDescr() method
adds imports, globals, functions and rules to the PackageDescr. My
load-test just repeatedly calls the same rulebase, so
populatePackageDescr() will be doing exactly the same thing for each
request. Occasionally (normally once or twice per 100 requests) I get
a rule compilation error (the exact error varies from request to
request) whereas most of the time the same rule compiles fine. This
makes me suspect a thread-safety issue in either the PackageBuilder or
the compiler (I'm using the eclipse compiler).
Initially, I suspected a problem in my
populatePackageDescr(packageDescr) method, but I think I've ruled this
out. There is nothing stateful in this method, and I've tried dumping
the XML representation of the packageDescr immediately after
populating it; it looks fine to me and is exactly the same whether
compilation succeeds or and fails.
Has anyone done this kind of thing successfully under a heavy load?
Thanks,
Dean.
17 years, 3 months
global Service service
by hypnosat7
Hi,
I'm using Drools 4.0.1 snapshot but the Global Data View seems not work :
this is my rule :
global Service service
global Parking parking
rule "gestion file d'attente"
when
v:Vehicule( age <= 3 ) from service.getVehicules()
then
parking.garer(v); // add vehicule to parking
end
1) But in debug mode, in the Global Data View I have this message :
"The selected working memory has no globals defined"
2) And In the Agenda View I don't see any activation, I see
"MAIN[focus]:...... (id=1370), is it normal ?
when I check my parking I find a vehicule, so the rule was executed!
Thanks
--
View this message in context: http://www.nabble.com/global-Service-service-tf4316159.html#a12289656
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 3 months
Infinite Recursion, with no-loop also
by Arjun Dhar
Hi,
This problem needs to be solved conceptually before technically.
Assuming (I can't use Agenda Groups in decision tables).
SUMMARY
-------
Some rules evaluate some logic and pass it to a rule which aggregates the logic
to give the final outcome. Now that requires use of update. (or insert)
Before I get into the details as I usually do; one quick Question:
Q) Are recursion a result of update() or can they be caused by insert()???
because i have an alternative hypothesis using insert() (described in my
solution section)
DETAILS
--------
So exact scenario in 'Rules' is below; and this causes infinite-recursion.
Note: I've solved it but I'm looking for something more sophisticated or clean.
My current solution is written below after the problem is described in rules.
rule "Main"
no-loop true
when
cntct: Contact(initialized==true)
eval(cntct.extendedProperty("Table1_Output",true) ==true)
then
...
end
# setExtendedProperty = hashMap
rule "Rule_1"
no-loop true
when
cntct: Contact(initialized==true)
cfg_tab1: BooleanConfiguration(value!=false, param=="x1")
then
cntct.setExtendedProperty("Table1_Output", false);
...
update(cntct);
end
rule "Rule_2"
no-loop true
when
cntct: Contact(initialized==true)
cfg_tab2: BooleanConfiguration(value!=false, param=="x2")
then
cntct.setExtendedProperty("Table2_Output", false);
...
update(cntct);
end
rule "Rule_3"
no-loop true
when
cntct: Contact(initialized==true)
cfg_tab3: BooleanConfiguration(value!=false, param=="x3")
then
cntct.setExtendedProperty("Table3_Output", false);
...
update(cntct);
end
-----------------------
My solution: take one of the rules:
rule "Rule_3"
no-loop true
when
cntct: Contact(initialized==true)
cfg_tab3: BooleanConfiguration(value!=false, param=="x3")
## Line below filters & restrcits the execution to once only per table ##
eval(cntct.extendedProperty("Table1_Output",true) ==true)
then
cntct.setExtendedProperty("Table3_Output", false);
...
update(cntct);
end
Criticism of my own solution:
1. This solution, will only allow one rule to fire per table (For each rule 1,
there is a table of rules like rule 1, similarly for rule 2 type rules there is
a table if you just play with true and false values in those rules)?
Even with Agenda-Groups; again how do you do an update() once you know the
rules of the agenda have all fired??? Can we program that in the rules itself??
2. Can i use insert instead of update(cntct) and insert another Object into
working memoy and evaluate that as part of a condition to prevent recursion?
I feel adding conditions to control activations and sequence as a path of long
term confusion, so can you please provide a more sophisticated approach or re-
evaluate my approaches to the least?
Thanks,
Arjun
17 years, 3 months
use EObject for facts?
by jack wu
Hi, I am wondering if it is possible to use the EMF EObject, instead of java beans as facts. or does it require a lot of effort to make that happen.
what EObject has is very similar to what the Fact interface requires:
Object getFieldValue(String name);
void setFieldValue(String name,
Object value);
when a java beans got passed in as fact, do we internally instantiate a Fact object to represent the java bean? at runetime, when rules are evaluated, do all the calls to get fact field values go through the Fact interface? using getFieldValue()?
thanks.
jack.
____________________________________________________________________________________
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more.
http://mobile.yahoo.com/go?refer=1GNXIC
17 years, 3 months
help, Unable to create Field Extractor for ....
by grupo cft ing sostware
I meet working a simple example to interiorize with jboss rules and I obtain
the following error:
Exception in thread "main" org.drools.rule.InvalidRulePackage: Unable to
create Field Extractor for 'CantSegundos' : [Rule name=Valida Duracion nula,
agendaGroup=MAIN, salience=0, no-loop=false]
*org.drools.RuntimeDroolsException*: *org.drools.RuntimeDroolsException*:
java.lang.NullPointerExceptionUnable to create Field Extractor for
'CantSegundos' : [Rule name=valida Duracion , agendaGroup=MAIN, salience=0,
no-loop=false]
*
org.drools.RuntimeDroolsException*: *org.drools.RuntimeDroolsException*: *
java.lang.NullPointerException
*
at org.drools.rule.Package.checkValidity(*Package.java:408*)
at org.drools.common.AbstractRuleBase.addPackage(*AbstractRuleBase.java:288*
)
at prototipo.Prueba.main(*Prueba.java:27*)
the class main is:
*
public* *static* *final* *void* main(String[] args) *throws* Exception {
* final* PackageBuilder builder = *new* PackageBuilder();
* *builder.addPackageFromDrl( *new* InputStreamReader( Prueba.*
class*.getResourceAsStream( "regla.drl" ) ) );
* final* RuleBase ruleBase = RuleBaseFactory.*newRuleBase*();
* ruleBase*.addPackage( builder.getPackage() );
* final* StatefulSession session = ruleBase.newStatefulSession();
* *Integer segundos = *new* Integer(5);
* *validaciones valida = *new* validaciones();
* *valida.setCantSegundos(segundos);
* *session.insert( valida);
* *session.fireAllRules();
*in the rules is:*
*
package prototipo
import prototipo.validaciones;
rule "Valida Duracion nula"
when
v : validaciones(CantSegundos == 0)
then
v.setResultado("I");
System.out.println( "obtenemos" + v.getResultado() );
end
rule "valida Duracion "when
v : validaciones(CantSegundos > 0)
then
v.setResultado("S");
System.out.println( "obtenemos" + v.getResultado());
end
**
Thank you for helping me.
***
**
17 years, 3 months
Can't merge packages with different names. -- PackageException
by Krishnan
Hi All,
When I migrated to use the latest 4.0 GA release jars, loading of my rule
files fails.
I have basically split my rule files into hierarchies as below :-
Directory structure
rules\a\A.drl
rules\b\B.drl
A.drl
com.company.a;
some rules ...
B.drl
com.company.b;
some rules ...
Java code to load the rules
//read in the source
final Reader source = new InputStreamReader(new FileInputStream(ruleFile));
//this will parse and compile in one step
//NOTE: There are 2 methods here, the one argument one is for normal DRL.
builder.addPackageFromDrl(source);
builder is created as follows :-
private PackageBuilder getPackageBuilder() {
//Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can also be used...
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = (JavaDialectConfiguration)
conf.getDialectConfiguration( "java" );
javaConf.setJavaLanguageLevel("1.5");
PackageBuilder builder = new PackageBuilder(conf);
return builder;
}
Exception I get is as follows :-
EXCEPTION [org.drools.compiler.PackageBuilder$PackageMergeException: Can't
merge packages with different names. This package:
com.makesys.fs.is.dnpiac.vendorBehaviour.snmp - New package:
com.makesys.fs.is.dnpiac.vendorBehaviour.cli]
STACK [org.drools.compiler.PackageBuilder$PackageMergeException: Can't merge
packages with different names. This package:
com.makesys.fs.is.dnpiac.vendorBehaviour.snmp - New package:
com.makesys.fs.is.dnpiac.vendorBehaviour.cli
at org.drools.compiler.PackageBuilder.validatePackageName(
PackageBuilder.java:299)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:226)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java
:160)
at com.makesys.fs.is.dnpiac.DNPIACConfigReaderHelper.loadRuleFile(
DNPIACConfigReaderHelper.java:359)
at com.makesys.fs.is.dnpiac.DNPIACConfigReaderHelper.loadRuleFiles(
DNPIACConfigReaderHelper.java:426)
at com.makesys.fs.is.dnpiac.DNPIACConfigReaderHelper.loadRuleFiles(
DNPIACConfigReaderHelper.java:380)
at com.makesys.fs.is.dnpiac.DNPIACConfigReaderHelper.initializeParams(
DNPIACConfigReaderHelper.java:531)
at com.makesys.fs.is.dnpiac.DNPIAutoConfigurationAdapter.collect(
DNPIAutoConfigurationAdapter.java:61)
at com.makesys.fs.app.adapter.BaseAdapter.activate(BaseAdapter.java:177)
at com.makesys.fs.app.adapter.UnicastAdapterImpl.activate(
UnicastAdapterImpl.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java
:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(
TCPTransport.java:707)
at java.lang.Thread.run(Thread.java:595)
]
Not sure what the issue is. Any ideas ?
TIA,
Krishnan
--
Sivaramakrishna Iyer Krishnan (Anand)
Never assume the obvious is true.
- William Safire
17 years, 3 months
Simple rulebase not behaving as expected
by Dean Jones
Hi,
I have the following simple rulebase:
package org.drools.examples
rule "Hello World"
when
o : Object( )
then
System.out.println("Hello world (o=" + o + ")");
end
rule "Goodbye World"
when
not Object( )
then
System.out.println("Goodbye cruel world");
end
and the following code:
public class TestReadRuleFile {
public static void main(String[] args) throws Exception {
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(
new InputStreamReader(
TestReadRuleFile.class.getResourceAsStream("test.drl")));
Package pkg = builder.getPackage();
RuleBase rulebase = RuleBaseFactory.newRuleBase();
rulebase.addPackage(pkg);
StatefulSession session = rulebase.newStatefulSession();
session.fireAllRules();
}
}
which produces the following output:
Hello world (o=org.drools.reteoo.InitialFactImpl@4dde85f0)
I expected the "Goodbye World" rule to fire, as there should not be
any Objects in the working memory. If I change my code to insert an
object into the working memory as follows:
session.insert(new Object());
I now get the following output:
Hello world (o=org.drools.reteoo.InitialFactImpl@4dde85f0)
Hello world (o=java.lang.Object@17ba38f)
In this case, I expected the "Hello World" rule to fire only once. Any
thoughts on what I'm doing wrong here?
Thanks,
Dean.
17 years, 3 months
Migration guide
by Krishnan
Hi all,
Is there a migration guide from 4.0 MR2 to 4.0 GA ?. I had got the code
working in 4.0 MR2 and thought it would be
as easy as just changing the jars. But it is not. Many things have changed.
(a) I modified the assert() into insert()
Is there anything else I should know about ?
One of my failure is for the method clearAgenda() is undefined for the type
KnowledgeHelper.
Previously, in the rules file (.drl), once a rule has executed and I know I
am done, I would call drools.clearAgenda() to
expedite the processing, this does not work anymore. Has the functionality
changed ?
Any help will be appreciated ?.
thanks,
Krishnan.
--
Sivaramakrishna Iyer Krishnan (Anand)
Never assume the obvious is true.
- William Safire
17 years, 3 months
Rules with 'From' condition with another not using From causes problem
by Arjun Dhar
Test case:
Write a Rule that uses a From clause and on another object does not use a from
clause:
example:
#From row number: 28
rule "Rules_28"
when
cntct: Contact(initialized==true)
config: BooleanConfiguration(value==true) from
meta.getConfiguration(cntct.getClient(), "Param1")
pref: Relation(contact==cntct, type=="old") or (eval
(false==true) and not Relation(contact==cntct, origin=="old"))
then
System.out.println("Fired 28");
end
If All 3 are true:
1. Delete Condition 2 --> Rule fires
2. Delete COnditon 3 (But keep 2) --> Rule fires
3. Keep 2 & 3 (with 1) --> Rule does not fire
Whats strage is that conditon 1 does not use from and it works with condition 2
without any problem, but when 2 & 3 are there together the rule does not work.
Please see if it is a bug
Am posting on JIRA
17 years, 3 months