Problem passing objects to a method via the eval statement
by Joshua Undesser
I am curious if anyone else has run into this problem.....It seems like there
is something wrong in the Drools Logic....My issue can be very easily be
recreated in about 5 minutes....
>From eclipse I set up a new drools project. Where DroolTest.java is
defined I create 4 new classes, ClassA, ClassB extends ClassA, ClassC
extends ClassA, and ClassD.
Each of these classes has a default constructor that does nothing, there are
no attributes or anything in these classes just to make the example simple
to reproduce. Ie ClassA looks like this....
package com.sample;
public class ClassA {
public ClassA() {
}
}
Now within the DroolsTest.java source code at line 29 (ie right after the
workingMemory.insert( message ) method call I added 4 more lines which
creates and inserts two objects...
ClassB classB = new ClassB();
ClassD classD = new ClassD();
workingMemory.insert( classB );
workingMemory.insert( classD );
and then the next line would be the
workingMemory.fireAllRules();
as normal.
Then in the sample.drl file I add the following rule and functions
1 rule "Test"
2 when
3
4 $classA : ClassA()
5 $classD : ClassD()
6
7 (or
8 $classB : ClassB(eval($classB == $classA))
9 $classC : ClassC(eval($classC == $classA))
10 )
11
12 eval(retB($classA, $classD))
13
14 then
15 System.out.println("\n\n<<FIRE RULE>>TEST");
16 end
17
18 function boolean retA(Object obj) {
19 System.out.println("Ret Val = " + obj);
20 return true;
21 }
22
23 function boolean retB(Object obj1, Object obj2) {
24 System.out.println("Ret Val 1 = " + obj1);
25 System.out.println("Ret Val 2 = " + obj2);
26 return true;
27 }
So what I am doing is very quick and very simple to reproduce. What is
happening is that when i run the program I am getting a class cast exception
which is very very strange.
At first I thought it was tied only to the OR statement because if I break
the rule into two rules (one for each of the or conditions) it works fine.
But after playing with it a little further I get a lot of other strange
class cast exceptions.
For instance if I replace line 12 (eval(retB($classA, $classD))) with
eval(retA($classA)) it works fine, but if I replace it with
eval(retA($classD)) I get another class cast exception. Another strainge
issue....if switch lines 4 and 5 and keep line 12 as eval(retA($classD))
that previously failed, it now passes, but if I change line 12 back to
eval(retA($classA)) which previously passed it now fails.....
There are a few other combinations that produce errors as well. Just seems
to be a fundamental flaw in the logic and I'm curious if anyone else has
seen this?
Thanks!
Joshua
P.S.
Also I've noticed an issue with the manual example 6.36
This does not seem to work for me
pensioner : (or Person( sex == "f", age > 60 )
Person( sex == "m", age > 65 ) )
But this does
(or pensioner : Person( sex == "f", age > 60 )
pensioner : Person( sex == "m", age > 65 ) )
Although both formats are stated as working in the manual.
--
View this message in context: http://www.nabble.com/Problem-passing-objects-to-a-method-via-the-eval-st...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 8 months
FW: Can I use drools to solve my problem?
by Anstis, Michael (M.)
Posted to forum for a wider audience.
I think you will need to be more specific with your use case.
With kind regards,
Mike
-----Original Message-----
From: kingcd8(a)hotmail.com [mailto:kingcd8@hotmail.com]
Sent: 07 March 2008 15:35
To: Anstis, Michael (M.)
Subject: Can I use drools to solve my problem?
I have a list of products and want to divide this list in other lists
applying the rules, than i want to apply the same rules to this new lists.
So I keep dividing them until no rules are applicable anymore.
Thank you
16 years, 8 months
RuleAgent question
by Eric Miles
Is the rule agent only good for drl files or serialized packages? What
about dsl or ruleflow inclusion? I'm looking through the source and it
seems it doesn't deal with either of items I've identified.
Thanks!
Eric
16 years, 8 months
Auditing Requirement
by manrai.java
Hi,
We have a requirement were in we want to create an audit report after rules
have been executed. For each rule, we need to track Desired Condition
Value(as
specified in when part), Actual Condition Value(value in asserted object)
and so on. This data is to be collected not only for rules which finally got
fired but also for rules which failed.
It would be great if someone can guide me how to achieve this.
Regards
Manrai
16 years, 8 months
RuleAgent(insuranceconfig) EXCEPTION (Thu Mar 06 12:18:45 PST 2008): Was unable to reach server
by SB.Raghavendra
Hi All,
When i ran the sample Insurance Example outside of Eclipse with Tomcat
v6.0.It worked fine but when i am trying to run the same inside the eclipse
and deployed in Eclipse configured tomcat then iam getting the following
error :
RuleAgent(insuranceconfig) WARNING (Thu Mar 06 12:18:45 PST 2008): Was an
error contacting
http://localhost:8080/drools-jbrms/org.drools.brms.JBRMS/package/org.acme....
Reponse header: {null=[HTTP/1.1 404
/drools-jbrms/org.drools.brms.JBRMS/package/org.acme.insurance.base/InsuranceDemo],
Date=[Thu, 06 Mar 2008 20:18:45 GMT], Content-Length=[1195],
Content-Type=[text/html;charset=utf-8], Server=[Apache-Coyote/1.1]}
RuleAgent(insuranceconfig) EXCEPTION (Thu Mar 06 12:18:45 PST 2008): Was
unable to reach server.. Stack trace should follow.
*
java.io.IOException*: Was unable to reach server.
at org.drools.agent.URLScanner.hasChanged(*URLScanner.java:144*)
at org.drools.agent.URLScanner.getChangeSet(*URLScanner.java:108*)
at org.drools.agent.URLScanner.loadPackageChanges(*URLScanner.java:88*)
at org.drools.agent.RuleAgent.checkForChanges(*RuleAgent.java:330*)
at org.drools.agent.RuleAgent.refreshRuleBase(*RuleAgent.java:298*)
at org.drools.agent.RuleAgent$2.run(*RuleAgent.java:438*)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Please assist me to resolve this..
--
Regards,
SB.Raghavendra.
16 years, 8 months
Problem removing rules at run time
by Héron Nicolas
Hello,
I am using drools 4.0.4 on a loyalty system and we have problems
removing rules at run-time.
In fact, it removes the rule (it says) but the effect is no rules is
applied any more.
I join a small eclipse junit project.
Am I making an error in my way of using drools ?
Thanks in advance
Nicolas Héron
Sopra Group Lille
16 years, 8 months
IMPORTANT: if you use dynamic rules and serialization, please READ
by Edson Tirelli
I mentioned that in a few e-mails already, but since some people missed,
I decided to send an specific e-mail for that.
We made a focused effort in the last few weeks to add test cases and fix
a few bugs related to dynamic rules (adding/removing rules at runtime) and
also related to serialization. This is a work in progress, but we already
fixed a few important scenarios in 4.0.x branch.
So, if you make use of these features, we strongly advise you to build
the 4.0.x branch yourself and use that instead of 4.0.4 until we release
4.0.5. Please, do not report bugs related to dynamic rules and serialization
in 4.0.4 without first trying the 4.0.x branch. This will allow us to save
time and focus on any eventual scenario that is still not covered.
If you are a Red Hat subscription customer, you can obviously use the
customer portal to request help with your use case and/or ask for an
official binary build until the next version is released.
For those that don't know, instructions on where to get the sources from
and how to build is in the drools manual. The 4.0.x branch source is
available here:
http://anonsvn.labs.jboss.com/labs/jbossrules/branches/4.0.x/
Thanks,
Edson
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
16 years, 8 months
Performance Issue when multiple drl files loaded
by Mehak
Hi
I have numerous .drl files that contain around 100 rules, in 5 packages.
Please tell me what can be an optimsed solution so that my application
performance is not made to suffer?
I should load all the drl files in and form a Rule Base. After this
depending on my application logic I go on picking up rules from the rule
base to be fired. How does drool sreach for the rule that I specify to be
fired using an agenda filter, does it search the entire Rule base for a
single rule or it has some optimization features?
Please let me know as I have many rules in my application and I want to
optimize searching for a given rule to be fired.
Waiting for an early response
--
View this message in context: http://www.nabble.com/Performance-Issue-when-multiple-drl-files-loaded-tp...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 8 months
Granularity of facts
by Aaron Dixon
Hello, all,
I've designed a simple generic problem to demonstrate our issue. (We
are building a system having difficulty designing fact classes that do
not produce infinite loops and wanted input/discussion from Drools
users.)
I'd like to assert Mothers and Fathers to an engine and then ensure
that each mother and father produces exactly one child, where the
child has the father's first and last name and the mother's middle
name. Of course, I could achieve this in one rule, but I like to break
out the rules so that as my requirements change I can change a single
rule (for example, suppose the requirement changes such that the child
should not get its middle name set to its mother's but its mother's
last name).
My object model is Mother, Father, and Child, but the following rules
produce an infinite execution loop in the rules engine.
I know why this is; it is because i have to update($child) whenever I
modify it--even if I modify a single property on the child. All other
rules that use the child in their LHS will re-fire thinking that the
entire fact has changed. The way to fix this is to not use the Mother,
Father, and Child objects as mutable facts but introduce other Classes
that represent the *properties* first, middle, and last name... in
this case I would produce fact "new MiddleName( $child, "Sue" )", for
example. But this results in less-readable rules.
Why can't Drools allow us to indicate property-updates (and track
facts at the property-level, not at the class level)? Or is there
another suggestion to offer?
Here are the rules:
=====
rule "Every mother and father produce a child"
no-loop
when
$mother : Mother( )
$father : Father( )
eval( $mother.getPartner() == $father )
then
Child child = new Child($mother.getId() + "-" + $father.getId());
child.setMother($mother);
child.setFather($father);
insertLogical( child );
end
rule "Every child gets his/her father's first and last name"
no-loop
when
$father : Father( )
$child : Child( father == $father )
then
$child.setFirst($father.getFirst());
$child.setLast($father.getLast());
update($child);
end
rule "Every child gets his/her mother's middle name"
no-loop
when
$mother : Mother( )
$child : Child( mother == $mother )
then
$child.setMiddle($mother.getMiddle());
update($child);
end
=====
16 years, 8 months