I&#39;m still thinking about that mapping and those assumptions<br><br><div class="gmail_quote">On Sat, Apr 16, 2011 at 5:05 PM, Mauricio Salatino <span dir="ltr">&lt;<a href="mailto:salaboy@gmail.com">salaboy@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Can you? or Can&#39;t you?<div><div></div><div class="h5"><br><br><br><div class="gmail_quote">On Sat, Apr 16, 2011 at 4:24 PM, Pablo Nussembaum <span dir="ltr">&lt;<a href="mailto:baunax@gmail.com" target="_blank">baunax@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


  
    
  
  <div bgcolor="#ffffff" text="#000000">
    Esteban,<br>
    You can assume that a resource that was obtained from the classpath
    exists in your filesystem, for instance it can be a file inside a
    jar or war that are not exploded. In other words you can&#39;t always
    convert an URL to <a>&quot;file://&quot;</a>.<br>
    <br>
    -- <br>
    Bauna<div><div></div><div><br>
    <br>
    On 04/15/2011 08:52 AM, Esteban Aliverti wrote:
    </div></div><blockquote type="cite"><div><div></div><div>Hi Guys,
      <div><br>
      </div>
      <div>I want to discuss a problem I have found when using the
        combination of knowledge agent + classpathResources.</div>
      <div>I will try to describe what am I doing first to give you some
        context. </div>
      <div>I&#39;m deploying drools-camel-server in a Tomcat 7 container.
        Inside the WEB-INF/classes directory I have some DRL files that
        I want to use.</div>
      <div>My knowledge-services.xml file declares the following kagent:</div>
      <div><br>
      </div>
      <div>&lt;drools:kagent id=&quot;kagent1&quot; kbase=&quot;kbase1&quot;
        new-instance=&quot;false&quot;&gt;</div>
      <div><span style="white-space:pre-wrap"> </span>&lt;drools:resources&gt; <br clear="all">
                     &lt;drools:resource type=&quot;DRL&quot; source=&quot;<b>classpath</b>:simple.drl&quot;/&gt;</div>
      
      <div>             ... </div>
      <div>    &lt;/drools:resources&gt;</div>
      <div>&lt;/drools:kagent&gt;</div>
      <div><br>
      </div>
      <div>When spring parses this configuration file it creates a
        KnowledgeAgent instance with a ChangeSet containing all the
        listed resources.</div>
      <div>The next step is to start ResourceChangeNotifierService
        and ResourceChangeScannerService. </div>
      <div>So far so good.</div>
      <div><br>
      </div>
      <div>The problem:</div>
      <div>The problem I&#39;m having is not directly related to drools, but
        I think it is quite easy to provide a solution for the people
        that is in my same situation.</div>
      <div><br>
      </div>
      <div>ClassPathResource is the class that represents a resource
        defined as &quot;<b>classpath:&quot;</b></div>
      <div><br>
      </div>
      <div>This class has 2 important methods:</div>
      <div><br>
      </div>
      <div>
        
        <div>
          public long getLastModified(){</div>
        <div>  return this.classLoader.getResource( this.path
          ).openConnection().getLastModified();</div>
        <div>}</div>
      </div>
      <div><br>
      </div>
      <div>public InputStream getInputStream(){</div>
      <div>  return this.classLoader.getResourceAsStream( this.path );</div>
      <div>}</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>The first method is used by ResourceChangeScannerService to
        check whether the resource has changed or not. It works fine.
        When the resource in the filesystem changes, the scanner detects
        the change without any problem.</div>
      <div>The scanner ends up notifying the kagent about the change,
        and the kagent passes the Resource to an instance of
        KnowledgeBuilder. </div>
      <div>An here is when things fail.</div>
      <div>The kbuilder uses the second method of ClassPathResource
        (getInputStream()) to get the content of the resource. In the
        case of Tomcat (and probably some other environments), it seems
        that the classloader (Tomcat&#39;s classloader) is using a cache. So
        the InputStream returned doesn&#39;t reflect the current state of
        the resource.</div>
      <div>Long story short: the agent is notified about a change in the
        resource, but the change is never applied to the kbase because
        the kbuilder is unable to get it :P</div>
      <div><br>
      </div>
      <div>Solutions:</div>
      <div>The first solution is not to use classpath resources :). You
        can use just url resources like <a>http://</a> or <a>file:/</a>. But honestly,
        when you have your rules inside your webapp, it is much
        more comfortable and even manageable to avoid the use of real
        paths.</div>
      <div><br>
      </div>
      <div>What I was thinking about (I already have a working
        prototype) is to create a new Resource type for these cases.
        This resource type will let you define your resources present in
        your classpath as usually but it will translate them to URL
        Resource internally.</div>
      <div>So, in the example above: </div>
      
      
      
      <div>
        <br>
      </div>
      <div>
        
        &lt;drools:resource type=&quot;DRL&quot; source=&quot;<b>URLClasspath</b>:simple.drl&quot;/&gt;</div>
      <div><br>
      </div>
      <div>is going to be translated (internally and in a transparent
        way) to something like:
        <a>file:/usr/local/apache-tomcat-7/webapps/MyWebapp/WEB-INF/simple.drl</a>.</div>
      <div><br>
      </div>
      <div>Opinions? </div>
      <div><br>
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
        <br>
        Esteban Aliverti<br>
        - Developer @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com
        </a><br>
        - Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>
      </div>
      </div></div><pre><fieldset></fieldset>
_______________________________________________
rules-dev mailing list
<div><a href="mailto:rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
</div></pre>
    </blockquote>
  </div>

<br>_______________________________________________<br>
rules-dev mailing list<br>
<a href="mailto:rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
<br></blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br> - CTO @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com</a>  <br> - MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><br>

 - Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br> <br> - Salatino &quot;Salaboy&quot; Mauricio -<br>
</font></blockquote></div><br><br clear="all"><br>-- <br> - CTO @ <a href="http://www.plugtree.com">http://www.plugtree.com</a>  <br> - MyJourney @ <a href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
 - Co-Founder @ <a href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br> <br> - Salatino &quot;Salaboy&quot; Mauricio -<br>