[rules-users] auto-loading of rules from dir using Know Agent (Drools 5)

nadeem mehmood nadeemmehmood at yahoo.com
Tue Nov 24 19:34:54 EST 2009


Hello,
I am new to drools and trying to work with the knowledge agent for the automatic loading of rules into the knowledge base from a directory and then firing all the rules. Am using the ChangeSet xml File to configure the rule directory. Actually the problem is: the rules are fired for the first time only, but when I put a new rule file in the directory the new rules does't fire.
plz find the source code in the attachment
rgards,nadeem

MY CODE:public class KnowAgent {	KnowledgeBase buildKBA(KnowledgeBase kb){		KnowledgeAgent kagent =
 KnowledgeAgentFactory.newKnowledgeAgent( "MyAgent" );		
				kagent.applyChangeSet( ResourceFactory.newClassPathResource("resChangeSet.xml") );				ResourceFactory.getResourceChangeNotifierService().start();		ResourceFactory.getResourceChangeScannerService().start();		kb = kagent.getKnowledgeBase();		return kb;
	}}--------------------------------------------------public class RuleRunnerKnowledgeAgent {	private KnowAgent myKnowAgent = new KnowAgent();	private KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();	private KnowledgeRuntimeLogger logger;	private StatefulKnowledgeSession ksession;
    public void RuleRunnerKnowledgeAgent(String[] rules,                         Object[] facts) throws Exception {        kbase = myKnowAgent.buildKBA(kbase);      
          ksession = kbase.newStatefulKnowledgeSession();        logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "agentkblog");        ksession.fireAllRules();    }}--------------------------------------------------<?xml version="1.0" encoding="utf-8"?><change-set xmlns='http://drools.org/drools-5.0/change-set'             xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'             xs:schemaLocation='http://drools.org/drools-5.0/change-set drools-change-set-5.0.xsd' >   <add>      <resource source='file:src/main/rules/org/drools/prepare/collection/' type='DRL'
 />   </add></change-set>--------------------------------------------------rule "Rule 01"       when        eval (1==1)    then        System.out.println("Rule 01 Works");end
2nd DRL file is also same like, but with diff rule and file name and output.--------------------------------------------------CONSOLE OUTPUT[2009:11:329 00:11:762:info] ResourceChangeNotification created[2009:11:329 00:11:764:info] ResourceChangeScanner created with default interval=60[2009:11:329 00:11:765:debug] ResourceChangeNotification monitor added monitor=org.drools.io.impl.ResourceChangeScannerImpl at 19134f4[2009:11:329 00:11:766:info] KnowledgAgent created, with
 configuration:monitorChangeSetEvents=true scanResources=true scanDirectories=true[2009:11:329 00:11:766:info] KnowledegAgent has started listening for ChangeSet notifications
(null: 4, 101): schema_reference.4: Failed to read schema document 'drools-change-set-5.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.(null: 4, 101): cvc-elt.1: Cannot find the declaration of element 'change-set'.(null: 5, 9): schema_reference.4: Failed to read schema document 'drools-change-set-5.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.(null: 7, 90): schema_reference.4: Failed to read schema document 'drools-change-set-5.0.xsd', because 1) could not find the document; 2) the document could not be read;
 3) the root element of the document is not <xsd:schema>.[2009:11:329 00:11:873:info] KnowledgAgent applying ChangeSet[2009:11:329 00:11:875:debug] KnowledgeAgent subscribing to directory=[UrlResource path='file:src/main/rules/org/drools/prepare/collection/'][2009:11:329 00:11:875:debug] ResourceChangeNotification subscribing listener=org.drools.agent.impl.KnowledgeAgentImpl at 12d7a10 to resource=[UrlResource path='file:src/main/rules/org/drools/prepare/collection/'][2009:11:329 00:11:875:debug] ResourceChangeScanner subcribing notifier=org.drools.io.impl.ResourceChangeNotifierImpl at 1feca64 to resource=[UrlResource path='file:src/main/rules/org/drools/prepare/collection/'][2009:11:329 00:11:877:debug] KnowledgeAgent subscribing to directory content resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1.drl'][2009:11:329 00:11:877:debug]
 ResourceChangeNotification subscribing listener=org.drools.agent.impl.KnowledgeAgentImpl at 12d7a10 to resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1.drl'][2009:11:329 00:11:877:debug] ResourceChangeScanner subcribing notifier=org.drools.io.impl.ResourceChangeNotifierImpl at 1feca64 to resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1.drl'][2009:11:329 00:11:878:debug] KnowledgeAgent ChangeSet requires KnowledgeBuilder[2009:11:329 00:11:878:debug] KnowledgeAgent rebuilding KnowledgeBase using ChangeSet[2009:11:329 00:11:171:debug] KnowledgeAgent building resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1.drl'][2009:11:329 00:11:601:info] KnowledgeAgent new KnowledgeBase now built and in use[2009:11:329 00:11:603:info] ResourceChangeNotification has started listening
 for ChangeSet publications[2009:11:329 00:11:603:debug] ResourceChangeNotification thread is waiting for queue update
