<br><font size=2 face="sans-serif">Edson,</font>
<br><font size=2 face="sans-serif"><br>
Thanks for the quick response!</font>
<br>
<br><font size=2 face="sans-serif">I'm using Drools 4.0.7 and mvel 1.3.1</font>
<br>
<br><font size=2 face="sans-serif">Thanks for the tip about packages and
rulebases. &nbsp;I'll make sure to change that in our code. &nbsp;</font>
<br>
<br><font size=2 face="sans-serif">As far as changing the accumulate to
collect, I can easily work around that selector returning a list of PotentialMatches
instead of Integers. &nbsp;I made that change and have been unable to create
the ClassCastException since. &nbsp;I'm still not certain that the problem
is resolved due to its random nature, but I'm hoping that it is patched
enough for now until we can make the rulebase change you mentioned.</font>
<br>
<br><font size=2 face="sans-serif">Thanks for the info about Drools 5.
&nbsp;I'm currently in the process of converting to Drools 5.</font>
<br>
<br><font size=2 face="sans-serif">You're right the eval does look odd,
but it is working for the time being. &nbsp;This rule is in one of the
first features I implemented using Drools, so it is probably not done in
the best way possible. &nbsp;I'll keep an eye on it if I do not get this
issue resolved some other way.</font>
<br>
<br><font size=2 face="sans-serif">Thanks again!</font>
<br><font size=2 face="sans-serif"><br>
</font><font size=3>Steve Ronderos </font>
<br>
<br><tt><font size=2>rules-users-bounces@lists.jboss.org wrote on 06/23/2009
11:09:48 AM:<br>
<br>
&gt; [image removed] </font></tt>
<br><tt><font size=2>&gt; <br>
&gt; Re: [rules-users] Class Cast Exception in Drools 4 Generated &nbsp;<br>
&gt; Accumulate Method</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; Edson Tirelli </font></tt>
<br><tt><font size=2>&gt; <br>
&gt; to:</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; Rules Users List</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; 06/23/2009 11:29 AM</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; Sent by:</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; rules-users-bounces@lists.jboss.org</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; Please respond to Rules Users List</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; <br>
&gt; &nbsp;&nbsp; Steve,<br>
&gt; <br>
&gt; &nbsp;&nbsp; What versions of MVEL and Drools are you using?<br>
&gt; &nbsp;&nbsp; Comments:<br>
&gt; <br>
&gt; * You can not share packages between rulebases. You can share <br>
&gt; rulebases among sessions. So, I strongly advise you to change your
<br>
&gt; application to build the rulebase once, and have the web sessions
<br>
&gt; only create the rule session every time... not the whole rulebase.
<br>
&gt; Since packages have their own classloaders and everytime you create
<br>
&gt; a rulebase you merge such classloaders, the problem might happen <br>
&gt; (CCE) exactly at the time you are creating the rulebase <br>
&gt; concurrently. Drools 5 allows you to share packages, although I <br>
&gt; still prefer to not do it and share only the rulebase.<br>
&gt; <br>
&gt; * You can not use collect in this case, because you are creating a
<br>
&gt; list of $slot, not a list of PotentialMatch. Although, it is <br>
&gt; extremely easy to create an accumulate function for that. Drools 5
<br>
&gt; includes 2 accumulate functions: collectSet and collectList for <br>
&gt; that. If you want, just get the class from Drools 5, fix the imports<br>
&gt; to use the classes from Drools 4 and use it. Except for the <br>
&gt; &quot;imports&quot; you should not have any problem. Your rule would
look like:<br>
&gt; <br>
&gt; <br>
&gt; rule &quot;My Rule&quot; <br>
&gt; &nbsp; &nbsp; salience 50 <br>
&gt; &nbsp; &nbsp; dialect &quot;java&quot; <br>
&gt; &nbsp; &nbsp; no-loop true <br>
&gt; &nbsp; &nbsp; when <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $module : Module( selected == false, required
&gt; 1, $size : required )<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $list : List( ) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from accumulate(
PotentialMatch( module == $module, <br>
&gt; $slot : slot ), <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
collectList( $slot ) ) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; eval( countThem($list, $size) != $module.setMatchCount()
) <br>
&gt; &nbsp; &nbsp; then <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; modify( $module ) { setMatchCount(countThem($list,
$size)) }; <br>
&gt; end <br>
&gt; <br>
&gt; * Finally, your eval looks odd to me, but anyway, don't have enough
<br>
&gt; details to advise you on that.<br>
&gt; <br>
&gt; <br>
&gt; &nbsp;&nbsp;&nbsp; []s<br>
&gt; &nbsp;&nbsp;&nbsp; Edson<br>
&gt; <br>
</font></tt>
<br><tt><font size=2>&gt; 2009/6/23 Steve Ronderos &lt;steve.ronderos@ni.com&gt;</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; Hi Rules Users, <br>
&gt; <br>
&gt; I'm experiencing an issue with a Drools 4.0.7 rule. <br>
&gt; <br>
&gt; Here is a clip of the exception that is thrown: <br>
&gt; <br>
&gt; Caused by: org.mvel.CompileException: cannot invoke method <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.mvel.optimizers.impl.refl.MethodAccessor.getValue<br>
&gt; (MethodAccessor.java:54) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.mvel.optimizers.impl.refl.VariableAccessor.getValue<br>
&gt; (VariableAccessor.java:39) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at <br>
&gt; org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated<br>
&gt; (VariableDeepPropertyNode.java:22) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated<br>
&gt; (PropertyASTNode.java:21) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.mvel.MVELRuntime.execute(MVELRuntime.java:90)
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.mvel.MVEL.executeExpression(MVEL.java:235)
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.base.mvel.MVELConsequence.evaluate<br>
&gt; (MVELConsequence.java:48) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.common.DefaultAgenda.fireActivation<br>
&gt; (DefaultAgenda.java:554) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; ... 80 more <br>
&gt; Caused by: java.lang.reflect.InvocationTargetException <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.GeneratedMethodAccessor412.invoke(Unknown
Source) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.DelegatingMethodAccessorImpl.invoke<br>
&gt; (DelegatingMethodAccessorImpl.java:25) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at java.lang.reflect.Method.invoke(Method.java:585)
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.mvel.optimizers.impl.refl.MethodAccessor.getValue<br>
&gt; (MethodAccessor.java:46) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; ... 88 more <br>
&gt; Caused by: org.drools.RuntimeDroolsException: <br>
&gt; java.lang.ClassCastException: com.demo.Rule_My_Rule_0$Accumulate0
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.rule.Accumulate.accumulate(Accumulate.java:131)
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.reteoo.AccumulateNode.modifyTuple<br>
&gt; (AccumulateNode.java:352) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.reteoo.AccumulateNode.assertObject<br>
&gt; (AccumulateNode.java:248) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at <br>
&gt; org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject<br>
&gt; (CompositeObjectSinkAdapter.java:318) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.reteoo.ObjectTypeNode.assertObject<br>
&gt; (ObjectTypeNode.java:162) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.reteoo.Rete.assertObject(Rete.java:175)
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.reteoo.ReteooRuleBase.assertObject<br>
&gt; (ReteooRuleBase.java:192) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.reteoo.ReteooWorkingMemory.doInsert<br>
&gt; (ReteooWorkingMemory.java:71) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.common.AbstractWorkingMemory.insert<br>
&gt; (AbstractWorkingMemory.java:911) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.common.AbstractWorkingMemory.insert<br>
&gt; (AbstractWorkingMemory.java:883) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.base.DefaultKnowledgeHelper.insert<br>
&gt; (DefaultKnowledgeHelper.java:67) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.base.DefaultKnowledgeHelper.insert<br>
&gt; (DefaultKnowledgeHelper.java:61) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; ... 92 more <br>
&gt; Caused by: java.lang.ClassCastException: com.demo.Rule_My_Rule_0$Accumulate0
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at com.demo.Rule_My_Rule_0Accumulate0Invoker.accumulate<br>
&gt; (Rule_My_Rule_0Accumulate0Invoker.java:43) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; at org.drools.rule.Accumulate.accumulate(Accumulate.java:123)
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; ... 103 more <br>
&gt; <br>
&gt; The actually rule name and package are a lot longer, I changed them
<br>
&gt; here for brevity and because I don't believe the names themselves
<br>
&gt; are relevant. <br>
&gt; <br>
&gt; This exception is being thrown intermittently when this rule, which
<br>
&gt; contains an accumulate function is called. &nbsp;I say intermittently
<br>
&gt; because it does not happen every time the rule is run. &nbsp;As far
as I <br>
&gt; can tell the ClassCastExceptions only happens when the computer that<br>
&gt; the rules are running on is under load. <br>
&gt; <br>
&gt; A few more details before I post the rule itself. &nbsp;The rule base
<br>
&gt; that I am building consists of 2 drl files. &nbsp;Both of the files
have <br>
&gt; the same package declaration at the top. &nbsp;The 2 packages are
built <br>
&gt; separately using PackageBuilder then combined using <br>
&gt; RuleBase.addPackage() on both packages. &nbsp;Also, I'm not sure if
this <br>
&gt; is relevant, but this scenario takes place in a web application <br>
&gt; where the two package objects are only built once (for performance)
<br>
&gt; but each user session creates a new RuleBase and adds the packages.
<br>
&gt; &nbsp;The individual sessions then create stateful sessions from the
rule base. <br>
&gt; <br>
&gt; This is the rule that I believe is causing the issue. <br>
&gt; <br>
&gt; rule &quot;My Rule&quot; <br>
&gt; &nbsp; &nbsp; salience 50 <br>
&gt; &nbsp; &nbsp; dialect &quot;java&quot; <br>
&gt; &nbsp; &nbsp; no-loop true <br>
&gt; &nbsp; &nbsp; when <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $module : Module( selected == false, required
&gt; 1, $size : required )<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $list : ArrayList( ) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from accumulate(
PotentialMatch( module == $module, <br>
&gt; $slot : slot ), <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
init( List result = new ArrayList(); ), <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
action( result.add($slot); ), <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
reverse( result.remove((Integer)$slot ); ), <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
result( result ) ) <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; eval( countThem($list, $size) != $module.setMatchCount()
) <br>
&gt; &nbsp; &nbsp; then <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; modify( $module ) { setMatchCount(countThem($list,
$size)) }; <br>
&gt; end <br>
&gt; <br>
&gt; As I'm typing this I realize that there is another way to write this<br>
&gt; rule using collect. &nbsp;I'm not sure why it was written this way,
but <br>
&gt; since I have already come this far, has anyone had any experience
<br>
&gt; with the Drools 4 generated code throwing ClassCastExceptions? <br>
&gt; <br>
&gt; Thanks, <br>
&gt; <br>
&gt; Steve Ronderos<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; rules-users@lists.jboss.org<br>
&gt; </font></tt><a href="https://lists.jboss.org/mailman/listinfo/rules-users"><tt><font size=2>https://lists.jboss.org/mailman/listinfo/rules-users</font></tt></a><tt><font size=2><br>
</font></tt>
<br><tt><font size=2>&gt; <br>
&gt; <br>
&gt; <br>
&gt; -- <br>
&gt; &nbsp;Edson Tirelli<br>
&gt; &nbsp;JBoss Drools Core Development<br>
&gt; &nbsp;JBoss by Red Hat @ </font></tt><a href=www.jboss.com><tt><font size=2>www.jboss.com</font></tt></a><tt><font size=2><br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; rules-users@lists.jboss.org<br>
&gt; </font></tt><a href="https://lists.jboss.org/mailman/listinfo/rules-users"><tt><font size=2>https://lists.jboss.org/mailman/listinfo/rules-users</font></tt></a><tt><font size=2><br>
</font></tt>