<div><br></div>   Hi Chris,<div><br></div><div>   Best way is to explicitly define the relationship with a temporal constraint (although there are other ways). E.g.:</div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "><br>
</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); ">when</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "></span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); ">    $dr: DataReading(reading &gt; 10.0) from entry-point &quot;My Stream&quot;</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "></span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); ">    not(DataReading(reading &lt; 10.0, this after[0s,3s] $dr) from </span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); ">entry-point &quot;My Stream&quot;)</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "></span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); ">    not(ReconfigEvent( this before[0,5s] $dr ) from entry-point &quot;My Stream&quot;)</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); ">then</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "></span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "> </span></div>
<div><div>   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.</div>
<div><br></div><div>   Edson</div><div><br></div><br><div class="gmail_quote">2011/7/26 Chris Richmond <span dir="ltr">&lt;<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<u></u>

  
    
    
  
  <div bgcolor="#ffffff" text="#000000">
    Ok, well how to make them marry only those alive(&lt;100 years old)
    and ensure all those over 100 years old go out of memory?<br><font color="#888888">
    <br>
    Chris</font><div><div></div><div class="h5"><br>
    <br>
    On 7/25/2011 2:32 PM, Edson Tirelli wrote:
    <blockquote type="cite">
      <div><br>
      </div>
         Chris
      <div><br>
      </div>
      <div>   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 &quot;periods where there is no ReconfigEvent&quot;, as the
        lifetime of DataReading is infinity.</div>
      <div><br>
      </div>
      <div>   Maybe a simpler way of understanding it (without using the
        &quot;not&quot; for simplification) is think about this:</div>
      <div><br>
      </div>
      <div>declare Man</div>
      <div>   @livesUpTo( 100 years )</div>
      <div>
        end</div>
      <div><br>
      </div>
      <div>rule &quot;marriage&quot;</div>
      <div>when</div>
      <div>   $w : Woman( age &gt; 18 ) </div>
      <div>   $m : Man( )</div>
      <div>then</div>
      <div>   // marry woman and man</div>
      <div>end</div>
      <div><br>
      </div>
      <div>
            The rule above defines that each woman will merry every
        existing man, even if each of them only lives for 100 years.</div>
      <div><br>
      </div>
      <div>    Edson<br>
        <br>
        <div class="gmail_quote">2011/7/26 Chris Richmond <span dir="ltr">&lt;<a href="mailto:crichmond@referentia.com" target="_blank">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">
            <div bgcolor="#ffffff" text="#000000"> Edson,<br>
              <br>
              I was under the impression that this:
              <div><br>
                <br>
                declare ReconfigEvent<br>
                    @role( event )<br>
                    @expires ( 5s )<br>
                end<br>
                <br>
              </div>
              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>
              <font color="#888888"> Chris</font>
              <div>
                <div><br>
                  <br>
                  On 7/25/2011 12:17 PM, Edson Tirelli wrote:
                  <blockquote type="cite">
                    <div><br>
                    </div>
                       Chris,
                    <div><br>
                    </div>
                    <div>   I haven&#39;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. </div>
                    <div><br>
                    </div>
                    <div>   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>   Edson<br>
                      <br>
                      <div class="gmail_quote">2011/7/26 Chris Richmond
                        <span dir="ltr">&lt;<a href="mailto:crichmond@referentia.com" target="_blank">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>
                                for (int x = 0; x &lt; 100000; x++){<br>
                                  DataReading dr = new
                          DataReading(&quot;Reading &quot; + x, 12.0f);<br>
                                  myStream.insert(dr);<br>
                                  ksession.fireAllRules();<br>
                                  Thread.sleep(1);<br>
                          <br>
                                }<br>
                          <br>
                          <br>
                          The rule that evaluates this is simple.  It
                          basically delays &quot;then&quot; 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.  This<br>
                          all works just fine as expected.<br>
                          <br>
                          My question is, how come I don&#39;t get memory
                          back when all 100,000 of my<br>
                          events have been inserted.  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.   I should
                          not have to explicitly<br>
                          remove/retract events should I? Shouldn&#39;t they
                          be removed from working<br>
                          memory as soon as they are no longer viable?
                           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>
                            @SuppressWarnings(&quot;restriction&quot;)<br>
                            public static void main(String[] args) {<br>
                          <br>
                          <br>
                              try {<br>
                          <br>
                                KnowledgeSessionConfiguration config =<br>
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
                                config.setOption(
                          ClockTypeOption.get(&quot;realtime&quot;) );<br>
                          <br>
                          <br>
                                KnowledgeBase kbase;<br>
                                kbase = readKnowledgeBase();<br>
                                StatefulKnowledgeSession ksession =<br>
                          kbase.newStatefulKnowledgeSession();<br>
                          <br>
                                WorkingMemoryEntryPoint myStream =<br>
                          ksession.getWorkingMemoryEntryPoint(&quot;My
                          Stream&quot;);<br>
                          <br>
                                for (int x = 0; x &lt; 100000; x++){<br>
                                  DataReading dr = new
                          DataReading(&quot;Reading &quot; + x, 12.0f);<br>
                                  myStream.insert(dr);<br>
                                  ksession.fireAllRules();<br>
                                  Thread.sleep(1);<br>
                          <br>
                                }<br>
                          <br>
                              } catch (Exception e) {<br>
                                // TODO Auto-generated catch block<br>
                                e.printStackTrace();<br>
                              }<br>
                          <br>
                            }<br>
                          <br>
                            @SuppressWarnings(&quot;restriction&quot;)<br>
                            private static KnowledgeBase
                          readKnowledgeBase() throws Exception {<br>
                              KnowledgeBuilder kbuilder =<br>
                          KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
                             
                          kbuilder.add(ResourceFactory.newClassPathResource(&quot;Sample.drl&quot;),<br>
                          ResourceType.DRL);<br>
                              KnowledgeBuilderErrors errors =
                          kbuilder.getErrors();<br>
                              if (errors.size() &gt; 0) {<br>
                                for (KnowledgeBuilderError error:
                          errors) {<br>
                                  System.err.println(error);<br>
                                }<br>
                                throw new
                          IllegalArgumentException(&quot;Could not parse
                          knowledge.&quot;);<br>
                              }<br>
                          <br>
                              KnowledgeBaseConfiguration kbConfig =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
                              kbConfig.setOption(
                          EventProcessingOption.STREAM );<br>
                              KnowledgeBase kbase =
                          KnowledgeBaseFactory.newKnowledgeBase(kbConfig);<br>
                             
                          kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
                          <br>
                          <br>
                              return kbase;<br>
                            }<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>
                              @role( event )<br>
                          end<br>
                          <br>
                          <br>
                          declare ReconfigEvent<br>
                              @role( event )<br>
                              @expires ( 5s )<br>
                          end<br>
                          <br>
                          <br>
                          <br>
                          rule &quot;Wait for follup reading or no config&quot;<br>
                          //lock-on-active<br>
                          when<br>
                          <br>
                              $dr: DataReading(reading &gt; 10.0) from
                          entry-point &quot;My Stream&quot;<br>
                              not(DataReading(reading &lt; 10.0, this
                          after[0s,3s] $dr) from<br>
                          entry-point &quot;My Stream&quot;)<br>
                              not(ReconfigEvent() from entry-point &quot;My
                          Stream&quot;)<br>
                          <br>
                          then<br>
                              System.err.println(&quot;Action: &quot; + new
                          Date(System.currentTimeMillis()));<br>
                              System.err.println(&quot;Data reading &quot; +
                          $dr.getName() + &quot; &gt; 10&quot;);<br>
                              ReconfigEvent rce = new ReconfigEvent();<br>
                              entryPoints[&quot;My Stream&quot;].insert( rce );<br>
                          <br>
                          end<br>
                          <br>
                          <br>
                          <br>
                          <br>
                          <br>
                          <br>
_______________________________________________<br>
                          rules-users mailing list<br>
                          <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
                          <a 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>
                        Edson Tirelli<br>
                        JBoss Drools Core Development<br>
                        JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
                    </div>
                    <pre><fieldset></fieldset>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            rules-users mailing list<br>
            <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
            <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
            <br>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <br>
        -- <br>
          Edson Tirelli<br>
          JBoss Drools Core Development<br>
          JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
      </div>
      <pre><fieldset></fieldset>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </blockquote>
    <br>
  </div></div></div>

<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>