Re: [rules-users] counting Facts
Excuse the typo: s/$sgroup8/$group8/ -W On 23 July 2011 00:22, pamerida elp...@hotmail.com wrote: Hi everyone, I need to perform a count of facts, but my problem is that the facts are nested inside other facts My model would be something like this a class called Cuscar that is like the main class that contains the other facts inside the class Cuscar I have a list called segmentGroup7 (private ListSegmentGroup7 segmentGroup7), and inside each SegmentGroup7 I have another list (ListSegmentGroup8 segmentGroup8) with this rule Im able to get all the facts of the type segmentGroup8 $cuscar : Cuscar(); $group7: SegmentGroup7() from $cuscar.segmentGroup7; $group8 : SegmentGroup8() from $group7.segmentGroup8; but I would like to count the number of facts, any idea how?? thanks so much for your help :) -- View this message in context: http://drools.46999.n3.nabble.com/counting-Facts-tp3192513p3192513.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Guvnor - AccumulateFunction ClassCastException
I am having trouble getting my rule package, which contains areference to a custom accumulate function,to compile within Guvnor (5.2.0.Final on JBoss AS 5.1.0.GA). I have been using the same rules as DRL files without issue in Eclipse. I have tests which exercise the accumulate function and they are all passing. The error I get from Guvnor when I try to build the package is: Service method 'public abstract org.drools.guvnor.client.rpc.BuilderResult org.drools.guvnor.client.rpc.PackageService.buildPackage(java.lang.String,boolean,java.lang.String,java.lang.String,java.lang.String,boolean,java.lang.String,java.lang.String,boolean,java.lang.String) throws com.google.gwt.user.client.rpc.SerializationException' threw an unexpected exception: java.lang.ClassCastException: test.accumulate.BigIntegerSumAccumulateFunction cannot be cast to org.drools.runtime.rule.AccumulateFunction I've isolated the problem into a reproducible test, or rather a set of steps: 1.Compile the attached BigIntegerSumAccumulateFunction.java into a jar and copy the jar to the JBoss server's lib folder. 2. Start up JBoss. 3.Create a new package in Guvnor. I called mine "test". 4. Create a new fact that has a numeric property. Here's mine: declare Foo value : int end 5. Upload the attached drools.packagebuilder.conf to the Guvnor package. 6. Createa new rule that references the custom accumulate function: when BigInteger() from accumulate( Foo( $v : value), bigIntegerSum( $v ) ) then System.out.println("test"); 7. Try to build the binary package in Guvnor. The error listed above occurs. Please see the end of this email for a full stack trace. It's telling me that my custom accumulate function can't be cast to org.drools.runtime.rule.AccumulateFunction, but I have a unit test (also attached) that proves that it can. Again, I have other tests which exercise rules that reference the accumulate function and they compile and work fine. Any thoughts? Why does the Guvnor compiler work differently from when I build my knowledge base in code? Thanks in advance for any assistance. Mike Melton FULL STACK TRACE: java.lang.ClassCastException: test.accumulate.BigIntegerSumAccumulateFunction cannot be cast to org.drools.runtime.rule.AccumulateFunctionat org.drools.compiler.PackageBuilderConfiguration.loadAccumulateFunction(PackageBuilderConfiguration.java:491)at org.drools.compiler.PackageBuilderConfiguration.buildAccumulateFunctionsMap(PackageBuilderConfiguration.java:440)at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:177)at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:148)at org.drools.guvnor.server.builder.BRMSPackageBuilder.getPackageBuilderConfiguration(BRMSPackageBuilder.java:134)at org.drools.guvnor.server.builder.BRMSPackageBuilder.init(BRMSPackageBuilder.java:67)at org.drools.guvnor.server.builder.AssemblerBase.createBuilder(AssemblerBase.java:46)at org.drools.guvnor.server.builder.PackageAssembler.createBuilder(PackageAssembler.java:35)at org.drools.guvnor.server.builder.AssemblerBase.init(AssemblerBase.java:42)at org.drools.guvnor.server.builder.PackageAssemblerBase.init(PackageAssemblerBase.java:44)at org.drools.guvnor.server.builder.PackageAssembler.init(PackageAssembler.java:49)at org.drools.guvnor.server.RepositoryPackageOperations.buildPackage(RepositoryPackageOperations.java:522)at org.drools.guvnor.server.RepositoryPackageOperations.buildPackage(RepositoryPackageOperations.java:480)at org.drools.guvnor.server.RepositoryPackageService.buildPackage(RepositoryPackageService.java:299)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)at org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:157)at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)at
[rules-users] Temporal rule doesn't fire in STREAM mode
Hello, I have been fighting with this issue for several days, and I just stumbled upon the reason why, but that raised another question for me. I have a rule checking that two events of the same type do not occur in succession without an event of a specific other type in between them: # If two WorkerInWorkEvents exist for a worker, there must be a WorkerOutOfWorkEvent between them rule ERROR: Consecutive WorkerInWorkEvents when $w1 : WorkerInWorkEvent( $workerId : workerId ) $w2 : WorkerInWorkEvent( workerId == $workerId, this after $w1 ) not WorkerOutOfWorkEvent( workerId == $workerId, this after $w1, this before $w2 ) then errors.add(Two WorkerInWorkEvents without a WorkerOutOfWorkEvent in between ( + $w2 + )); retract( $w2 ); end I could see via the log that this file was activating, however it was never firing. The retraction of $w2 should have cancelled other rules' activations, but it wasn't doing so because this rule was never firing. I just discovered a thread (http://drools.46999.n3.nabble.com/Drools-fusion-and-absence-of-events-td51125.html) which finally explained to me the reason why: I was running in STREAM mode, and the engine was waiting to see if a WorkerOutOfWorkEvent timestamped between the two WorkerInWorkEvents was going to show up. When I switched to CLOUD mode, the rule fired as expected and my other activations were cancelled as I expected. Now, my new question is: Since I have not specified any intervals, how long will the engine wait for the WorkerOutOfWorkEvent to show up? Forever? Thanks in advance for any light you can shed on this. Mike ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Deprecated Drools packages?
I keep seeing mentioned on the mailing list packages which have been deprecated (or are not part of the stable release), but I have not seen any javadocs or other documentation (and google has been no help) indicating *which* packages I should avoid using. Every time Eclipse gives me a choice between two packages for a Drools class, I am unsure which one to pick. Apologies if I've missed something obvious, but can someone educate me? Thanks! Mike ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Temporal rule doesn't fire in STREAM mode
Inline. 2011/7/25 Melton, Michael P CTR SPAWARSYSCEN-ATLANTIC, 01200 michael.melton@navy.mil # If two WorkerInWorkEvents exist for a worker, there must be a WorkerOutOfWorkEvent between them rule ERROR: Consecutive WorkerInWorkEvents when $w1 : WorkerInWorkEvent( $workerId : workerId ) $w2 : WorkerInWorkEvent( workerId == $workerId, this after $w1 ) not WorkerOutOfWorkEvent( workerId == $workerId, this after $w1, this before $w2 ) then errors.add(Two WorkerInWorkEvents without a WorkerOutOfWorkEvent in between ( + $w2 + )); retract( $w2 ); end I'd say that this after $w1 makes the Engine wait for ever since after is not bounded. That the truth of $w2 after $w1 is established before the not needs to be evaluated and that this, in combination with this before $w2 effectually limits the waiting as soon as the second CE is matched is something that would need symbolic expression interpretation - something that's not so easy to program. Feel free to raise a JIRA if you think otherwise. However, temporal reasoning with several flank events is tricky. My advice would be to try retain at most one of each kind in WM, and combine them into a WorkerWorking event with a duration as soon as possible. Then - a WorkerOutOfWorkEvent without a matching WorkerInWorkEvent is an error and retracts it - a WorkerOutOfWorkEvent with a matching WorkerInWorkEvent creates a WorkerWorking event and retracts both - a WorkerInWorkEvent during a WorkerWorking is an error etc. - (etc) -W I could see via the log that this file was activating, however it was never firing. The retraction of $w2 should have cancelled other rules' activations, but it wasn't doing so because this rule was never firing. I just discovered a thread ( http://drools.46999.n3.nabble.com/Drools-fusion-and-absence-of-events-td51125.html) which finally explained to me the reason why: I was running in STREAM mode, and the engine was waiting to see if a WorkerOutOfWorkEvent timestamped between the two WorkerInWorkEvents was going to show up. When I switched to CLOUD mode, the rule fired as expected and my other activations were cancelled as I expected. Now, my new question is: Since I have not specified any intervals, how long will the engine wait for the WorkerOutOfWorkEvent to show up? Forever? Thanks in advance for any light you can shed on this. Mike ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counting Facts
Thanks man it works perfectly... :) But I have another scenario where inside each SegmentGroup7 theres a SegmentGroup14 and inside this group I have to verify a value inside another class called GoodsItemDetails, as in my last post I can collect all the occurrences with this code : $cuscar : Cuscar(); $group7: SegmentGroup7() from $cuscar.segmentGroup7; $group8 : SegmentGroup8() from $group7.segmentGroup8; $group14 : SegmentGroup14() from $group8.segmentGroup14; GoodsItemDetails(c7064 == 9 from $group14.gid ); but again I want to count the number of facts, is there a way to do this?? thanks so much in advance for your suggestions :) -- View this message in context: http://drools.46999.n3.nabble.com/counting-Facts-tp3192513p3197756.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Temporal rule doesn't fire in STREAM mode
Wolfgang, Your suggestions are wonderful advice and make perfect sense. I'm shaking my head a little for not thinking of it myself. Many thanks, Mike -- View this message in context: http://drools.46999.n3.nabble.com/rules-users-Temporal-rule-doesn-t-fire-in-STREAM-mode-tp3197365p3198029.html Sent from the Drools: User forum mailing list archive at Nabble.com.___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counting Facts
Wouldn't you be better off by writing one or two static methods or DRL functions to compute these sums? Going down from, down from, down from a fact in WM is not really a good design pattern. -W On 25 July 2011 17:20, pamerida elp...@hotmail.com wrote: Thanks man it works perfectly... :) But I have another scenario where inside each SegmentGroup7 theres a SegmentGroup14 and inside this group I have to verify a value inside another class called GoodsItemDetails, as in my last post I can collect all the occurrences with this code : $cuscar : Cuscar(); $group7: SegmentGroup7() from $cuscar.segmentGroup7; $group8 : SegmentGroup8() from $group7.segmentGroup8; $group14 : SegmentGroup14() from $group8.segmentGroup14; GoodsItemDetails(c7064 == 9 from $group14.gid ); but again I want to count the number of facts, is there a way to do this?? thanks so much in advance for your suggestions :) -- View this message in context: http://drools.46999.n3.nabble.com/counting-Facts-tp3192513p3197756.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Guvnor - AccumulateFunction ClassCastException
This is looking like a classloader issue. I assume your function is correctly implementing the org.drools.runtime.rule.AccumulateFunction, as you mention that it works outside of guvnor. So my guess is that your function jar is being loaded by a classloader in a different hierarchy and that is raising the CCE? Edson 2011/7/25 Melton, Michael P CTR SPAWARSYSCEN-ATLANTIC, 01200 michael.melton@navy.mil I am having trouble getting my rule package, which contains a reference to a custom accumulate function, to compile within Guvnor (5.2.0.Final on JBoss AS 5.1.0.GA). I have been using the same rules as DRL files without issue in Eclipse. I have tests which exercise the accumulate function and they are all passing. The error I get from Guvnor when I try to build the package is: Service method 'public abstract org.drools.guvnor.client.rpc.BuilderResult org.drools.guvnor.client.rpc.PackageService.buildPackage(java.lang.String,boolean,java.lang.String,java.lang.String,java.lang.String,boolean,java.lang.String,java.lang.String,boolean,java.lang.String) throws com.google.gwt.user.client.rpc.SerializationException' threw an unexpected exception: java.lang.ClassCastException: test.accumulate.BigIntegerSumAccumulateFunction cannot be cast to org.drools.runtime.rule.AccumulateFunction I've isolated the problem into a reproducible test, or rather a set of steps: 1. Compile the attached BigIntegerSumAccumulateFunction.java into a jar and copy the jar to the JBoss server's lib folder. 2. Start up JBoss. 3. Create a new package in Guvnor. I called mine test. 4. Create a new fact that has a numeric property. Here's mine: declare Foo value : int end 5. Upload the attached drools.packagebuilder.conf to the Guvnor package. 6. Create a new rule that references the custom accumulate function: when BigInteger() from accumulate( Foo( $v : value), bigIntegerSum( $v ) ) then System.out.println(test); 7. Try to build the binary package in Guvnor. The error listed above occurs. Please see the end of this email for a full stack trace. It's telling me that my custom accumulate function can't be cast to org.drools.runtime.rule.AccumulateFunction, but I have a unit test (also attached) that proves that it can. Again, I have other tests which exercise rules that reference the accumulate function and they compile and work fine. Any thoughts? Why does the Guvnor compiler work differently from when I build my knowledge base in code? Thanks in advance for any assistance. Mike Melton FULL STACK TRACE: java.lang.ClassCastException: test.accumulate.BigIntegerSumAccumulateFunction cannot be cast to org.drools.runtime.rule.AccumulateFunction at org.drools.compiler.PackageBuilderConfiguration.loadAccumulateFunction(PackageBuilderConfiguration.java:491) at org.drools.compiler.PackageBuilderConfiguration.buildAccumulateFunctionsMap(PackageBuilderConfiguration.java:440) at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:177) at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:148) at org.drools.guvnor.server.builder.BRMSPackageBuilder.getPackageBuilderConfiguration(BRMSPackageBuilder.java:134) at org.drools.guvnor.server.builder.BRMSPackageBuilder.init(BRMSPackageBuilder.java:67) at org.drools.guvnor.server.builder.AssemblerBase.createBuilder(AssemblerBase.java:46) at org.drools.guvnor.server.builder.PackageAssembler.createBuilder(PackageAssembler.java:35) at org.drools.guvnor.server.builder.AssemblerBase.init(AssemblerBase.java:42) at org.drools.guvnor.server.builder.PackageAssemblerBase.init(PackageAssemblerBase.java:44) at org.drools.guvnor.server.builder.PackageAssembler.init(PackageAssembler.java:49) at org.drools.guvnor.server.RepositoryPackageOperations.buildPackage(RepositoryPackageOperations.java:522) at org.drools.guvnor.server.RepositoryPackageOperations.buildPackage(RepositoryPackageOperations.java:480) at org.drools.guvnor.server.RepositoryPackageService.buildPackage(RepositoryPackageService.java:299) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) at
Re: [rules-users] How to use OR-Operator
you can create two rule... rule or_conjunction_one when eventA : EventA(status == true) from entry-point StreamA then System.out.println(A); end rule or_conjunction_two when eventB : EventB(status == true) from entry-point StreamB then System.out.println(B); end - with kind regards, -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use-OR-Operator-tp3197784p3198114.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counting Facts
Am 25.07.2011 19:29, schrieb pamerida: if I insert int the WM the SegmentGruoup7 (that inside contains the SegmentGroup8) and then I insert SegmentGroup8 in the WM, wouldnt that be duplicating the information? or drools just holds a reference to this classes, IIRC, Drools creates an additional FactHandle for each object reference you insert into the working memory, but these handles are lightweight. So the actual 'data' is not duplicated, only Drools-internal references are. Best regards Ansgar ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reclaiming memory usage
Chris, I haven't tried your code, but just looking at the rule, there is no temporal correlation between DataReading and ReconfigEvent, so if I am not mistaken, that will create a required interval of infinite time when the temporal reasoning is applied, meaning the engine has to keep the readings in memory forever. Adding a temporal constraint on the ReconfigEvent pattern on your rule or defining an explicit expiration policy for the DataReadings are ways to work around that. Edson 2011/7/26 Chris Richmond crichm...@referentia.com Hello I am performing a simple test of injecting an event every 1 millisecond like so: for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } The rule that evaluates this is simple. It basically delays then for 3s to see if a followup reading is inserted and makes sure that no ReconfigEvent is active(5s expiration). So if a reading comes in and a followup reading is not inserted within 3 seconds and there is is not an existing ReconfigEvent event alive, then it should output and insert a ReconfigEvent, essentially disabling any DataReading action on those events for the next 5 seconds or so. This all works just fine as expected. My question is, how come I don't get memory back when all 100,000 of my events have been inserted. Memory goes up slowly over the course of insertions, which I can understand, but once that loop is finished, memory never reduces, so essentially, the application will eventually run out of memory after some time. I should not have to explicitly remove/retract events should I? Shouldn't they be removed from working memory as soon as they are no longer viable? What should I be doing to reclaim memory from the session/knowledgebase? I have included the full Main program here and the Sample.drl file below it. FusionMain.java* package com.sample; 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.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.runtime.KnowledgeSessionConfiguration; import org.drools.runtime.StatefulKnowledgeSession; import org.drools.runtime.conf.ClockTypeOption; import org.drools.runtime.rule.WorkingMemoryEntryPoint; public class FusionMain { @SuppressWarnings(restriction) public static void main(String[] args) { try { KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption( ClockTypeOption.get(realtime) ); KnowledgeBase kbase; kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); WorkingMemoryEntryPoint myStream = ksession.getWorkingMemoryEntryPoint(My Stream); for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @SuppressWarnings(restriction) 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.); } KnowledgeBaseConfiguration kbConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbConfig.setOption( EventProcessingOption.STREAM ); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConfig); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); return kbase; } } *Sample.drl* package com.sample import java.util.Date; declare DataReading @role( event ) end declare ReconfigEvent @role( event ) @expires ( 5s ) end rule Wait for follup reading or no config //lock-on-active when $dr: DataReading(reading 10.0) from entry-point My Stream not(DataReading(reading 10.0, this after[0s,3s] $dr) from entry-point My Stream) not(ReconfigEvent()
Re: [rules-users] counting Facts
Thanks for the info, I will try that... -- View this message in context: http://drools.46999.n3.nabble.com/counting-Facts-tp3192513p3198936.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reclaiming memory usage
Edson, I was under the impression that this: declare ReconfigEvent @role( event ) @expires ( 5s ) end would cover that, meaning that every ReconfigEvent would expire after 5s, thus causing to no longer be needed by the engine. Thanks, Chris On 7/25/2011 12:17 PM, Edson Tirelli wrote: Chris, I haven't tried your code, but just looking at the rule, there is no temporal correlation between DataReading and ReconfigEvent, so if I am not mistaken, that will create a required interval of infinite time when the temporal reasoning is applied, meaning the engine has to keep the readings in memory forever. Adding a temporal constraint on the ReconfigEvent pattern on your rule or defining an explicit expiration policy for the DataReadings are ways to work around that. Edson 2011/7/26 Chris Richmond crichm...@referentia.com mailto:crichm...@referentia.com Hello I am performing a simple test of injecting an event every 1 millisecond like so: for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } The rule that evaluates this is simple. It basically delays then for 3s to see if a followup reading is inserted and makes sure that no ReconfigEvent is active(5s expiration). So if a reading comes in and a followup reading is not inserted within 3 seconds and there is is not an existing ReconfigEvent event alive, then it should output and insert a ReconfigEvent, essentially disabling any DataReading action on those events for the next 5 seconds or so. This all works just fine as expected. My question is, how come I don't get memory back when all 100,000 of my events have been inserted. Memory goes up slowly over the course of insertions, which I can understand, but once that loop is finished, memory never reduces, so essentially, the application will eventually run out of memory after some time. I should not have to explicitly remove/retract events should I? Shouldn't they be removed from working memory as soon as they are no longer viable? What should I be doing to reclaim memory from the session/knowledgebase? I have included the full Main program here and the Sample.drl file below it. FusionMain.java* package com.sample; 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.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.runtime.KnowledgeSessionConfiguration; import org.drools.runtime.StatefulKnowledgeSession; import org.drools.runtime.conf.ClockTypeOption; import org.drools.runtime.rule.WorkingMemoryEntryPoint; public class FusionMain { @SuppressWarnings(restriction) public static void main(String[] args) { try { KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption( ClockTypeOption.get(realtime) ); KnowledgeBase kbase; kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); WorkingMemoryEntryPoint myStream = ksession.getWorkingMemoryEntryPoint(My Stream); for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @SuppressWarnings(restriction) 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.); } KnowledgeBaseConfiguration kbConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbConfig.setOption( EventProcessingOption.STREAM );
Re: [rules-users] Reclaiming memory usage
Chris That defines the expiration policy for ReconfigEvent, but it does not define the relationship between ReconfigEvent and DataReading. Imagine a timeline, dotted with ReconfigEvents... what your rule is saying is for each DataReading event, match it with all the periods where there is no ReconfigEvent, as the lifetime of DataReading is infinity. Maybe a simpler way of understanding it (without using the not for simplification) is think about this: declare Man @livesUpTo( 100 years ) end rule marriage when $w : Woman( age 18 ) $m : Man( ) then // marry woman and man end The rule above defines that each woman will merry every existing man, even if each of them only lives for 100 years. Edson 2011/7/26 Chris Richmond crichm...@referentia.com ** Edson, I was under the impression that this: declare ReconfigEvent @role( event ) @expires ( 5s ) end would cover that, meaning that every ReconfigEvent would expire after 5s, thus causing to no longer be needed by the engine. Thanks, Chris On 7/25/2011 12:17 PM, Edson Tirelli wrote: Chris, I haven't tried your code, but just looking at the rule, there is no temporal correlation between DataReading and ReconfigEvent, so if I am not mistaken, that will create a required interval of infinite time when the temporal reasoning is applied, meaning the engine has to keep the readings in memory forever. Adding a temporal constraint on the ReconfigEvent pattern on your rule or defining an explicit expiration policy for the DataReadings are ways to work around that. Edson 2011/7/26 Chris Richmond crichm...@referentia.com Hello I am performing a simple test of injecting an event every 1 millisecond like so: for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } The rule that evaluates this is simple. It basically delays then for 3s to see if a followup reading is inserted and makes sure that no ReconfigEvent is active(5s expiration). So if a reading comes in and a followup reading is not inserted within 3 seconds and there is is not an existing ReconfigEvent event alive, then it should output and insert a ReconfigEvent, essentially disabling any DataReading action on those events for the next 5 seconds or so. This all works just fine as expected. My question is, how come I don't get memory back when all 100,000 of my events have been inserted. Memory goes up slowly over the course of insertions, which I can understand, but once that loop is finished, memory never reduces, so essentially, the application will eventually run out of memory after some time. I should not have to explicitly remove/retract events should I? Shouldn't they be removed from working memory as soon as they are no longer viable? What should I be doing to reclaim memory from the session/knowledgebase? I have included the full Main program here and the Sample.drl file below it. FusionMain.java* package com.sample; 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.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.runtime.KnowledgeSessionConfiguration; import org.drools.runtime.StatefulKnowledgeSession; import org.drools.runtime.conf.ClockTypeOption; import org.drools.runtime.rule.WorkingMemoryEntryPoint; public class FusionMain { @SuppressWarnings(restriction) public static void main(String[] args) { try { KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption( ClockTypeOption.get(realtime) ); KnowledgeBase kbase; kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); WorkingMemoryEntryPoint myStream = ksession.getWorkingMemoryEntryPoint(My Stream); for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @SuppressWarnings(restriction) private static KnowledgeBase readKnowledgeBase() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
Re: [rules-users] Reclaiming memory usage
Ok, well how to make them marry only those alive(100 years old) and ensure all those over 100 years old go out of memory? Chris On 7/25/2011 2:32 PM, Edson Tirelli wrote: Chris That defines the expiration policy for ReconfigEvent, but it does not define the relationship between ReconfigEvent and DataReading. Imagine a timeline, dotted with ReconfigEvents... what your rule is saying is for each DataReading event, match it with all the periods where there is no ReconfigEvent, as the lifetime of DataReading is infinity. Maybe a simpler way of understanding it (without using the not for simplification) is think about this: declare Man @livesUpTo( 100 years ) end rule marriage when $w : Woman( age 18 ) $m : Man( ) then // marry woman and man end The rule above defines that each woman will merry every existing man, even if each of them only lives for 100 years. Edson 2011/7/26 Chris Richmond crichm...@referentia.com mailto:crichm...@referentia.com Edson, I was under the impression that this: declare ReconfigEvent @role( event ) @expires ( 5s ) end would cover that, meaning that every ReconfigEvent would expire after 5s, thus causing to no longer be needed by the engine. Thanks, Chris On 7/25/2011 12:17 PM, Edson Tirelli wrote: Chris, I haven't tried your code, but just looking at the rule, there is no temporal correlation between DataReading and ReconfigEvent, so if I am not mistaken, that will create a required interval of infinite time when the temporal reasoning is applied, meaning the engine has to keep the readings in memory forever. Adding a temporal constraint on the ReconfigEvent pattern on your rule or defining an explicit expiration policy for the DataReadings are ways to work around that. Edson 2011/7/26 Chris Richmond crichm...@referentia.com mailto:crichm...@referentia.com Hello I am performing a simple test of injecting an event every 1 millisecond like so: for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } The rule that evaluates this is simple. It basically delays then for 3s to see if a followup reading is inserted and makes sure that no ReconfigEvent is active(5s expiration). So if a reading comes in and a followup reading is not inserted within 3 seconds and there is is not an existing ReconfigEvent event alive, then it should output and insert a ReconfigEvent, essentially disabling any DataReading action on those events for the next 5 seconds or so. This all works just fine as expected. My question is, how come I don't get memory back when all 100,000 of my events have been inserted. Memory goes up slowly over the course of insertions, which I can understand, but once that loop is finished, memory never reduces, so essentially, the application will eventually run out of memory after some time. I should not have to explicitly remove/retract events should I? Shouldn't they be removed from working memory as soon as they are no longer viable? What should I be doing to reclaim memory from the session/knowledgebase? I have included the full Main program here and the Sample.drl file below it. FusionMain.java* package com.sample; 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.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.runtime.KnowledgeSessionConfiguration; import org.drools.runtime.StatefulKnowledgeSession; import org.drools.runtime.conf.ClockTypeOption; import org.drools.runtime.rule.WorkingMemoryEntryPoint; public class FusionMain { @SuppressWarnings(restriction) public static void main(String[] args) { try { KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption(
Re: [rules-users] Reclaiming memory usage
Hi Chris, Best way is to explicitly define the relationship with a temporal constraint (although there are other ways). E.g.: when $dr: DataReading(reading 10.0) from entry-point My Stream not(DataReading(reading 10.0, this after[0s,3s] $dr) from entry-point My Stream) not(ReconfigEvent( this before[0,5s] $dr ) from entry-point My Stream) then As we evolve the product I believe we can add defaults and other types of policies to the system that will allow for other ways to define these relationships, but the system, at the moment, will use strict temporal logic and if no temporal join is defined, it will cross product like it would with non-temporal constraints... and that means keeping everything in memory. Edson 2011/7/26 Chris Richmond crichm...@referentia.com ** Ok, well how to make them marry only those alive(100 years old) and ensure all those over 100 years old go out of memory? Chris On 7/25/2011 2:32 PM, Edson Tirelli wrote: Chris That defines the expiration policy for ReconfigEvent, but it does not define the relationship between ReconfigEvent and DataReading. Imagine a timeline, dotted with ReconfigEvents... what your rule is saying is for each DataReading event, match it with all the periods where there is no ReconfigEvent, as the lifetime of DataReading is infinity. Maybe a simpler way of understanding it (without using the not for simplification) is think about this: declare Man @livesUpTo( 100 years ) end rule marriage when $w : Woman( age 18 ) $m : Man( ) then // marry woman and man end The rule above defines that each woman will merry every existing man, even if each of them only lives for 100 years. Edson 2011/7/26 Chris Richmond crichm...@referentia.com Edson, I was under the impression that this: declare ReconfigEvent @role( event ) @expires ( 5s ) end would cover that, meaning that every ReconfigEvent would expire after 5s, thus causing to no longer be needed by the engine. Thanks, Chris On 7/25/2011 12:17 PM, Edson Tirelli wrote: Chris, I haven't tried your code, but just looking at the rule, there is no temporal correlation between DataReading and ReconfigEvent, so if I am not mistaken, that will create a required interval of infinite time when the temporal reasoning is applied, meaning the engine has to keep the readings in memory forever. Adding a temporal constraint on the ReconfigEvent pattern on your rule or defining an explicit expiration policy for the DataReadings are ways to work around that. Edson 2011/7/26 Chris Richmond crichm...@referentia.com Hello I am performing a simple test of injecting an event every 1 millisecond like so: for (int x = 0; x 10; x++){ DataReading dr = new DataReading(Reading + x, 12.0f); myStream.insert(dr); ksession.fireAllRules(); Thread.sleep(1); } The rule that evaluates this is simple. It basically delays then for 3s to see if a followup reading is inserted and makes sure that no ReconfigEvent is active(5s expiration). So if a reading comes in and a followup reading is not inserted within 3 seconds and there is is not an existing ReconfigEvent event alive, then it should output and insert a ReconfigEvent, essentially disabling any DataReading action on those events for the next 5 seconds or so. This all works just fine as expected. My question is, how come I don't get memory back when all 100,000 of my events have been inserted. Memory goes up slowly over the course of insertions, which I can understand, but once that loop is finished, memory never reduces, so essentially, the application will eventually run out of memory after some time. I should not have to explicitly remove/retract events should I? Shouldn't they be removed from working memory as soon as they are no longer viable? What should I be doing to reclaim memory from the session/knowledgebase? I have included the full Main program here and the Sample.drl file below it. FusionMain.java* package com.sample; 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.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.runtime.KnowledgeSessionConfiguration; import org.drools.runtime.StatefulKnowledgeSession; import org.drools.runtime.conf.ClockTypeOption; import org.drools.runtime.rule.WorkingMemoryEntryPoint; public class FusionMain {