<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Edson,<br>
    <br>
    I was under the impression that this:<br>
    <br>
    declare ReconfigEvent<br>
    &nbsp; &nbsp; @role( event )<br>
    &nbsp; &nbsp; @expires ( 5s )<br>
    end<br>
    <br>
    would cover that, meaning that every ReconfigEvent would expire
    after 5s, thus causing to no longer be needed by the engine.<br>
    <br>
    Thanks,<br>
    Chris<br>
    <br>
    On 7/25/2011 12:17 PM, Edson Tirelli wrote:
    <blockquote
cite="mid:CAD7AJne_igvwAuJ3jKkLwZJ41g6=z0vB3sp70NULdiVNUxaw+w@mail.gmail.com"
      type="cite">
      <div><br>
      </div>
      &nbsp;&nbsp; Chris,
      <div><br>
      </div>
      <div>&nbsp;&nbsp; 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.&nbsp;</div>
      <div><br>
      </div>
      <div>&nbsp;&nbsp; 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.</div>
      <div><br>
      </div>
      <div>&nbsp;&nbsp; Edson<br>
        <br>
        <div class="gmail_quote">2011/7/26 Chris Richmond <span
            dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>&gt;</span><br>
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            padding-left: 1ex;">
            Hello<br>
            <br>
            I am performing a simple test of injecting an event every 1
            millisecond<br>
            like so:<br>
            <br>
            &nbsp; &nbsp; &nbsp; for (int x = 0; x &lt; 100000; x++){<br>
            &nbsp; &nbsp; &nbsp; &nbsp; DataReading dr = new DataReading("Reading " + x,
            12.0f);<br>
            &nbsp; &nbsp; &nbsp; &nbsp; myStream.insert(dr);<br>
            &nbsp; &nbsp; &nbsp; &nbsp; ksession.fireAllRules();<br>
            &nbsp; &nbsp; &nbsp; &nbsp; Thread.sleep(1);<br>
            <br>
            &nbsp; &nbsp; &nbsp; }<br>
            <br>
            <br>
            The rule that evaluates this is simple. &nbsp;It basically delays
            "then" for<br>
            3s to see if a followup reading is inserted and makes sure
            that no<br>
            ReconfigEvent is active(5s expiration).<br>
            <br>
            So if a reading comes in and a followup reading is not
            inserted within 3<br>
            seconds and there is is not an existing ReconfigEvent event
            alive, then<br>
            it should output and insert a ReconfigEvent, essentially
            disabling any<br>
            DataReading action on those events for the next 5 seconds or
            so. &nbsp;This<br>
            all works just fine as expected.<br>
            <br>
            My question is, how come I don't get memory back when all
            100,000 of my<br>
            events have been inserted. &nbsp;Memory goes up slowly over the
            course of<br>
            insertions, which I can understand, but once that loop is
            finished,<br>
            memory never reduces, so essentially, the application will
            eventually<br>
            run out of memory after some time. &nbsp; I should not have to
            explicitly<br>
            remove/retract events should I? Shouldn't they be removed
            from working<br>
            memory as soon as they are no longer viable? &nbsp;What should I
            be doing to<br>
            reclaim memory from the session/knowledgebase?<br>
            <br>
            I have included the full Main program here and the
            Sample.drl file below it.<br>
            <br>
            ************FusionMain.java*****************<br>
            <br>
            package com.sample;<br>
            <br>
            import org.drools.KnowledgeBase;<br>
            import org.drools.KnowledgeBaseConfiguration;<br>
            import org.drools.KnowledgeBaseFactory;<br>
            import org.drools.builder.KnowledgeBuilder;<br>
            import org.drools.builder.KnowledgeBuilderError;<br>
            import org.drools.builder.KnowledgeBuilderErrors;<br>
            import org.drools.builder.KnowledgeBuilderFactory;<br>
            import org.drools.builder.ResourceType;<br>
            import org.drools.conf.EventProcessingOption;<br>
            import org.drools.io.ResourceFactory;<br>
            import org.drools.logger.KnowledgeRuntimeLogger;<br>
            import org.drools.logger.KnowledgeRuntimeLoggerFactory;<br>
            import org.drools.runtime.KnowledgeSessionConfiguration;<br>
            import org.drools.runtime.StatefulKnowledgeSession;<br>
            import org.drools.runtime.conf.ClockTypeOption;<br>
            import org.drools.runtime.rule.WorkingMemoryEntryPoint;<br>
            <br>
            <br>
            public class FusionMain {<br>
            <br>
            &nbsp; @SuppressWarnings("restriction")<br>
            &nbsp; public static void main(String[] args) {<br>
            <br>
            <br>
            &nbsp; &nbsp; try {<br>
            <br>
            &nbsp; &nbsp; &nbsp; KnowledgeSessionConfiguration config =<br>
            KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
            &nbsp; &nbsp; &nbsp; config.setOption( ClockTypeOption.get("realtime") );<br>
            <br>
            <br>
            &nbsp; &nbsp; &nbsp; KnowledgeBase kbase;<br>
            &nbsp; &nbsp; &nbsp; kbase = readKnowledgeBase();<br>
            &nbsp; &nbsp; &nbsp; StatefulKnowledgeSession ksession =<br>
            kbase.newStatefulKnowledgeSession();<br>
            <br>
            &nbsp; &nbsp; &nbsp; WorkingMemoryEntryPoint myStream =<br>
            ksession.getWorkingMemoryEntryPoint("My Stream");<br>
            <br>
            &nbsp; &nbsp; &nbsp; for (int x = 0; x &lt; 100000; x++){<br>
            &nbsp; &nbsp; &nbsp; &nbsp; DataReading dr = new DataReading("Reading " + x,
            12.0f);<br>
            &nbsp; &nbsp; &nbsp; &nbsp; myStream.insert(dr);<br>
            &nbsp; &nbsp; &nbsp; &nbsp; ksession.fireAllRules();<br>
            &nbsp; &nbsp; &nbsp; &nbsp; Thread.sleep(1);<br>
            <br>
            &nbsp; &nbsp; &nbsp; }<br>
            <br>
            &nbsp; &nbsp; } catch (Exception e) {<br>
            &nbsp; &nbsp; &nbsp; // TODO Auto-generated catch block<br>
            &nbsp; &nbsp; &nbsp; e.printStackTrace();<br>
            &nbsp; &nbsp; }<br>
            <br>
            &nbsp; }<br>
            <br>
            &nbsp; @SuppressWarnings("restriction")<br>
            &nbsp; private static KnowledgeBase readKnowledgeBase() throws
            Exception {<br>
            &nbsp; &nbsp; KnowledgeBuilder kbuilder =<br>
            KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
            &nbsp; &nbsp;
            kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),<br>
            ResourceType.DRL);<br>
            &nbsp; &nbsp; KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
            &nbsp; &nbsp; if (errors.size() &gt; 0) {<br>
            &nbsp; &nbsp; &nbsp; for (KnowledgeBuilderError error: errors) {<br>
            &nbsp; &nbsp; &nbsp; &nbsp; System.err.println(error);<br>
            &nbsp; &nbsp; &nbsp; }<br>
            &nbsp; &nbsp; &nbsp; throw new IllegalArgumentException("Could not parse
            knowledge.");<br>
            &nbsp; &nbsp; }<br>
            <br>
            &nbsp; &nbsp; KnowledgeBaseConfiguration kbConfig =<br>
            KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
            &nbsp; &nbsp; kbConfig.setOption( EventProcessingOption.STREAM );<br>
            &nbsp; &nbsp; KnowledgeBase kbase =
            KnowledgeBaseFactory.newKnowledgeBase(kbConfig);<br>
            &nbsp; &nbsp;
            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
            <br>
            <br>
            &nbsp; &nbsp; return kbase;<br>
            &nbsp; }<br>
            <br>
            <br>
            }<br>
            <br>
            <br>
            *********Sample.drl*************************<br>
            <br>
            package com.sample<br>
            <br>
            <br>
            import java.util.Date;<br>
            <br>
            declare DataReading<br>
            &nbsp; &nbsp; @role( event )<br>
            end<br>
            <br>
            <br>
            declare ReconfigEvent<br>
            &nbsp; &nbsp; @role( event )<br>
            &nbsp; &nbsp; @expires ( 5s )<br>
            end<br>
            <br>
            <br>
            <br>
            rule "Wait for follup reading or no config"<br>
            //lock-on-active<br>
            when<br>
            <br>
            &nbsp; &nbsp; $dr: DataReading(reading &gt; 10.0) from entry-point "My
            Stream"<br>
            &nbsp; &nbsp; not(DataReading(reading &lt; 10.0, this after[0s,3s]
            $dr) from<br>
            entry-point "My Stream")<br>
            &nbsp; &nbsp; not(ReconfigEvent() from entry-point "My Stream")<br>
            <br>
            then<br>
            &nbsp; &nbsp; System.err.println("Action: " + new
            Date(System.currentTimeMillis()));<br>
            &nbsp; &nbsp; System.err.println("Data reading " + $dr.getName() + "
            &gt; 10");<br>
            &nbsp; &nbsp; ReconfigEvent rce = new ReconfigEvent();<br>
            &nbsp; &nbsp; entryPoints["My Stream"].insert( rce );<br>
            <br>
            end<br>
            <br>
            <br>
            <br>
            <br>
            <br>
            <br>
            _______________________________________________<br>
            rules-users mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
            <a moz-do-not-send="true"
              href="https://lists.jboss.org/mailman/listinfo/rules-users"
              target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <br>
        -- <br>
        &nbsp; Edson Tirelli<br>
        &nbsp; JBoss Drools Core Development<br>
        &nbsp; JBoss by Red Hat @ <a moz-do-not-send="true"
          href="http://www.jboss.com">www.jboss.com</a><br>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>