Hi Pritam, <div>As you mentioned, KA loads, caches and reload kbases. When the KA process a change-set, adds a Listener to every resource so it can detect when they are modified. In order to detect these modifications, two services should be running: <span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><i>ResourceChangeScannerService</i></span> and <i><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">ResourceChangeNotifierService</span> </i>(as you are already doing).</div>

<div><br></div><div><div><div>Listeners are only set for those resources of a change-set, if the initial kbase contained preloaded rules, their resources are not monitored. What I recommend to use change-sets. It seams that your error is in the change-set structure. You must pass a xml definition of a change-set to KA#applyChangeSet() and not a path to a file. Here is an example of a well formed change-set that can be passed to applyChangeSet():</div>

<div><br></div><div><br></div><div><div><i>String xml = &quot;&quot;;</i></div><div><i>        xml += &quot;&lt;change-set xmlns=&#39;<a href="http://drools.org/drools-5.0/change-set">http://drools.org/drools-5.0/change-set</a>&#39;&quot;;</i></div>

<div><i>        xml += &quot;    xmlns:xs=&#39;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&#39;&quot;;</i></div><div><i>        xml += &quot;    xs:schemaLocation=&#39;<a href="http://drools.org/drools-5.0/change-set">http://drools.org/drools-5.0/change-set</a> drools-change-set-5.0.xsd&#39; &gt;&quot;;</i></div>

<div><i>        xml += &quot;    &lt;add&gt; &quot;;</i></div><div><i>        xml += &quot;        &lt;resource source=&#39;<a href="http://localhost:9000/rule1.drl">http://localhost:9000/rule1.drl</a>&#39; type=&#39;DRL&#39; /&gt;&quot;;</i></div>

<div><i>        xml += &quot;        &lt;resource source=&#39;<a href="http://localhost:9000/rule2.drl">http://localhost:9000/rule2.drl</a>&#39; type=&#39;DRL&#39; /&gt;&quot;;</i></div><div><i>        xml += &quot;    &lt;/add&gt; &quot;;</i></div>

<div><i>        xml += &quot;&lt;/change-set&gt;&quot;;</i></div></div><div><br></div></div></div><div>This is a change-set that contains 2 resources. They are accessed using http, but you can use <i>file://</i> if they are local. </div>

<div><br></div><div><br></div><div>Best,</div><div><br></div><div><br><br><div class="gmail_quote">On Thu, Jan 14, 2010 at 10:17 PM, Pritam <span dir="ltr">&lt;<a href="mailto:infinity2heaven@gmail.com">infinity2heaven@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;"><br>
Before I ask the problem, here&#39;s the design I currently have:<br>
<br>
Our &quot;site&quot; (webapp) has 100 pages. While rendering each page, the rule<br>
engine is called for filtering the page contents. We have 100 drl files<br>
(corresponding to each page). Since creating of a KnowledgeBase is<br>
expensive, I&#39;m using a KnowledgeAgent.getKnowledeBase() since the javadocs<br>
mentions it as &quot;it loads, caches, reloads knowledgeBase.&quot;<br>
<br>
However after using the sample code given, a change in the rule file is not<br>
reloading the knowledgeBase automatically. Note that I cache the<br>
knowledgeAgent since I need one agent per knowledge base (is there a better<br>
way to manage multiple drl files in one knowledge base and agent?)<br>
<br>
Is something wrong with the below code?<br>
<br>
// ruleFile is a complete file path on server<br>
public static KnowledgeBase createKnowledgeBaseFromAgent(String ruleFile)<br>
            throws DroolsParserException, IOException {<br>
<br>
        ResourceChangeScannerConfiguration sconf = ResourceFactory<br>
                .getResourceChangeScannerService()<br>
                .newResourceChangeScannerConfiguration();<br>
<br>
        // static map of knowledgeAgents<br>
        if (knowledgeAgents.containsKey(ruleFile)) {<br>
            return<br>
((KnowledgeAgent)knowledgeAgents.get(ruleFile)).getKnowledgeBase();<br>
        }<br>
<br>
        sconf.setProperty(&quot;drools.resource.scanner.interval&quot;, &quot;5&quot;);<br>
<br>
        ResourceFactory.getResourceChangeScannerService().configure(sconf);<br>
<br>
        KnowledgeBase knowledgeBase = createKnowledgeBase(ruleFile);<br>
<br>
        ResourceFactory.getResourceChangeScannerService().start();<br>
        ResourceFactory.getResourceChangeNotifierService().start();<br>
<br>
        KnowledgeAgentConfiguration conf =<br>
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();<br>
        conf.setProperty(&quot;drools.agent.scanDirectories&quot;, &quot;true&quot;);<br>
<br>
        final KnowledgeAgent agent =<br>
KnowledgeAgentFactory.newKnowledgeAgent(<br>
                &quot;my agent&quot;, knowledgeBase, conf);<br>
<br>
       // agent.applyChangeSet(ResourceFactory.newFileResource(ruleFile));<br>
<br>
        setKnowledgeAgent(ruleFile, agent);<br>
<br>
        return agent.getKnowledgeBase();<br>
    }<br>
<br>
<br>
public static KnowledgeBase createKnowledgeBase(<br>
        KnowledgeBaseConfiguration config,<br>
        KnowledgeBuilderConfiguration knowledgeBuilderConfig,<br>
        String ruleFile) throws DroolsParserException, IOException {<br>
<br>
    // else, create a knowledgeBase<br>
    KnowledgeBuilder knowledgeBuilder =<br>
        KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBuilderConfig);<br>
        knowledgeBuilder.add(ResourceFactory.newFileResource(ruleFile),<br>
ResourceType.DRL);<br>
<br>
    if (knowledgeBuilder.hasErrors()) {<br>
        throw new RuntimeException(knowledgeBuilder.getErrors().toString());<br>
    }<br>
<br>
    KnowledgeBase knowledgeBase =<br>
KnowledgeBaseFactory.newKnowledgeBase(config);<br>
<br>
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());<br>
<br>
    return knowledgeBase;<br>
}<br>
<br>
I commented out<br>
agent.applyChangeSet(ResourceFactory.newFileResource(ruleFile));<br>
<br>
since I get a NPE<br>
java.lang.NullPointerException<br>
        at<br>
org.drools.agent.impl.KnowledgeAgentImpl.processChangeSet(KnowledgeAgentImpl.java:135)<br>
<br>
Pl suggest<br>
<font color="#888888">--<br>
View this message in context: <a href="http://n3.nabble.com/KnowledgeAgent-not-reloading-KnowledgeBase-tp121401p121401.html" target="_blank">http://n3.nabble.com/KnowledgeAgent-not-reloading-KnowledgeBase-tp121401p121401.html</a><br>


Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>
</div>