<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Op 20/09/2013 21:23, Davide Sottara
      schreef:<br>
    </div>
    <blockquote cite="mid:523CA0A3.50802@gmail.com" type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      <div class="moz-cite-prefix">Brecht, thanks for reporting this,
        but I don't think these are bugs.<br>
        <br>
      </div>
    </blockquote>
    Thanks for the explanations. I tested it to be sure and it works as
    expected. The "drools.agent.useKBaseClassLoaderForCompiling" option
    indeed fixes the issue unless the agent detects several files at the
    same time in which case they are processed in alphabetical order
    (which is to be expected). In that case my preprocessing hack is
    still useful. The globals are just something different than what I
    expected globals to be. <br>
    <br>
    Thank you very much for the support.<br>
    <blockquote cite="mid:523CA0A3.50802@gmail.com" type="cite">
      <div class="moz-cite-prefix"> 1) In order to set the value of a
        global from a rule's RHS, you have to do somehting like this<br>
        <br>
        drools.getKnowledgeRuntime().setGlobal( "RULES_MATCHED",
        newValue );<br>
        <br>
        The reason is that the rule's RHS sees a reference to the
        original global... a local variable with the<br>
        same name initialized appropriately. Something like
        RULES_MATCHED = 0 will only change the local<br>
        reference, not modify the global.<br>
        <br>
        2) The KnowledgeAgent supports declared types incrementally..
        (Esteban and I spent a lot of time to make<br>
        that work), but you have to set a flag in the KA's
        configuration:<br>
        <br>
        KnowledgeAgentConfiguration aconf =
        KnowledgeAgentFactory.newKnowledgeAgentConfiguration();<br>
        aconf.setProperty(
        "drools.agent.useKBaseClassLoaderForCompiling", true );<br>
        <br>
        The "incremental" mode (newInstance=false) only ensures that the
        existing KnowlegeBase is updated,<br>
        tue "useKBaseClassLoaderForCompiling" will ALSO make sure that,
        as the new resources are compiled<br>
        by a KnowledgeBuilder, this is initialized with the KB's
        classloader, which has the classes for the declared types.<br>
        <br>
        3) I have proposed a fix for the issue you reported the other
        day... actually two in one. <br>
        - 3a ) Runtime exceptions will be catched,<br>
        - 3b ) you **WILL NOT** be able to use primitive types with
        globals anymore.. (which would result in a RTE anyway)<br>
        <br>
        Hope this help<br>
        Best<br>
        Davide<br>
        <br>
        <br>
        <br>
        On 09/20/2013 02:18 AM, De Rooms Brecht wrote:<br>
      </div>
      <blockquote cite="mid:523C12DF.2060000@vub.ac.be" type="cite">
        <meta http-equiv="content-type" content="text/html;
          charset=ISO-8859-1">
        Dear Drools Users,<br>
        <br>
        I am building a network server for drools&nbsp; since the existing
        drools-server did not meet my requirements.&nbsp; Since I recently
        found a bug and find the people here very helpful I'll try to
        explain another issue I encountered in the hope that it improves
        drools 5.6 and 6.0.<br>
        I noticed that declared types and globals don't seem to be found
        when you access them from a rule that was written in a different
        file. For the declared types I hacked around this issue by
        preprocessing the files and placing every declared type at the
        top of each file that needs it. For globals this is of course
        not possible. <br>
        <br>
        An example is shown below. File1 is loaded from the moment the
        agent starts up, then file2 is loaded.<br>
        There is a difference when the knowledgeAgent detects the two
        files at once or one by one. In this case the KnowledgeAgent
        detects one file and then a few minutes later the other file and
        compiles them completely separately.<br>
        The idea is to keep how many rules are matched of a certain type
        in a global.<br>
        <br>
        &nbsp;<b><small>&nbsp;&nbsp; FILE1: global_rules_matches.drl<br>
            &nbsp;&nbsp;&nbsp; ----------------------------------------------<br>
            &nbsp;&nbsp;&nbsp; package ellipsoidfacts<br>
            <br>
            &nbsp;&nbsp;&nbsp; // declare<br>
            &nbsp;&nbsp;&nbsp; global Integer RULES_MATCHED;<br>
            <br>
            &nbsp;&nbsp;&nbsp; // initialize global<br>
            &nbsp;&nbsp;&nbsp; rule "initRULESMATCHED"<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; salience 999<br>
            &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; when<br>
            &nbsp;&nbsp; <br>
            &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; then<br>
            &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RULES_MATCHED = 0;<br>
            &nbsp;&nbsp;&nbsp; end</small></b><br>
        <br>
        &nbsp;<b><small>&nbsp;&nbsp; FILE2: testrule.drl<br>
            &nbsp;&nbsp;&nbsp; ----------------------------------------------<br>
            &nbsp;&nbsp;&nbsp; package ellipsoidfacts<br>
            <br>
            &nbsp;&nbsp; rule "Gesture_lefthook"<br>
            &nbsp;&nbsp;&nbsp; when <br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ... any&nbsp; precedent rules ...&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
            <br>
            &nbsp;&nbsp;&nbsp; then<br>
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; System.out.println("matched gesture:&nbsp; lefthook"+
            RULES_MATCHED);<br>
            &nbsp;&nbsp;&nbsp; end</small></b><br>
        <br>
        In this particular case, my rule is not matched. I load these
        rules using a changeset xml, my knowledgeagent is set to
        incremental (but either doesnt work).<br>
        The same happens when I declare types in FILE1 and use them in
        FILE2. When I write the type declaration in both files it works
        perfectly. <br>
        Being the same package I assumed that these two scenarios should
        work. Am I doing something wrong or is the agent not supposed to
        work like this and should a package be in one file?<br>
        <br>
        Kind Regards,<br>
        De Rooms Brecht<br>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <br>
        <pre wrap="">_______________________________________________
rules-users mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
      </blockquote>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Brecht De Rooms
=================================
Phd Student 
Vrije Universiteit Brussel
Research Group CISA(WISE) - DINF F.10.707    
Department of Computer Science 
Pleinlaan 2   - 1050 Brussels - Belgium
Tel. +32-2-629 1103
E-mail: <a class="moz-txt-link-abbreviated" href="mailto:bderooms@vub.ac.be">bderooms@vub.ac.be</a>
Website  <a class="moz-txt-link-freetext" href="http://wise.vub.ac.be/brecht-de-rooms">http://wise.vub.ac.be/brecht-de-rooms</a>
=================================
</pre>
  </body>
</html>