Janino Autoboxing inside drools
by Joe White
According to the Janino Jira in
http://jira.codehaus.org/browse/JANINO-72 autoboxing was supported in
version 2.5.6. It looks like drools 4.0.4 uses Janino 2.5.10. The test
below uses a DRL file that would require autoboxing and it produces a
runtime exception from Janino. Does anybody know of a way to make a
Janino/Drools Autoboxing combination work? I have to use autoboxing and
I would very much prefer to use Janino over MVEL for drl compilation.
Thanks for your help,
Joe
The information below includes the stack trace, the Input java file, the
DRL, and a snippet for the drools setup and execution. The exception is
easy to produce and the info below should be enough to reproduce it.
/********************INPUT JAVA OBJECT *******************************/
package com.sample;
public class Input {
public Double valOne;
public Double valTwo;
public Double getValOne() {
return valOne;
}
public void setValOne(Double valOne) {
this.valOne = valOne;
}
public Double getValTwo() {
return valTwo;
}
public void setValTwo(Double valTwo) {
this.valTwo = valTwo;
}
}
/********************END *******************************/
/********************DRL *******************************/
package test;
import com.sample.Input
dialect "java"
rule "test 293"
when
inputVal : Input()
then
//double valOne = 0;
double deductibleapplied =inputVal.valOne*inputVal.valTwo;
end
/********************END *******************************/
/********************DROOLS SETUP *******************************/
...
PackageBuilderConfiguration pkgBuilderCfg = new
PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = (JavaDialectConfiguration)
pkgBuilderCfg.getDialectConfiguration( "java" );
javaConf.setCompiler( JavaDialectConfiguration.JANINO );
PackageBuilder builder = new PackageBuilder(pkgBuilderCfg);
...
Input input = new Input();
input.setValOne(10.0);
input.setValTwo(1000.0);
workingMemory.insert( input );
workingMemory.fireAllRules();
/********************END *******************************/
/******************** STACK TRACE *******************************/
java.lang.RuntimeException: SNO: Conversion failed
at
org.codehaus.janino.UnitCompiler.binaryNumericPromotion(UnitCompiler.jav
a)
at
org.codehaus.janino.UnitCompiler.compileArithmeticOperation(UnitCompiler
.java)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$39(UnitCompiler.java)
at
org.codehaus.janino.UnitCompiler$7.visitBinaryOperation(UnitCompiler.jav
a)
at org.codehaus.janino.Java$BinaryOperation.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java)
at
org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$12(UnitCompiler.java)
at
org.codehaus.janino.UnitCompiler$2.visitLocalVariableDeclarationStatemen
t(UnitCompiler.java)
at
org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.j
ava)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$3(UnitCompiler.java)
at
org.codehaus.janino.UnitCompiler$2.visitBlock(UnitCompiler.java)
at org.codehaus.janino.Java$Block.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at
org.codehaus.janino.UnitCompiler$1.visitPackageMemberClassDeclaration(Un
itCompiler.java)
at
org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java)
at org.codehaus.janino.Compiler.compile(Compiler.java)
at
org.drools.commons.jci.compilers.JaninoJavaCompiler.compile(JaninoJavaCo
mpiler.java:174)
at
org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJa
vaCompiler.java:51)
at
org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.
java:332)
at
org.drools.compiler.DialectRegistry.compileAll(DialectRegistry.java:60)
at
org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:308)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java
:167)
at com.sample.SimpleTester.readRule(SimpleTester.java:62)
at com.sample.SimpleTester.main(SimpleTester.java:23)
16 years, 8 months
FW: Rule match count?
by Brian Olson
Hi,
Does anyone know of a way to know when the rules are fired against
working memory, if it is possible to know how many rules matched? I
want to use Drools for coupons in a pricing application. If I don't
match any coupons (in my rules file), I'd like to know so I can use a
default one.
Any insight is appreciated.
Brian
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
16 years, 8 months
From 4.0.6 to 4.0.4 to 4.0.3
by Chris Woodrow
Hi,
I would to share our experience about recent versions of Drools.
We found out that 4.0.6 was out on last wednesday, so we decided to move up
from 4.0.3 to 4.0.6. We made a few tests but we counted on the fact that
backward compatibility was provided. On friday, I went on Drools website and
found out that version 4.0.6 was replaced by 4.0.4 whithout any more
explaination, I made a research on this list to find out that you had to
make a roll back. At the same time we found out a drools bug on our app :
Caused by: java.lang.NullPointerException
at
org.drools.base.evaluators.ObjectFactory$ObjectEqualsComparator.equals(ObjectFactory.java:561)
at
org.drools.base.evaluators.ObjectFactory$ObjectNotEqualEvaluator.evaluate(ObjectFactory.java:158)
at
org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:61)
at
org.drools.rule.LiteralConstraint.isAllowed(LiteralConstraint.java:82)
at
org.drools.reteoo.AccumulateNode.assertTuple(AccumulateNode.java:156)
at
org.drools.reteoo.CompositeTupleSinkAdapter.propagateAssertTuple(CompositeTupleSinkAdapter.java:30)
at org.drools.reteoo.FromNode.assertTuple(FromNode.java:90)
at
org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple(SingleTupleSinkAdapter.java:20)
at org.drools.reteoo.JoinNode.assertTuple(JoinNode.java:107)
at
org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple(SingleTupleSinkAdapter.java:20)
at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:151)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:140)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:909)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:881)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:682)
We had to deploy our app on friday, so we decieded to rollback to 4.0.4 to
find out that we had the same error. So we decided to rollback to 4.0.3, I
went to the download section of your site, and found out that previous
versions where just unavailable, which is unacceptable. Obviously, I found
it on our SVN, but I wasn't very happy about this.
Here are my conclusions :
- We are not going to change our version of Drools soon
- Please give us access to previous versions
Chris
16 years, 8 months
Question on setting globals
by Seema Richard
Hi,
I've been reading the Drools documentation where it is mentioned that
"It is strongly discouraged to set (or change) a global value from
inside your rules. We recommend to you always set the value from your
application using the working memory interface." What is the reason for
this?
Also, in the example shown, are you not modifying the global? Isn't it
what is discouraged?
* global java.util.List myGlobalList;
*
* rule "Using a global"
* when
* eval( true )
* then
* myGlobalList.add( "Hello World" );
* end
Thanks,
Seema
16 years, 8 months
Re: [rules-users] Feature request
by Steven Williams
I also have this requirement. I spoke to Michael Neale about it and he
thought that it shouldn't be too difficult. Michael, I wasn't sure if you
were going to add the feature request or if you want me to do it?
cheers
Steve
On Thu, Apr 10, 2008 at 9:30 AM, Brian Trezise <
Brian.Trezise(a)intellidata.net> wrote:
> This is a feature request, or if the feature already exists, a request
> that somebody let me know :)
>
>
>
> I have a set of rules that heavily depend on regular expressions to
> operate. The regular expression is matched on the LHS of the rule, and then
> passed to another object for additional processing in the RHS of the rule.
> We're looking at a few hundred rules here. Here's the problem – because of
> needing to use the regexes twice, I have stored them in a separate container
> class as public static final String variables; however what we really want
> to do is to be able to make a modification to either the regex or the rules
> themselves, hot deploy the changes to the rule, and have everything work.
> We specifically do not want to have to try hot-deploying or re-compiling
> classes due to the potential issues that can arise. As it stands now it's
> looking like we are going to have to endure a pretty heavy maintenance
> burden by changing the rule, hot deploying, then later in the evening
> redeploying the java code and rebooting the server whenever we make a
> change.
>
>
>
> The ideal solution for this problem would be if we could set
> package-scoped variables in the .drl file, outside of the rules. For
> example, at the top of the drl file, below the import statements, if we
> could write something like the following:
>
> let String THIS_STRING = "this regular expression";
>
>
>
> and then in the background when the rule classes are generated, have them
> be declared as static final/constant variables. This way they could be used
> on either side of the rule, but if a change is made the RuleAgent will see
> that and overwrite the old version of the rule package and fact processing
> would be able to continue uninterrupted.
>
>
>
> If anybody has any suggestions on a work around, I would be appreciative.
>
>
>
> Oh, and thanks to everybody for helping me get the RuleAgent to work :)
>
> *___________________________________________________
> Brian Trezise
> Staff Software Engineer
> IntelliData, Inc
> *3173 s. uravan way
> aurora, colorado 80013
> T: 720.524.4864
> brian.trezise(a)intellidata.net
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
Steven Williams
Supervising Consultant
Object Consulting
Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
steven.williams(a)objectconsulting.com.au
www.objectconsulting.com.au
consulting | development | training | support
our experience makes the difference
16 years, 8 months
Hot Deployment
by Brian Trezise
In the What's New? Section of the Drools 4.0 documentation there is a
reference in 1.1.2 to a "Rules Engine Agent for hot deployment and BRMS
integration". This would be ideal for the application I am currently
developing. However, this is the only mention of this agent anywhere in the
documentation. Does anybody know anything about this, how to use it, any
documentation about it?
Thanks,
___________________________________________________
Brian Trezise
Staff Software Engineer
IntelliData, Inc
3173 s. uravan way
aurora, colorado 80013
T: 720.524.4864
brian.trezise(a)intellidata.net
16 years, 8 months
Working with Maps
by Gerald Cantor
I have a Map in working memory. The Map has Strings as keys and Integers as
values. It has 7 keys (REG301, REG302, ... REG307). I'm looking for a way to
incorporate the following into the LHS of a rule:
For keys 301, 302, 303, compute the total of the Integer values (total 1)
For keys 301, 302, 303, compute the number of keys that have greater than 0
values (total 2)
Divide total 1 by total 2 (if total 2 > 0) and check against a range
For keys 304, 305, 306, 307, compute the total of the Integer values (total
3)
For keys 304, 305, 306, 307, compute the number of keys that have greater
than 0 values (total 4)
Divide total 3 by total 4 (if total 4 > 0) and check against a range
I have not seen a way to collect / sum over select Map elements.
Any insight as to how I would compute the above totals using collect / sum
would be very much appreciated.
Thanks in advance,
Gerald
--
View this message in context: http://www.nabble.com/Working-with-Maps-tp16597566p16597566.html
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 8 months
Order of operations
by Joe White
I have a question regarding order of operations in the consequence of a
rule when using the mvel dialect. When executed the Drl below provides
Right =30.0 and Wrong =140.0. The only difference is the parens around
the multiplying expressions, which shouldn't be necessary given order of
operations. Is this a problem with the drools/mvel interaction or is it
completely an issue with mvel?
Is the general expectation that all expressions must be completely
scoped by parens when using mvel?
package test;
dialect "mvel"
rule "test 11"
when
then
double rightVal=((10-5)*2) + (5*(8-4));
double wrongVal=(10-5)*2 + 5*(8-4);
System.out.println("Right ="+rightVal);
System.out.println("Wrong ="+wrongVal);
End
After execution:
Right =30.0
Wrong =140.0
Thank you for all of your help. We are using drools 4.0.4.
Joe
Also, I haven't figured out how it arrives at 140. The following format
also produces 140, which seems a little more strange.
double wrongVal=10-5*2 + 5*8-4;
16 years, 8 months
OT:Order of operations
by Hehl, Thomas
Anyone else use Please Excuse My Dear Aunt Sally? (Parentheses,
Exponentiation, Multiplication, Division, Addition, Subtraction)
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Wednesday, April 09, 2008 2:39 PM
To: Rules Users List
Subject: Re: [rules-users] Order of operations
Hi Joe,
It seems someone skipped the elementary math lessons at school... :(
Will open a JIRA for that.
[]s
Edson
2008/4/9 Joe White <Joe.White(a)recondotech.com
<mailto:Joe.White@recondotech.com> >:
I have a question regarding order of operations in the consequence of a rule
when using the mvel dialect. When executed the Drl below provides Right
=30.0 and Wrong =140.0. The only difference is the parens around the
multiplying expressions, which shouldn't be necessary given order of
operations. Is this a problem with the drools/mvel interaction or is it
completely an issue with mvel?
Is the general expectation that all expressions must be completely scoped by
parens when using mvel?
package test;
dialect "mvel"
rule "test 11"
when
then
double rightVal=((10-5)*2) + (5*(8-4));
double wrongVal=(10-5)*2 + 5*(8-4);
System.out.println("Right ="+rightVal);
System.out.println("Wrong ="+wrongVal);
End
After execution:
Right =30.0
Wrong =140.0
Thank you for all of your help. We are using drools 4.0.4. <http://4.0.4.>
Joe
Also, I haven't figured out how it arrives at 140. The following format also
produces 140, which seems a little more strange.
double wrongVal=10-5*2 + 5*8-4;
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org <mailto:rules-users@lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users
<https://lists.jboss.org/mailman/listinfo/rules-users>
--
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 <http://www.jboss.com>
16 years, 8 months