<div>Hi Geoffrey,</div><div>thanks for sharing your opinion! </div><div><br></div><div>When drools-spring creates the resource from the configuration file, it creates it passing the class' class loader:</div><div><br></div>
<div><div>new ClassPathResource(path, ClassPathResource.class.getClassLoader() );</div></div><div><br></div><div>Internally, ClassPathResource is doing:</div><div><br></div><div><div>this.classLoader = ClassLoaderUtil.getClassLoader( new ClassLoader[] { classLoader },null, false );</div>
</div><div><br></div><div>So, a classloader is indeed supplied. AFAIK, the problem is that the provided classloader is tomcat's classloader.</div><div><br></div><div>I know it is dangerous to store native URLs instead of the classpath, but after all, after you deploy drools-server, each of the resources will have an URL. </div>
<div>If this is a problem, you can always use classpath resources. That is why I thought in a new Resource type and not in modify ClassPathResource class.</div><div><br></div><div>I have created an issue for this: <a href="https://issues.jboss.org/browse/JBRULES-2960">https://issues.jboss.org/browse/JBRULES-2960</a></div>
<div><br></div><div>Thanks again for your time!</div><div><br></div><div>Best Regards,</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>
<br><br><div class="gmail_quote">On Fri, Apr 15, 2011 at 9:38 AM, Geoffrey De Smet <span dir="ltr"><<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div text="#000000" bgcolor="#ffffff"><div class="im">
<blockquote type="cite">The kbuilder uses the second method
of ClassPathResource (getInputStream()) to get the content of the
resource.</blockquote>
<br></div>
Shouldn't that also supply a ClassLoader or a Class (of which
Class.getClassLoader() is used)?<div class="im"><br>
<br>
<blockquote type="cite">This resource type will let you define your
resources present in your classpath as usually but it will
translate them to URL Resource internally.</blockquote></div>
It's probably dangerous to store the native URL the concept of a
classpath is designed to have a map of files "that are just there"
and you don't need to worry what's the OS-specific underlying
details.<br>
Instead, I believe, the classpath key (for example "simpler.drl")
and the ClassLoader (for example MyApp.class.getClassLoader())
should be stored.<br>
<br>
Op 15-04-11 13:52, Esteban Aliverti schreef:
<blockquote type="cite"><div><div></div><div class="h5">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'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><drools:kagent id="kagent1" kbase="kbase1"
new-instance="false"></div>
<div><span style="white-space:pre-wrap"> </span><drools:resources> <br clear="all">
<drools:resource type="DRL" source="<b>classpath</b>:simple.drl"/></div>
<div> ... </div>
<div> </drools:resources></div>
<div></drools:kagent></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'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> 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'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>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>
<drools:resource type="DRL" source="<b>URLClasspath</b>:simple.drl"/></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
<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>
</pre>
</blockquote>
<br>
<pre cols="72">--
With kind regards,
Geoffrey De Smet</pre>
</div>
<br>_______________________________________________<br>
rules-dev mailing list<br>
<a href="mailto:rules-dev@lists.jboss.org">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>