It works now (I get a StatefulKnowledgeSessionImpl back which is fine). Thanks for fixing this.<br><br><div class="gmail_quote">On Sun, Mar 8, 2009 at 4:43 AM, Mark Proctor <span dir="ltr">&lt;<a href="mailto:mproctor@codehaus.org" target="_blank">mproctor@codehaus.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">



  

<div bgcolor="#ffffff" text="#000000"><div>
Mark Proctor wrote:
<blockquote type="cite">
  
Michal Bali wrote:
  <blockquote type="cite">Hi,<br>
    <br>
I guess the issue is that StatelessKnowledgeSession doesn&#39;t extend the
WorkingMemory interface as David pointed out. So if you call
event.getKnowledgeRuntime() you&#39;ll get <b>null</b> back.<br>
  </blockquote>
when in an event or in a consequence, whether using a stateless or
stateful session it should return a knowledgeruntime instance - if it&#39;s
not, it&#39;s a bug. I&#39;ll look into it.<br>
</blockquote></div>
I&#39;ve looked into this and fixed the bug, you should now be able to
access the knowledgeruntime from the consequence and the event. Please
do retest all of this from trunk<div><div></div><div><br>
<a href="https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/" target="_blank">https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/</a><br>
</div></div><blockquote type="cite"><div><div></div><div>
  <blockquote type="cite"><br>
Similar issue happens when you call drools.getKnowledgeRuntime() from
within rule&#39;s consequence. However in this case it throws the following
exception (running with snapshot from 07.
03. 2009):<br>
    <br>
org.drools.runtime.rule.ConsequenceException:
java.lang.ClassCastException: <b>org.drools.reteoo.</b><b>ReteooWorkingMemory
cannot be cast to org.drools.reteoo.</b><b>ReteooStatefulSession</b><br>
    at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)<br>
    at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)<br>
    at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)<br>
    at
org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1082)<br>
    at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:682)<br>
    at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:659)<br>
    at
org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:213)<br>
    at com.sample.DroolsTest.main(DroolsTest.java:45)<br>
Caused by: java.lang.ClassCastException:
org.drools.reteoo.ReteooWorkingMemory cannot be cast to
org.drools.reteoo.ReteooStatefulSession<br>
    at
org.drools.base.DefaultKnowledgeHelper.getKnowledgeRuntime(DefaultKnowledgeHelper.java:222)<br>
    at
com.sample.Rule_Hello_World_0.consequence(Rule_Hello_World_0.java:7)<br>
    at
com.sample.Rule_Hello_World_0ConsequenceInvoker.evaluate(Rule_Hello_World_0ConsequenceInvoker.java:26)<br>
    at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)<br>
    ... 6 more<br>
    <br>
for this rule:<br>
rule &quot;Hello World&quot;<br>
    when<br>
        Message( )<br>
    then<br>
        System.out.println( drools.getKnowledgeRuntime() );<br>
end<br>
    <br>
Best Regards,<br>
Michal<br>
    <br>
    <br>
    <div class="gmail_quote">On Fri, Mar 6, 2009 at 6:45 AM, Mark
Proctor <span dir="ltr">&lt;<a href="mailto:mproctor@codehaus.org" target="_blank">mproctor@codehaus.org</a>&gt;</span>
wrote:<br>
    <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
      <div bgcolor="#ffffff" text="#000000">
      <div>David Boaz wrote:
      <blockquote type="cite">
        <pre>Your answer refered to Statefull session. My question was regarding a
stateless session, that do not extend WorkingMemory.
  </pre>
      </blockquote>
      </div>
you are using an event, that event exposes the knowledgeruntime in the
event listener - stateless and stateful use the same event model and
both expose the knowledgeruntime as a parameter. All events should
extend KnowledgeRuntimeEvent which provides the method
getKnowledgeRuntime.<br>
      <font color="#888888"><br>
Mark</font>
      <div>
      <div><br>
      <blockquote type="cite">
        <pre>Currently, I did an ugly work-around. The Activation returns a
Collection&lt;FactHandle&gt;, and I noticed that in runtime, the FactHandle is
instanceof InternalFactHandle, that do have a getObject(). So, My code looks
like:
for(FactHandle handle:activation.getFactHandles()){
  assert(handle instanceof InternalFactHandle);
  Object o=((InternalFactHandle)handle).getObject();
  ...
}
Im looking for the correct way to implement this functionality. 
Thanks, David


Mark Proctor wrote:
  </pre>
        <blockquote type="cite">
          <pre>David Boaz wrote:
    </pre>
          <blockquote type="cite">
            <pre>Thanks Mark,

The post bellow doesn&#39;t deal with the event listener registration.
Assuming
the registration was solved, now I have another issue. How to retrieve
the
Facts given Fact-handles? In a stateless session, I have no access to the
working memory.
  
      </pre>
          </blockquote>
          <pre>If you are using StatefulKnowledgeSession. Then the Activation has
    Collection&lt; ? extends FactHandle&gt; getFactHandles();

And the KnowledgeRuntime is always available, which extends the 
WorkingMemory.

Mkar
    </pre>
          <blockquote type="cite">
            <pre>David


Mark Proctor wrote:
  
      </pre>
            <blockquote type="cite">
              <pre>David Boaz wrote:
    
        </pre>
              <blockquote type="cite">
                <pre>Hi all,

Im trying to listen to the events fired during the evaluation of a
stateless
session. I implemented org.drools.event.rule.AgendaEventListener. The
events
fire as expected. From the event I can extract the Activation, the Rule
and
the list of FactHandles. Now, from each FactHandle I want to retrieve
the
associated fact (Object). For that, I need a WorkingMemory. But the WM
doesn&#39;t participate in the event signature. In addition, since Im using
a
stateless session, the working memory does not exist until I execute()
method.

Can you please help?
  
      
          </pre>
              </blockquote>
              <pre>The event listeners don&#39;t work in the last release, this is fixed in 
trunk, please give it a try in a snapshot:
<a href="https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/" target="_blank">https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/</a>
    
        </pre>
              <blockquote type="cite">
                <pre>Thanks, David
  
      
          </pre>
              </blockquote>
              <pre>_______________________________________________
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>
            <pre>  
      </pre>
          </blockquote>
          <pre>_______________________________________________
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>
        <pre>  </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>
    <pre><hr size="4" width="90%">
_______________________________________________
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><pre><hr size="4" width="90%"><div>
_______________________________________________
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>
  </div></pre>
</blockquote>
<br>
</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>