Drools always using mvel dialect

702 views
Skip to first unread message

Bruno Freudensprung

unread,
Apr 19, 2016, 5:43:52 AM4/19/16
to Drools Usage
Hi all,

I am using Drools 5.4.0 and I am wondering the reason why Drools may decide to use the "mvel" dialect although "java" has been specified.

I have a rule project running in Eclipse. Now I have removed everything but this rules matching "Entity" objects (having a getFullName() method):

rule "count entities"
    salience
10000
   
when
        $e
: Entity()
   
then
end

When I put a breakpoint on the getFullName() method of Entity, and debug the program, the breakpoint is not hit (demonstrating that it is not called anywhere else).
Now I am modifying the rule:

rule "count entities"
    salience
10000
   
when
        $e
: Entity(this.getFullName() != null)
   
then
end

The breakpoint is now hit and the stack is showing mvel classes:

Entity.getFullName(NameNode.java:82)
sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun
.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun
.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java
.lang.reflect.Method.invoke(Unknown Source)
org
.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1105)
org
.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
org
.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377)
org
.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:143)
org
.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
org
.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
org
.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:107)
org
.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
org
.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:123)
org
.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:116)
org
.mvel2.MVEL.executeExpression(MVEL.java:930)
org
.drools.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:70)
org
.drools.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:49)
org
.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:167)
org
.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:124)
org
.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
org
.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
org
.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
org
.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
org
.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:337)
org
.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:298)
org
.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:888)
org
.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
org
.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269)

Is it the expected behavior? If not, do you have an idea of what I am doing wrong? What is puzzling me the most is I am pretty sure I already have observed JavaDialect* classes (during debugging sessions of other rules).

I can observe the same stack (including mvel) whether I do:

rule
"count entities"
    salience
10000
    dialect
"java"
   
when
        $e
: Entity(this.getFullName() != null)
   
then
end

Or:

rule "count entities"
    salience
10000
    dialect
"mvel"
   
when
        $e
: Entity(this.getFullName() != null)
   
then
end

Or:

dialect "java"
rule
"count entities"
    salience
10000
   
when
        $e
: Entity(this.getFullName() != null)
   
then
end

Any help would be very appreciated!
Thanks!

Bruno.

Mark Proctor

unread,
Apr 19, 2016, 5:55:47 AM4/19/16
to drools...@googlegroups.com
The dialects only control what is inside of evals or consequences.

Mark
--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/b4b7e145-64b0-4f48-94d4-f1685dfee122%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruno Freudensprung

unread,
Apr 19, 2016, 6:35:51 AM4/19/16
to Drools Usage

Thanks a lot Mark! You made my day :-).

I am under the impression it is not a good idea to generalize the use of evals (that is stated in the documentation), but I might give them try anyway since I don't know where is the cursor between "indexation but mvel low evaluation performances" and "no indexation but fast java evaluation performances".

A last question if you don't mind. You you say that there might be a performance difference between:

boundvar1 : SomeType()
boundvar2
: SomeType()
Entity (eval (<<condition based on boundvar1>> && <<condition based on boundvar2>>))


and:

boundvar1 : SomeType()
boundvar2
: SomeType()
Entity (eval (<<condition based on boundvar1>>), eval(<<condition based on boundvar2>>))


(I am wondering if the engine remembers which bound variable has been "injected" into the eval, or if it is simply considering that eval results have the right not to be consistent over time).

Many thanks!

Bruno.

Mark Proctor

unread,
Apr 19, 2016, 8:12:24 AM4/19/16
to drools...@googlegroups.com
On 19 Apr 2016, at 10:43, Bruno Freudensprung <bfreude...@gmail.com> wrote:

Hi all,

I am using Drools 5.4.0 and I am wondering the reason why Drools may decide to use the "mvel" dialect although "java" has been specified.

I have a rule project running in Eclipse. Now I have removed everything but this rules matching "Entity" objects (having a getFullName() method):

rule "count entities"
    salience
10000
   
when
        $e
: Entity()
   
then
end

When I put a breakpoint on the getFullName() method of Entity, and debug the program, the breakpoint is not hit (demonstrating that it is not called anywhere else).
Now I am modifying the rule:

rule "count entities"
    salience
10000
   
when
        $e
: Entity(this.getFullName() != null)
   
then
end

This syntax is not necessary.

Entity ( fullName != null )

Mark
Reply all
Reply to author
Forward
0 new messages