[2009:11:329 00:11:604:info] ResourceChangeNotification scanner has started[2009:11:329 00:11:605:debug] ResourceChangeScanner attempt to scan 2 resources[2009:11:329 00:11:605:debug] ResourceChangeScanner scanning directory=[UrlResource path='file:src/main/rules/org/drools/prepare/collection/'][2009:11:329 00:11:606:debug] ResourceChangeScanner thread is waiting for 60Rule 01 Works[2009:11:329 00:11:607:debug] ResourceChangeScanner attempt to scan 2 resources[2009:11:329 00:11:608:debug] ResourceChangeScanner scanning directory=[UrlResource path='file:src/main/rules/org/drools/prepare/collection/'][2009:11:329 00:11:609:debug] ResourceChangeScanner new resource=[FileResource
 file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'][2009:11:329 00:11:609:debug] ResourceChangeNotification subscribing directory=[UrlResource path='file:src/main/rules/org/drools/prepare/collection/'] content resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'][2009:11:329 00:11:609:debug] ResourceChangeNotification subscribing listener=org.drools.agent.impl.KnowledgeAgentImpl at 12d7a10 to resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'][2009:11:329 00:11:610:debug] ResourceChangeScanner subcribing notifier=org.drools.io.impl.ResourceChangeNotifierImpl at 1feca64 to resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'][2009:11:329 00:11:611:debug] ResourceChangeScanner modified resource=[FileResource
 file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'] : -1 : 1259108256456[2009:11:329 00:11:611:debug] ResourceChangeNotification received ChangeSet notification[2009:11:329 00:11:612:debug] ResourceChangeScanner thread is waiting for 60[2009:11:329 00:11:612:debug] ResourceChangeNotification processing ChangeSet[2009:11:329 00:11:612:debug] ResourceChangeNotification ChangeSet added resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'] for listener=org.drools.agent.impl.KnowledgeAgentImpl at 12d7a10[2009:11:329 00:11:613:debug] ResourceChangeNotification ChangeSet modified resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'] for listener=org.drools.agent.impl.KnowledgeAgentImpl at 12d7a10[2009:11:329 00:11:613:debug] KnowledgeAgent received ChangeSet changed
 notification[2009:11:329 00:11:613:debug] ResourceChangeNotification thread is waiting for queue update[2009:11:329 00:11:613:info] KnowledgAgent applying ChangeSet[2009:11:329 00:11:613:debug] KnowledgeAgent subscribing to resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'][2009:11:329 00:11:614:debug] ResourceChangeNotification subscribing listener=org.drools.agent.impl.KnowledgeAgentImpl at 12d7a10 to resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'][2009:11:329 00:11:614:debug] KnowledgeAgent ChangeSet requires KnowledgeBuilder[2009:11:329 00:11:614:debug] KnowledgeAgent rebuilding KnowledgeBase using ChangeSet[2009:11:329 00:11:619:debug] KnowledgeAgent building resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1.drl'][2009:11:329
 00:11:749:debug] KnowledgeAgent building resource=[FileResource file='src\main\rules\org\drools\prepare\collection\objectCollection1A.drl'][2009:11:329 00:11:840:info] KnowledgeAgent new KnowledgeBase now built and in use






      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091124/d333078f/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: src.zip
Type: application/zip
Size: 5061 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20091124/d333078f/attachment.zip 


More information about the rules-users mailing list