0 Replies Latest reply on Jul 7, 2011 10:45 PM by rp2

    Temporal reasoning with external persistence not working

    rp2 Newbie

      I am trying to use an external storage for loading and persisting objects. But when I try a set a temporal reasoning rule it start to fail. The rule, test code and exception are given below. Please help

       

       

      // rules file

       

      {code}

      package foo.externalwm;

       

      global foo.ExternalStorage session;

      import foo.externalwm.YUser

      import foo.externalwm.Test

       

       

      declare User

          @role(event)

      end

       

      declare Contest

          @role(event)

      end

       

       

      rule "test"

      dialect "java"

      when

          $c1:Contest() from session.getContestByName("Contest1")

          User(this after[0,3m] $c1) from session.getUserByIndex(0)

      then

          System.out.println("rule fired");

      end

       

      {code}

       

       

      // ************ code

       

      {code}

      public class Test {

       

          public static void main(String[] args) throws Exception {

              KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();

              config.setOption( EventProcessingOption.STREAM );

       

              KnowledgeBase k = init(); // read and compile rules done here

       

              final StatefulKnowledgeSession ksession = k.newStatefulKnowledgeSession();

       

              ExternalStorage session = new ExternalStorage();

              ksession.setGlobal("session", session);

              ksession.fireAllRules();       

          }

      {code}

       

       

      ***********EXCEPTION

      Exception in thread "main" org.drools.RuntimeDroolsException: Unexpected exception executing action org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction@669a4cb

          at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:996)

          at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:730)

          at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:699)

          at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)

          at foo.externalwm.Test.main(Test.java:55)

      Caused by: java.lang.ClassCastException: org.drools.common.DefaultFactHandle cannot be cast to org.drools.common.EventFactHandle

          at org.drools.base.evaluators.AfterEvaluatorDefinition$AfterEvaluator.evaluateCachedLeft(AfterEvaluatorDefinition.java:332)

          at org.drools.rule.VariableRestriction.isAllowedCachedLeft(VariableRestriction.java:110)

          at org.drools.rule.VariableConstraint.isAllowedCachedLeft(VariableConstraint.java:111)

          at org.drools.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:127)

          at org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:274)

          at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:137)

          at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:189)

          at org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:64)

          at org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:279)

          at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:137)

          at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:189)

          at org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:138)

          at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:141)

          at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)

          at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:185)

          at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:143)

          at org.drools.reteoo.Rete.assertObject(Rete.java:107)

          at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:260)

          at org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:343)

          at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:994)

          ... 4 more