<br>   This was a bug. It is fixed now. Thanks for reporting.<br><br><a href="https://jira.jboss.org/jira/browse/JBRULES-2202">https://jira.jboss.org/jira/browse/JBRULES-2202</a><br><br>   Edson<br><br><div class="gmail_quote">
2009/7/9 bill simms <span dir="ltr">&lt;<a href="mailto:sitrious@gmail.com">sitrious@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br><br>Recently I&#39;ve been working with Drools version 5.0.1 to set up an event processor.  While doing so I have come<br>across difficulties with the accumulate function, in that it will always throw a ClassCastException<br>

when inserting events that are declared within my drl file.  To illustrate this I&#39;ve set up an example which is <br>shown below.  I&#39;ve search Google and the mailing list for several hours, but the only way past this problem<br>

appears to be that I will have to declare a class externally and make sure it implements Serializable.  Does<br>anyone has suggestions for another approach?  Secondly, I would have assumed that since Drools was<br>compiling these internally declared classes, that Serializable would have been implemented automatically.  So<br>

is this a result of the generated class not implementing Serializable, or have I missed something in my rules<br>file?  Thanks.<br><br>The important part of my drl file is:<br><br>declare TestEvent<br>   @role( event )<br>

   @expires(10s)<br>   id : String<br>end <br><br>#This rule works fine when &#39;Accumulate Count&#39; is commented out, and is used to make<br>#sure that the event inserting has worked.<br>rule &quot;Is It There&quot;<br>

    when<br>        TestEvent() from entry-point &quot;test&quot;<br>    then<br>        System.out.println(&quot;Found a TestEvent.&quot;);<br>end<br><br>#This rule throws a ClassCastException when a TestEvent is inserted.<br>

rule &quot;Accumulate Count&quot;<br>    when<br>        $n : Number() from accumulate($t : TestEvent() from entry-point &quot;test&quot;,    count($t))<br>    then<br>        System.out.println(&quot;Found &quot; + $n + &quot; events.&quot;);<br>

end<br><br>The unit test does this:<br><br>FactType testEventType = session.getKnowledgeBase().getFactType(&quot;com.drools.test&quot;, &quot;TestEvent&quot;);<br>for(int i = 0; i &lt; 10; i++){<br>    Object testEvent = testEventType.newInstance();<br>

    testEventType.set(testEvent, &quot;id&quot;, &quot;id&quot;);<br>    WorkingMemoryEntryPoint mainStream = session.getWorkingMemoryEntryPoint(&quot;test&quot;);<br>    mainStream.insert(event);<br>    session.fireAllRules();<br>

}<br><br>The exception I receive is:<br><br>org.drools.RuntimeDroolsException: java.lang.ClassCastException: com.drools.test.TestEvent cannot be cast to java.io.Serializable<br>    at org.drools.rule.Accumulate.accumulate(Accumulate.java:172)<br>

    at org.drools.reteoo.AccumulateNode.modifyTuple(AccumulateNode.java:424)<br>    at org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:284)<br>    at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:42)<br>

    at org.drools.reteoo.PropagationQueuingNode$AssertAction.execute(PropagationQueuingNode.java:326)<br>    at org.drools.reteoo.PropagationQueuingNode.propagateActions(PropagationQueuingNode.java:221)<br>    at org.drools.reteoo.PropagationQueuingNode$PropagateAction.execute(PropagationQueuingNode.java:394)<br>

    at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1486)<br>    at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:158)<br>    at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:122)<br>

    at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:80)<br>    at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:28)<br>    at com.drools.test.MyUnitTest.testEvents(EvaluationTest.java:66)<br>

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>    at java.lang.reflect.Method.invoke(Unknown Source)<br>

    at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160)<br>    at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)<br>    at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)<br>

    at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)<br>    at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)<br>

    at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)<br>    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)<br>

    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)<br>    at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)<br>    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)<br>

    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)<br>    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)<br>    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)<br>

    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)<br>    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)<br>    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)<br>

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)<br>    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)<br>    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)<br>

Caused by: java.lang.ClassCastException: com.drools.test.TestEvent cannot be cast to java.io.Serializable<br>    at org.drools.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.java:110)<br>

    at org.drools.rule.Accumulate.accumulate(Accumulate.java:164)<br>    ... 36 more<br><br><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>