RemoveIdentities with KnowledgeAgent
by rjr201
Hi,
I'm using a KnowledgeAgent to create a KnowledgeBase. However, I need to
turn off Identities. In previous projects (not using knowledgeAgent) I've
done:
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setRemoveIdentities( true );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);
I'm sure there is a very similar approach with the KAgent, but I can't seem
work out what it is. I thought maybe something like this:
KnowledgeAgentConfiguration conf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
conf.setProperty("drools.removeIdentities", "true");
kagent = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent", conf);
But that doesn't seem to work. Any help with this would be greatly
appreciated.
Regards,
Rich.
--
View this message in context: http://drools.46999.n3.nabble.com/RemoveIdentities-with-KnowledgeAgent-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
Testing the count of a pattern binding variable
by David R Robison
I am developing rules using DSL so, from what I understand, I cannot use
collect and accumulate in some of my DSL definitions (especially when
using clauses that begin with a hyphen). So what I want to do is to test
the count of a pattern binding variable, such as
when
$sensors : Sensor()
accumulate($sensor; $count : count(1); $count > 3)
then
...
Is something like this possible? I cannot seem to make it work.
David
--
David R Robison
Open Roads Consulting, Inc.
103 Watson Road, Chesapeake, VA 23320
phone: (757) 546-3401
e-mail: drrobison(a)openroadsconsulting.com
web: http://openroadsconsulting.com
blog: http://therobe.blogspot.com
book: http://www.xulonpress.com/bookstore/bookdetail.php?PB_ISBN=9781597816526
This email communication (including any attachments) may contain confidential and/or privileged material intended solely for the individual or entity to which it is addressed.
If you are not the intended recipient, please delete this email immediately.
11 years, 9 months
Memory Leak in 5.4.0 and 5.5.0 [was: Garbage collection and sliding windows (Drools 5.5.0 Final)]
by Wolfgang Laun
With Drools 5.4.0.Final and 5.5.0.Final, automatic event retraction in
combination with a sliding window is broken, i.e., it suffers from a
memory leak. Full code for a demo has been posted by tai-atari; so I
just add some diagnostics that clearly indicate what goes wrong.
In the snapshot taken with jmap -histo:live after running the program
for several seconds and the insertion of 15800 AnEvent facts you can
see:
* several classes with 2000 instances each - AnEvents and the ones
required for bookkeeping the future expiry
* EventFactHandle, WindowTupleList, ObjectHashMap$ObjectEntry all
growing without restraint, indicating a memory leak.
num #instances #bytes class name
----------------------------------------------
1: 8747 8696096 [S
2: 26985 4110776 <constMethodKlass>
3: 26985 2161888 <methodKlass>
4: 47816 2046304 <symbolKlass>
5: 2414 1482672 <constantPoolKlass>
6: 6142 1434280 [I
7: 13800 1324800 org.drools.common.EventFactHandle
8: 2414 1056424 <instanceKlassKlass>
9: 1891 854664 <constantPoolCacheKlass>
10: 8348 644704 [C
11: 13800 441600 org.drools.reteoo.WindowTupleList
12: 2571 426976 [B
13: 15800 379200
org.drools.core.util.ObjectHashMap$ObjectEntry
14: 2672 256512 java.lang.Class
15: 545 246776 <methodDataKlass>
16: 7852 188448 java.lang.String
17: 4084 185496 [[I
18: 2000 176000 org.drools.common.PropagationContextImpl
19: 8 164288 [Lorg.drools.core.util.Entry;
20: 2000 160000 org.drools.common.AgendaItem
21: 2005 128320 org.drools.reteoo.WindowTuple
22: 2000 128000 org.drools.reteoo.RuleTerminalNodeLeftTuple
23: 2001 96048 java.util.concurrent.FutureTask$Sync
24: 2001 80040
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask
25: 1165 79152 [J
26: 229 75112 <objArrayKlassKlass>
27: 2001 64032
org.drools.time.impl.JDKTimerService$JDKJobHandle
28: 2001 64032 org.drools.time.impl.DefaultTimerJobInstance
29: 423 54728 [Ljava.lang.Object;
30: 2150 51600 java.util.LinkedList$Entry
31: 2052 49248 java.util.LinkedList
32: 2002 48048
org.drools.core.util.ObjectHashSet$ObjectEntry
33: 2001 48024 java.util.Date
34: 2000 48000
org.drools.reteoo.ObjectTypeNode$ExpireJobContext
35: 1958 46992 java.util.HashMap$Entry
36: 2261 36176 java.lang.Integer
37: 2006 32096 java.util.concurrent.atomic.AtomicBoolean
38: 2001 32016 org.drools.time.impl.PointInTimeTrigger
39: 2000 32000
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteExpireAction
40: 2000 32000 memcons.AnEvent
On 17/02/2013, tai-atari <p00temkin(a)gmail.com> wrote:
> Hi laune,
>
> Really appreciate you trying to reproduce the issue. Since you are not
> experiencing the same behavior I'm obviously missing something. I've
> attached a very simple example below which reproduces the scenario for the
> Drools versions I have tried so far: 5.2, 5.4 and 5.5.
>
> Basically this example runs an infinite loop which inserts 200 events about
> every second, and keeps a sliding window of 10 seconds. Every loop will
> print the current wm event count, which will increase to 2000 and stay put.
> This is where I expected the expired events to be available for garbage
> collection (since only 2000 are concurrently active in wm). But VisualVM
> shows that org.drools.common.EventFactHandle uses an increasing amount of
> memory over time.
>
> Start.java:
> ==================================
> package org.drools.example;
>
> import java.util.Random;
>
> import org.drools.KnowledgeBase;
> import org.drools.KnowledgeBaseConfiguration;
> import org.drools.KnowledgeBaseFactory;
> import org.drools.builder.KnowledgeBuilder;
> import org.drools.builder.KnowledgeBuilderError;
> import org.drools.builder.KnowledgeBuilderErrors;
> import org.drools.builder.KnowledgeBuilderFactory;
> import org.drools.builder.ResourceType;
> import org.drools.conf.EventProcessingOption;
> import org.drools.io.ResourceFactory;
> import org.drools.runtime.StatefulKnowledgeSession;
> import org.drools.runtime.rule.WorkingMemoryEntryPoint;
>
> public class Start {
>
> public static final void main(String[] args) {
> try {
>
> System.out.println("Init");
> KnowledgeBase kbase = readKnowledgeBase();
> StatefulKnowledgeSession ksession =
> kbase.newStatefulKnowledgeSession();
> WorkingMemoryEntryPoint eventStream =
> ksession.getWorkingMemoryEntryPoint("TheEventStream");
> Random randGen = new Random();
>
> while( true ) {
>
> // Insert 200
> int x = 0;
> while( x < 200 ) {
> AnEvent anEvent = new AnEvent();
> anEvent.setSource(randGen.nextInt());
> eventStream.insert(anEvent);
> ksession.fireAllRules();
> x++;
> }
>
> System.out.println("current event count in wm" + ": " +
> eventStream.getFactCount());
> Thread.sleep(1000);
> }
>
> //ksession.dispose();
>
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
>
> private static KnowledgeBase readKnowledgeBase() throws Exception {
>
> KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
> kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
> ResourceType.DRL);
> KnowledgeBuilderErrors errors = kbuilder.getErrors();
> if (errors.size() > 0) {
> for (KnowledgeBuilderError error: errors) {
> System.err.println(error);
> }
> throw new IllegalArgumentException("Could not parse
> knowledge.");
> }
>
> final KnowledgeBaseConfiguration kbConfig =
> KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
> kbConfig.setOption(EventProcessingOption.STREAM);
> KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConfig);
>
> kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
> return kbase;
> }
>
> }
> ==================================
>
> AnEvent.java:
> ==================================
> package org.drools.example;
>
> public class AnEvent {
>
> private Integer source;
>
> public AnEvent () {
> }
>
> public Integer getSource() {
> return source;
> }
>
> public void setSource(Integer source) {
> this.source = source;
> }
>
> }
> ==================================
>
> Sample.drl
> ==================================
> package org.drools.example
> import org.drools.example.AnEvent;
>
> declare AnEvent
> @role( event )
> end
>
> rule "Event print"
> when
> AnEvent ( $src: source ) over window:time(10s) from entry-point
> TheEventStream
> then
> System.out.println("---------> Received AnEvent from " + $src);
> end
> ==================================
>
> Also tried using an immutable pojo as you suggested cusmaimatteo, with
>
> AnEvent.java:
> ==================================
> package org.drools.example;
>
> public class AnEvent {
>
> private final Integer source;
>
> public AnEvent (Integer i) {
> this.source = i;
> }
>
> public Integer getSource() {
> return source;
> }
> }
> ==================================
>
> and using instead using
>
> eventStream.insert(new AnEvent(randGen.nextInt()));
>
> but with the same memory issues noted.
>
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Garbage-collection-and-sliding-windows-...
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
11 years, 9 months
Constants?
by Willem van Asperen
Hi All,
I have a bunch of rules that evaluate using some constant variable (say
"slackTicks"). Currently, in my rules, I write down the value of this
"slack" each and every time I use it, for example:
|TransferSchedule( tick > currentTick - 10d )|
where 10 is the slack.
A solution would be to insert constant facts:
|Constant( key = "slack", $slackTicks : value )||
||TransferSchedule( tick > currentTick - $slackTicks )|
Or inject a global properties object:
|global Properties constants||
||
||$slackTicks : Double.valueOf(constants.getPropertyValue("model.slack",
"0"))|
Or, the last one I can think of: a public final static on the fact class:
|TransferSchedule( tick > currentTick - TransferSchedule.SLACK_TICKS )||
|
These all cross the boundary between Java and Drools. In my Java code I
have to insert the Constant facts or inject the global. When my drools
developers think of some new ways to create the rules, I run the risk of
having to go in and modify the .properties file or, worse, change the
Java code.
To be able to define a "constant" would be a clean solution:
|declare||constant double SLACK_TICKS = 10||;
||||
...
||TransferSchedule( tick > currentTick - SLACK_TICKS )||
...
|
This separates the rules from the Java code and give the rules developer
all freedom to do whatever they want to make constant.
Ah, just thought of another way to do it. You can insert the facts from
within Drools itself:
|declare Constant||
|| key : String||
|| value : Object||
||end||
||
||rule initialize||
|| salience 100000||
|| when||
|| // always||
|| then||
|| insert( new Constant( "slack", 10d ) );||
|| //... other constants go here||
||end||
|
I will still have to "capture" the constants that I need in every rule
with a Constants( key == "...", $c : value ) premise, though... And you
would need to add some more Constant classes to cater to contain type
safety...
What's your thought? What strategy do you use?
Regards,
Willem
11 years, 9 months
Effective Dating of Rules
by MaverickDrools
Is there a way to effective date a rule through a program?
Requirement:
without using the Guvnor UI to write the rules, trying to upload a .drl file
using REST APIs which already has rules specified "without" the
date-effective/date-expire attributes. Is there a way to maintain versions
that could be used by effective dating the entire package itself?
Or in general, how do we effective date the rules in Guvnor without using
date-effective attributes for rules and create a knowledgebase from the
package based on the current date?
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Effective-Dating-of-Rules-tp4022422.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
incremental modification of dataset based on accumulate
by dharapvj
I would like to use drools in following scenario.
Say, I have a goal of producing 200 vehicles (each vehicle also has a random
priority). My factory can only produce 50 vehicles a day.. Thus, with this
constraint.. my 200 vehicles will get produced over next 4 days. I would
like to notify people as to when will each vehicle get produced.
First (topmost priority) 50 vehicles will get produced tomorrow. Next 50 day
after .. and so on.
So.. in drools, I am planning to insert the entire collection of 200
vehicles into ksession. Also, planning to insert the constraint of the
factory capacity of 50 and expect the date of production to be calculated.
I think I should use accumulate function for this.. but am not getting a
clear picture as to how to do this.
Can someone help?
--
View this message in context: http://drools.46999.n3.nabble.com/incremental-modification-of-dataset-bas...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
When - Then In DSL Rule
by IPatel
A basic question about writing DSL rules. I am not sure if i am using correct
terminology to ask the following question.
I have the following in my DSL Configuration:
[when] When the transcation is credit= $item:Item(CDIndicator == "Credit")
[then] Charge a fee = $item.setChargeFee (true)
[when] When the loan application is submitted =
$application:LoanApplication(Submitted == true)
Now in my business rules tab. I have the rule that when the loan application
is submitted then charge a fee.
so i selected something like this on the Business Rules tab:
When
1. When the loan application is submitted
THEN
1. Charge a fee
When i test this scenario, the system does not recognize "Then" part. So the
question is *Can i not use the "Then" part defined in DSL format with
different "When" part??*
--
View this message in context: http://drools.46999.n3.nabble.com/When-Then-In-DSL-Rule-tp4022407.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months