facing problems while adding a Rule to DROOLS using java client?
by PC
Hi,
i am using Guvnor-5.2.0 . Through a simple java client class i wanted to
add
a rule at runtime.
below is the snippet of java code i am using to add a rule.
KnowledgeBase knowledgeBase = createKnowledgeBase();
session = knowledgeBase.newStatefulKnowledgeSession();
logger = KnowledgeRuntimeLoggerFactory.newFileLogger(session,
"log/DroolsSample");
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
String ruleDescription = "package com.tcube.atyaf.dto;"+
"import
com.tcube.atyaf.dto.EmployeeDataDTO;" +
"rule \"SimpleDRLRule\""+
" @ID(11003588)"+
" lock-on-active true"+
" salience -11"+
" dialect 'mvel'"+
" when m :
EmployeeDataDTO(empName==\"PC\");"+
" then System.out.println(
\"*************rule executed\");" +
" m.setDesignation( \"Manager
,Additional Duties & Additional hike
!!!\" );"+
" update( m );"+
" end";
byte[] data = ruleDescription.getBytes();
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBase);
kbuilder.add( ResourceFactory.newClassPathResource("ChangeSet.xml"),
ResourceType.CHANGE_SET );
kbuilder.add( ResourceFactory.newClassPathResource("TestRule.drl"),
ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(data),
ResourceType.DRL);
if(kbuilder.hasErrors()) {
System.out.println( kbuilder.getErrors() );
return;
}
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
knowledgeBase.addKnowledgePackages( kpkgs );
emp = new EmployeeDataDTO();
emp.setEmpNo(1);
emp.setEmpName("PC");
emp.setAge(29);
emp.setSalary(new BigDecimal("6500"));
session.insert(emp);
session.fireAllRules();
I am getting all the rules executed as per exceptation since it is in the
same session, however the new rules that i have added are not reflected in
Drools-Guvnor UI....
please help me on code for deploying the knowldgeBase/Package(kpkgs) to
Drools-Guvnor UI..
-----
PC
--
View this message in context: http://drools.46999.n3.nabble.com/facing-problems-while-adding-a-Rule-to-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 9 months
Fact Instance "lifetime" in knowledge session
by Anne Fiore
Hi,
I'm very new to drools and am trying to understand how "facts" are managed
by the knowledge session. I've been experimenting with a simple example
using drools 5.3.0. I created a simple Account class that has a single
"balance" attribute. My rule tests the balance and prints a message if it
is less than 100. I am creating a new instance of Account in my main method
and inserting it into a stateful knowledge session. I put this into a
loop that runs 3 times and never dispose of the session. Each of my
Account instances has a balance less that 100. Here is a portion of the
code:
public static final void main(String[] args) throws InterruptedException
{
KnowledgeBase knowledgeBase = createKnowledgeBase();
StatefulKnowledgeSession session =
knowledgeBase.newStatefulKnowledgeSession();
for (int i = 0; i < 3; i++)
{
try
{
Account account = new Account();
switch (i)
{
case 0: account.setBalance(95);
break;
case 1: account.setBalance(85);
break;
case 2: account.setBalance(80);
break;
default: account.setBalance(80);
}
session.insert(account);
session.fireAllRules();
}
catch (Exception e)
{
System.out.println("Exception: " + e.toString());
}
Thread.sleep(1000);
}
}
My rule is:
rule "basic rule"
when $a : Account (balance < 100) // condition
then System.out.println("Account balance " + $a.getBalance() + " is less
than 100"); // consequence
end
What I see is that each time the loop executes only the last instance of
Account seems to get triggered. I expected that each time I call
"fireAllRules" it would examine all the facts in the session and execute
them. So I thought the first time the loop runs I would get 1 activation,
the second time the loop runs I get 2 activations, etc.
Are all 3 instances of Account still in the working memory or is the latest
instance replacing the existing one? Or, once a fact triggers the rules
engine, does it not trigger it again?
Thanks for any insights,
Anne
12 years, 9 months
Drools & jBPM Event : London 8th March 2012
by Mark Proctor
http://blog.athico.com/2012/02/drools-jbpm-event-london-8th-march-2012.html
-----
Register now to join us for the free Drools & jBPM London 2012 event,
hurry limited spaces :)
http://redhat-mail.com/t/XRU-OE4J-824IMOYW1D/cr.aspx
When Thursday 8th March
Where Stationers Hall, London
Agenda trans
trans trans trans
trans
trans
09:00 trans Registration, tea and coffee
trans
09:30 trans Introduction/ Welcome
trans
09:45 trans Rules, Events & Processes: the Open Source way
Mark Proctor - Worldwide Technical Lead for BRMS & BPMS, Red Hat
trans
10:45 trans Decision Tables
Michael Anstis, JBoss Core Developer, Red Hat
trans
11:15 trans Tea/Coffee Break
trans
11:30 trans BPMN2 and jBPM5
Kris Verlaenen, JBoss Core Developer, Red Hat
trans
12:15 trans Solving Planning Problems
Geoffrey de Smet, JBoss Core Developer, Red Hat
trans
12:45 trans Case Studies
trans
13:00 trans Lunch and Networking
trans
12 years, 9 months
Streaming mode
by Matteo Cusmai
Hi all,
i have a big problem with drools fusion.
I insert some new event (pojo object) into Working Memory, but another
thread retract it after a few ms.
Someone could tell me why?
Thanks a lot,
[java] gas2-event: 1330701201208
[java] INFO [2012-03-02 16:13:21,261] [ExpertSystem]
(ExpertVS.java:141) - **** eventRetracted: 1330701201232/30/32/0/100
[java] INFO [2012-03-02 16:13:31,224] [Thread-19]
(ExpertVS.java:135) - objectInserted
org.dfms.model.observation.GasObservation@1a30ef85
[java] INFO [2012-03-02 16:13:31,225] [Thread-19]
(ExpertVS.java:135) - objectInserted
org.dfms.model.observation.GasObservation@2bd1232
[java] INFO [2012-03-02 16:13:31,226] [Thread-19]
(ExpertVS.java:135) - objectInserted
org.dfms.model.observation.GasObservation@4045acb5
[java] INFO [2012-03-02 16:13:31,227] [Thread-19]
(ExpertVS.java:135) - objectInserted
org.dfms.model.observation.TemperatureObservation@1e4dc00a
[java] INFO [2012-03-02 16:13:31,227] [Thread-19]
(ExpertVS.java:135) - objectInserted
org.dfms.model.observation.HumidityObservation@27ae011
* [java] INFO [2012-03-02 16:13:31,227] [pool-1-thread-1]
(ExpertVS.java:124) - **** eventInserted: 1330701211226/30/32/0/100*
[java] INFO [2012-03-02 16:13:31,240] [Thread-19]
(ExpertVS.java:135) - objectInserted
org.dfms.model.observation.RadiationObservation@510c7d5c
[java] INFO [2012-03-02 16:13:31,251] [pool-1-thread-1]
(ExpertVS.java:143) - objectRetracted ==>[ObjectRetractedEventImpl:
getFactHandle()=1:105:45945394:45945394:105:lowLevelSensorStream,
getOldObject()=org.dfms.model.observation.GasObservation@2bd1232,
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@7224e11c,
getPropagationContext()=PropagationContextImpl [activeActivations=0,
dormantActivations=0, entryPoint=EntryPoint::lowLevelSensorStream,
factHandle=1:105:45945394:45945394:105:lowLevelSensorStream,
leftTuple=1:105:45945394:45945394:105:lowLevelSensorStream
[java] [fact
0:0:124232201:1306428912:0:DEFAULT:org.drools.reteoo.InitialFactImpl@4dde85f0
]
[java] , originOffset=-1, propagationNumber=220, rule=[Rule
name=gas2-event, agendaGroup=MAIN, salience=10, no-loop=true], type=1]]
[java] gas2-event: 1330701211203
* [java] INFO [2012-03-02 16:13:31,261] [ExpertSystem]
(ExpertVS.java:141) - **** eventRetracted: 1330701211226/30/32/0/100*
[java] INFO [2012-03-02 16:13:31,262] [ExpertSystem]
(ExpertVS.java:143) - objectRetracted ==>[ObjectRetractedEventImpl:
getFactHandle()=1:101:1512664237:1512664237:101:lowLevelSensorStream,
getOldObject()=org.dfms.model.observation.TemperatureObservation@5a296cad,
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@7224e11c,
getPropagationContext()=PropagationContextImpl [activeActivations=0,
dormantActivations=0, entryPoint=EntryPoint::lowLevelSensorStream,
factHandle=1:101:1512664237:1512664237:101:lowLevelSensorStream,
leftTuple=null, originOffset=-1, propagationNumber=224, rule=null, type=1]]
[java] INFO [2012-03-02 16:13:31,262] [ExpertSystem]
(ExpertVS.java:143) - objectRetracted ==>[ObjectRetractedEventImpl:
getFactHandle()=1:102:1436418073:1436418073:102:lowLevelSensorStream,
getOldObject()=org.dfms.model.observation.HumidityObservation@559e0019,
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@7224e11c,
getPropagationContext()=PropagationContextImpl [activeActivations=0,
dormantActivations=0, entryPoint=EntryPoint::lowLevelSensorStream,
factHandle=1:102:1436418073:1436418073:102:lowLevelSensorStream,
leftTuple=null, originOffset=-1, propagationNumber=226, rule=null, type=1]]
[java] INFO [2012-03-02 16:13:31,263] [ExpertSystem]
(ExpertVS.java:143) - objectRetracted ==>[ObjectRetractedEventImpl:
getFactHandle()=1:103:2014876984:2014876984:103:lowLevelSensorStream,
getOldObject()=org.dfms.model.observation.RadiationObservation@78189538,
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@7224e11c,
getPropagationContext()=PropagationContextImpl [activeActivations=0,
dormantActivations=0, entryPoint=EntryPoint::lowLevelSensorStream,
factHandle=1:103:2014876984:2014876984:103:lowLevelSensorStream,
leftTuple=null, originOffset=-1, propagationNumber=228, rule=null, type=1]]
[java] INFO [2012-03-02 16:13:41,228] [ExpertSystem]
(ExpertVS.java:143) - objectRetracted ==>[ObjectRetractedEventImpl:
getFactHandle()=1:108:508411914:508411914:108:lowLevelSensorStream,
getOldObject()=org.dfms.model.observation.TemperatureObservation@1e4dc00a,
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@7224e11c,
getPropagationContext()=PropagationContextImpl [activeActivations=0,
dormantActivations=0, entryPoint=EntryPoint::lowLevelSensorStream,
factHandle=1:108:508411914:508411914:108:lowLevelSensorStream,
leftTuple=null, originOffset=-1, propagationNumber=230, rule=null, type=1]]
[java] INFO [2012-03-02 16:13:41,230] [ExpertSystem]
(ExpertVS.java:143) - objectRetracted ==>[ObjectRetractedEventImpl:
getFactHandle()=1:109:41607185:41607185:109:lowLevelSensorStream,
getOldObject()=org.dfms.model.observation.HumidityObservation@27ae011,
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@7224e11c,
getPropagationContext()=PropagationContextImpl [activeActivations=0,
dormantActivations=0, entryPoint=EntryPoint::lowLevelSensorStream,
factHandle=1:109:41607185:41607185:109:lowLevelSensorStream,
leftTuple=null, originOffset=-1, propagationNumber=232, rule=null, type=1]]
12 years, 9 months
5.4.0.Beta2 parse error in consequence /* in string
by Benjamin Bennett
Just passing on I am using the drools 5.4.0Beta2
The following doesn't compile using the mvel dialect .
rule "some rule"
when
fact: Fact()
then
BasicFact fault= new BasicFact( "/*");
end
but
rule "some rule"
when
fact: Fact()
then
BasicFact fault= new BasicFact( "/ *");
end
does compile some how /* is being parsed as an expression I think and not a
string literal.
Thanks,
Ben
12 years, 10 months
limits on number of rules in Guvnor in a package, loaded in knowledge base
by vadlam
are there are any benchmarks around number of rules that can be created in a
package in Guvnor?
we run Guvnor 5.3.0.final in Guvnor on a windows server that has 1.4 GB heap
and we are seeing memory issues when the package has reached around 900
rules or so.
by memory issues, I mean that after the package is built successfully,
memory is not being released back. this behaviour is more obvious at such
high number of rules in package than when we had just around 600 rules or
so.
also, when we try to load the package generated (around 6.4 MB) into the
knowledgesession, it crashes the system .
are there any recommendations on
1. whether we can split up a package into two separate packages, and load
the 2 of them separately one after the other into the session ?
2. amount of memory that guvnor needs to build such high number of rules ?
3. ways to shrink the number of rules as per some best practices while
still meeting requirements ?
--
View this message in context: http://drools.46999.n3.nabble.com/limits-on-number-of-rules-in-Guvnor-in-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
Drools Guvnor 5.0.1 - Memory Usage Tuning
by tdakanalis
Hi,
We're using Drools Guvnor 5.0.1 in a production environment, running on
Tomcat 6. We're experiencing permgen issues, particularly when doing large
imports of rules, archiving, or compilation of rules.
Following permgen exceptions, we increased the permgen to :
-XX:MaxPermSize=2048M -ms3192M -mx3192M.
This sustained us for a while, but our assets are ever growing, and again
we're exceeding the permgen space allocated. Can someone recommend
appropriate settings/configuration in order to reduce the memory/cpu usage?
Assets in Guvnor:
~ 21K rules in 11 decision tables (.xls) in 1 package
Thanks,
Themistoklis Dakanalis
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-5-0-1-Memory-Usage-Tuning...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months