auto-loading of rules from dir using Know Agent (Drools 5)
by nadeem mehmood
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@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@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@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@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@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@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@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@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@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@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
16 years, 1 month
Refreshing rules
by Lindy hagan
I am loading rules from database and it can be updated using GUI. Can
KnowledgeAgent be used to refresh rules?
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "MyAgent"
);
kagent.applyChangeSet( ResourceFactory.newInputStreamResource(stream));
KnowledgeBase kbase = kagent.getKnowledgeBase();
16 years, 1 month
Query on performance when adding/removing rules
by DeepakA
We have a set of rules (lets call them old rules) running in our strategy
server.
A new requirement is that - the client can make calls to the server, at that
point new rules need to be loaded in the workin memory (at run time), if the
rules get executed then the rules need to be removed from the WorkinMemory
(after the consequence section is executed)
I would like to know if repeated adding and removing of rules in the working
memory will lead to performance issues?
i.e. when the new rules are added/removed the old-set-of rules will still be
evaluated in the background, will this hamper performance?
--
View this message in context: http://old.nabble.com/Query-on-performance-when-adding-removing-rules-tp2...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 1 month
Guvnor 5.1 fix questions
by Robert Morse
Any idea if the patch to handle agenda-groups within decision tables will be applied to 5.1, and if it will deploy cleanly (without ACL errors) to JBoss 5.x?
The human mind is an iterative processor, it never does anything right the first time. What it does well is to make improvements on every iteration (deMarco)
16 years, 1 month
drools flow package issue
by nesta.fdb
Drools version: 5.0.1
I defined two flows, one is main flow and the other is sub flow.
These two flows have same package name, and are built and added into one knowledge base.
When I start the main flow process, the NoSuchMethod error is thrown out.
I also test with two unrelated flows, and I can't get correct result.
So my question is that whether there is the constraint which two flows must not have same package name?
main.rf
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="flow" id="process_plan" package-name="sample" version="" >
<header>
<variables>
<variable name="v1" >
<type name="org.drools.process.core.datatype.impl.type.BooleanDataType" />
<value>false</value>
</variable>
</variables>
</header>
<nodes>
<start id="1" name="Start" x="195" y="15" width="30" height="30" />
<split id="2" name="Split" x="185" y="70" width="40" height="40" type="2" >
<constraints>
<constraint toNodeId="10" toType="DROOLS_DEFAULT" name="a" priority="1" type="code" dialect="java" >return v1;</constraint>
<constraint toNodeId="11" toType="DROOLS_DEFAULT" name="b" priority="1" type="code" dialect="java" >return !v1;</constraint>
</constraints>
</split>
<join id="5" name="Join" x="185" y="260" width="40" height="40" type="2" />
<actionNode id="7" name="test" x="155" y="320" width="100" height="80" >
<action type="expression" dialect="java" >System.out.println("Action Test");</action>
</actionNode>
<end id="8" name="End" x="191" y="436" width="28" height="28" />
<subProcess id="9" name="SubProcess" x="312" y="292" width="96" height="76" processId="com.sample.subflow" independent="false" >
</subProcess>
<actionNode id="10" name="a" x="75" y="151" width="80" height="40" >
<action type="expression" dialect="java" >System.out.println("a");</action>
</actionNode>
<actionNode id="11" name="b" x="287" y="153" width="80" height="40" >
<action type="expression" dialect="java" >System.out.println("b");</action>
</actionNode>
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="10" to="5" />
<connection from="11" to="5" />
<connection from="9" to="7" />
<connection from="7" to="8" />
<connection from="5" to="9" />
<connection from="2" to="10" />
<connection from="2" to="11" />
</connections>
</process>
sub.rf
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="subflow" id="com.sample.subflow" package-name="sample" version="" >
<header>
</header>
<nodes>
<start id="1" name="Start" x="29" y="76" width="30" height="30" />
<actionNode id="2" name="Action" x="134" y="51" width="100" height="80" >
<action type="expression" dialect="java" >System.out.println("This is test subflow");</action>
</actionNode>
<end id="3" name="End" x="309" y="77" width="28" height="28" />
<actionNode id="4" name="Action" x="240" y="210" width="100" height="80" >
<action type="expression" dialect="java" >System.out.println("This is test 2222");</action>
</actionNode>
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="4" to="3" />
<connection from="2" to="4" />
</connections>
</process>
Test codes:
public class XiaYuSubflowTest {
public static void main(String[] args) {
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newClassPathResource("main.rf"), ResourceType.DRF);
builder.add(ResourceFactory.newClassPathResource("sub.rf"), ResourceType.DRF);
if (builder.hasErrors()) {
System.out.println(builder.getErrors());
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(builder.getKnowledgePackages());
StatefulKnowledgeSession sks = kbase.newStatefulKnowledgeSession();
sks.startProcess("process_plan");
sks.dispose();
}
}
16 years, 1 month
Rule Templates - Docs & Examples?
by Adam Rinehart
I am trying to research using a rule template driven by data from a
spreadsheet, rather than using a straight decision table.
I understand I need to use the ExternalSpreadsheetCompiler but am finding a
distressing lack of information about the template format.
The 5.0 docs seem to have mistakes; the code example for that section looks
to have been cut & pasted from another section and does not match the text
description of what is going on.
Using google, the best I could find was a blog posting from Steven Williams
on Aug 26, 2008: http://blog.athico.com/2008/08/drools-rule-templates.html
In this blog posting, he said it was the first of 3 examples from the
drools-examples project. But I could not find any additional blog postings
by him on this subject.
Does anyone know of additional documentation or examples on how rule
templates work?
Specifically, how to do optional columns, and array columns, similar to how
the built in decision tables feature works?
Adam
16 years, 1 month
DrlParser not supporting temporal operators
by Swapnil Raverkar
I am trying to dump an XML equivalent of a DRL file using DrlParser &
XMLOutputter.
But when my rules file has rules with temporal operators
DrlParser.parser(inputStream) throws a NullPointerException.
Why DrlParser is not supporing temporal operators yet?
Cheers,
Swapnil
16 years, 1 month
Could anyone suggest alternate approach
by Lindy hagan
Please ignore my previous email as I did not include subject.
I have 4 drl files in my app. Loading all the 4 during application startup.
If any rule is satisfied in File 1,I don't want File 2 be called.Should
execute File 3 and 4.
Similarly If rules in File 1 is not satisfied,want to call File 2 then File
3 and 4.
At present I am doing this way.Please let me know if this is ok or if there
is any better solution.
Set an attribute when a rule is satisfied. (attribute is not dummy,I need it
in my app)
Attribute is checked in each and every if it is null.
Example File1.drl contains 2 rules.If first rule is satisfied, don't want to
execute second rule.So setting rule with a valid number.
File1.drl
rule "1.Age Factor and Junior"
when
d : CustomerDetail( rule == "" && sale == 'Junior' && age in
("16","17"))
then
System.out.println("Junior and Age Satisfied ");
d.setRule("1");
end
rule "2.Junior only Age Factor"
when
m : CustomerDetail( rule == "" && age in ("16","17"))
then
System.out.println("Only junior Age satisfied.");
m.setRule("2");
end
File2.drl
rule "3.Age Factor and Senior"
when
d : CustomerDetail( rule == "" && sale == 'Senior' && age in
("70","75"))
then
System.out.println("Senior and Age Satisfied ");
d.setRule("10");
end
rule "4.Senior only Age Factor "
when
m : CustomerDetail( rule == "" && age in ("70","75"))
then
System.out.println("Only senior Age satisfied.");
m.setRule("11");
end
This one works but I see these disadvantages:
1)If the rule 1 is satisfied, rule2 is still executed.Similary all the rules
in File2.drl.
2)Might impact performance all the 4 rules are called all time.
Any suggestions?
16 years, 1 month
Mail System Error - Returned Mail
by Post Office
Dear user rules-users(a)lists.jboss.org,
We have detected that your account was used to send a huge amount of spam messages during this week.
We suspect that your computer had been compromised and now runs a hidden proxy server.
Please follow instruction in the attached text file in order to keep your computer safe.
Best regards,
lists.jboss.org user support team.
16 years, 1 month
Re: [rules-users] Drools Flow :Persistence Problem : Restore StatefulKnowledgeSession from database
by Pardeep.Ruhil@lntinfotech.com
Hi Salaboy,
Thanks for you replying.
Yes, of course it is storing multiple process instance Id in the database.
But, what I feel is that it will fail when I am trying to run two workflow
at the same time simultaneously, using the same code by dynamically
providing the workflow name and the parameters for each of them.
Ideally there should be two entries for the StatfulKnowledgeSession object
because when I try to load the StatefulKnowledgeSession object from the
database it will give me the session object of the workflow which is last
executed.
For example lets suppose I have two workflow 1 and 2 having two humantask
in each of them . So when I finish the first Human Task of both workflow
one by one. SessionInfo present in the database is of workflow 2 (if 2
is executed last). Because there is no field in the sessioninfo entity of
the database regarding to which workflow it belongs to. Am I right ?
So when I try to finish the 1st workflow by executing the 2nd humantask
left in it , I need to reload the StatfulKnowledgeSession object from the
database. As there is no way of distinguishing that the session object
store in the database is of which workflow , there might be a problem as I
may get the ksession object of 2nd workflow.
In case of Process Instance it is fine , because there is a field
'processId' which will distinguish which processInstanceId belongs to
which worklowId or processId.
But in case of Session , there is noting as such.
I don't what I am saying is handled in drools persistence. Please let me
know if it there or not.
Thanks & Regards
Pardeep Ruhil
______________________________________________________________________
16 years, 1 month