<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Sorry "IF I *wasn't* clear" :-P<br>
    <br>
    On 04/16/2011 05:11 PM, Pablo Nussembaum wrote:
    <blockquote cite="mid:4DA9F7F2.6040206@gmail.com" type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      Sorry if I was clear. The problem when you do:
      ClassLoader.getResource( "resource.path" ) is the the resource can
      be inside a war the in WEB-INF/classes and the war could be NOT
      exploded in container that's is deployed, so the translation to
      something like <a moz-do-not-send="true"
        class="moz-txt-link-freetext" href="file://">file://</a> is NOT
      reliable. <br>
      <br>
      On 04/16/2011 05:05 PM, Mauricio Salatino wrote:
      <blockquote
        cite="mid:BANLkTikVs9W=+aW310VZEX3FDt7VnyM8vQ@mail.gmail.com"
        type="cite">I'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
              moz-do-not-send="true" href="mailto:salaboy@gmail.com">salaboy@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            padding-left: 1ex;">Can you? or Can't you?
            <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
                      moz-do-not-send="true"
                      href="mailto:baunax@gmail.com" target="_blank">baunax@gmail.com</a>&gt;</span>
                  wrote:<br>
                  <blockquote class="gmail_quote" style="margin: 0pt 0pt
                    0pt 0.8ex; border-left: 1px solid rgb(204, 204,
                    204); 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't always
                      convert an URL to <a moz-do-not-send="true">"file://"</a>.<br>
                      <br>
                      -- <br>
                      Bauna
                      <div>
                        <div><br>
                          <br>
                          On 04/15/2011 08:52 AM, Esteban Aliverti
                          wrote: </div>
                      </div>
                      <blockquote type="cite">
                        <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.&nbsp;</div>
                            <div>I'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="kagent1"
                              kbase="kbase1" new-instance="false"&gt;</div>
                            <div><span style="white-space: pre-wrap;"> </span>&lt;drools:resources&gt;&nbsp;<br
                                clear="all">
                              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;drools:resource
                              type="DRL" source="<b>classpath</b>:simple.drl"/&gt;</div>
                            <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...&nbsp;</div>
                            <div>&nbsp; &nbsp; &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&nbsp;ResourceChangeScannerService.&nbsp;</div>
                            <div>So far so good.</div>
                            <div><br>
                            </div>
                            <div>The problem:</div>
                            <div>The problem I'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 "<b>classpath:"</b></div>
                            <div><br>
                            </div>
                            <div>This class has 2 important methods:</div>
                            <div><br>
                            </div>
                            <div>
                              <div> public long getLastModified(){</div>
                              <div>&nbsp; return
                                this.classLoader.getResource( this.path
                                ).openConnection().getLastModified();</div>
                              <div>}</div>
                            </div>
                            <div><br>
                            </div>
                            <div>public InputStream getInputStream(){</div>
                            <div>&nbsp;
                              return&nbsp;this.classLoader.getResourceAsStream(
                              this.path );</div>
                            <div>}</div>
                            <div><br>
                            </div>
                            <div><br>
                            </div>
                            <div>The first method is used
                              by&nbsp;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.&nbsp;</div>
                            <div>An here is when things fail.</div>
                            <div>The kbuilder uses the second method
                              of&nbsp;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's classloader) is
                              using a cache. So the InputStream returned
                              doesn'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
                                moz-do-not-send="true">http://</a> or <a
                                moz-do-not-send="true">file:/</a>. But
                              honestly, when you have your rules inside
                              your webapp, it is much
                              more&nbsp;comfortable&nbsp;and even&nbsp;manageable&nbsp;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:&nbsp;</div>
                            <div> <br>
                            </div>
                            <div> &lt;drools:resource type="DRL"
                              source="<b>URLClasspath</b>:simple.drl"/&gt;</div>
                            <div><br>
                            </div>
                            <div>is going to be translated (internally
                              and in a transparent way) to something
                              like: <a moz-do-not-send="true">file:/usr/local/apache-tomcat-7/webapps/MyWebapp/WEB-INF/simple.drl</a>.</div>
                            <div><br>
                            </div>
                            <div>Opinions?&nbsp;</div>
                            <div><br>
                              XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
                              <br>
                              Esteban Aliverti<br>
                              - Developer @ <a moz-do-not-send="true"
                                href="http://www.plugtree.com"
                                target="_blank">http://www.plugtree.com
                              </a><br>
                              - Blog @ <a moz-do-not-send="true"
                                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 moz-do-not-send="true" href="mailto:rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a>
<a moz-do-not-send="true" 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 moz-do-not-send="true"
                      href="mailto:rules-dev@lists.jboss.org"
                      target="_blank">rules-dev@lists.jboss.org</a><br>
                    <a moz-do-not-send="true"
                      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>
              &nbsp;- CTO @ <a moz-do-not-send="true"
                href="http://www.plugtree.com" target="_blank">http://www.plugtree.com</a>&nbsp;
              <br>
              &nbsp;- MyJourney @ <a moz-do-not-send="true"
                href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><br>
              &nbsp;- Co-Founder @ <a moz-do-not-send="true"
                href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br>
              &nbsp;<br>
              &nbsp;- Salatino "Salaboy" Mauricio -<br>
            </font></blockquote>
        </div>
        <br>
        <br clear="all">
        <br>
        -- <br>
        &nbsp;- CTO @ <a moz-do-not-send="true"
          href="http://www.plugtree.com">http://www.plugtree.com</a>&nbsp; <br>
        &nbsp;- MyJourney @ <a moz-do-not-send="true"
          href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
        &nbsp;- Co-Founder @ <a moz-do-not-send="true"
          href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>
        &nbsp;<br>
        &nbsp;- Salatino "Salaboy" Mauricio -<br>
      </blockquote>
    </blockquote>
  </body>
</html>