<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Well..I insert some objects, fire the rules and this rule will
trigger the first time (when it finds no object with those
characterstis) but every time after than when I insert more objects
and fire the rules, the rule never fires again. I have no idea why.
Here is my simple test case. <br>
<br>
Two clasess: TestMain and TestObject and rule file Test.drl I have
included below.<br>
<br>
It insterts a group of facts at one time, fires the rules, and
retracts all those facts from the stream. I have an event listener
on the session, as you see to verify injections and retractions are
occuring. <br>
So the rule fires on the first batch, but on no other batches after
that???? What gives???? <br>
<br>
Among the Inserttion and retraction events I only see:<br>
<br>
A proper object does not exist<br>
<br>
One time, during firing rules on the first batch. Why does this
rule never fire again, even though every single batch of objects I
insert/retract does not contain the proper rule values, and so
should fire the rule.<br>
<br>
What is going on???<br>
<br>
<br>
<br>
<br>
<br>
TestMain.java *************************************<br>
<br>
package com.sample;<br>
<br>
import java.util.ArrayList;<br>
import java.util.List;<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.event.rule.ObjectInsertedEvent;<br>
import org.drools.event.rule.ObjectRetractedEvent;<br>
import org.drools.event.rule.ObjectUpdatedEvent;<br>
import org.drools.event.rule.WorkingMemoryEventListener;<br>
import org.drools.io.ResourceFactory;<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.FactHandle;<br>
import org.drools.runtime.rule.WorkingMemoryEntryPoint;<br>
<br>
public class TestMain {<br>
<br>
@SuppressWarnings("restriction")<br>
public static void main(String[] args) {<br>
<br>
<br>
try {<br>
<br>
KnowledgeSessionConfiguration config =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
config.setOption( ClockTypeOption.get("realtime") );<br>
<br>
<br>
KnowledgeBase kbase;<br>
kbase = readKnowledgeBase();<br>
final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();<br>
<br>
WorkingMemoryEntryPoint myStream =
ksession.getWorkingMemoryEntryPoint("My Stream");<br>
<br>
ksession.addEventListener(new WorkingMemoryEventListener(){<br>
<br>
@Override<br>
public void objectInserted(ObjectInsertedEvent oie) {<br>
System.err.println("Inserted: " + oie.toString());<br>
<br>
}<br>
<br>
@Override<br>
public void objectRetracted(ObjectRetractedEvent arg0) {<br>
System.err.println("Retracted: " + arg0.toString());<br>
<br>
}<br>
<br>
@Override<br>
public void objectUpdated(ObjectUpdatedEvent arg0) {<br>
// TODO Auto-generated method stub<br>
<br>
}<br>
<br>
});<br>
<br>
<br>
for (int a = 0; a < 1000; a++){<br>
List<FactHandle> factHandles = new
ArrayList<FactHandle>();<br>
for (int x = 0; x < 6; x++){<br>
<br>
double reading = 11.3;<br>
float f = (float)reading;<br>
TestObject dr = new TestObject("Reading " + x, f);<br>
FactHandle fh = myStream.insert(dr);<br>
factHandles.add(fh);<br>
<br>
<br>
<br>
}<br>
ksession.fireAllRules();<br>
for(FactHandle fh : factHandles){<br>
myStream.retract(fh);<br>
}<br>
Thread.sleep(4000);<br>
}<br>
<br>
} catch (Exception e) {<br>
// TODO Auto-generated catch block<br>
e.printStackTrace();<br>
}<br>
<br>
}<br>
<br>
@SuppressWarnings("restriction")<br>
private static KnowledgeBase readKnowledgeBase() throws Exception
{<br>
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
kbuilder.add(ResourceFactory.newClassPathResource("Test.drl"),
ResourceType.DRL);<br>
KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
if (errors.size() > 0) {<br>
for (KnowledgeBuilderError error: errors) {<br>
System.err.println(error);<br>
}<br>
throw new IllegalArgumentException("Could not parse
knowledge.");<br>
}<br>
<br>
KnowledgeBaseConfiguration kbConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
kbConfig.setOption( EventProcessingOption.STREAM );<br>
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(kbConfig);<br>
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
<br>
<br>
<br>
<br>
return kbase;<br>
}<br>
<br>
<br>
<br>
<br>
}<br>
<br>
TestObject.java *************************************<br>
package com.sample;<br>
<br>
public class TestObject {<br>
<br>
<br>
<br>
private String name;<br>
private float reading;<br>
<br>
<br>
public TestObject(String name, float reading){<br>
this.name = name;<br>
this.reading = reading;<br>
}<br>
<br>
<br>
public String getName() {<br>
return name;<br>
}<br>
<br>
<br>
public void setName(String name) {<br>
this.name = name;<br>
}<br>
<br>
<br>
public float getReading() {<br>
return reading;<br>
}<br>
<br>
<br>
public void setReading(float reading) {<br>
this.reading = reading;<br>
}<br>
}<br>
<br>
<br>
Test.drl*************************************************<br>
#created on: Aug 19, 2011<br>
package com.sample<br>
<br>
<br>
<br>
rule "Test For Lack of Objects with criteria"<br>
<br>
when<br>
not(TestObject(name=="blah") from entry-point "My Stream")<br>
then<br>
System.err.println("A proper object does not exist");<br>
end<br>
<br>
<br>
<br>
<br>
On 8/18/2011 8:46 PM, Wolfgang Laun wrote:
<blockquote
cite="mid:CANaj1LfSg77owDTipmep1zXjQsq-K+K2xiYZSWPqE4R1u7__6g@mail.gmail.com"
type="cite">On 19 August 2011 15:17, Chris Richmond <span
dir="ltr"><<a moz-do-not-send="true"
href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>></span>
wrote:<br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="border-left: 1px solid
rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;">
How do I fire a rule if an object with certain characterstics
does not<br>
exists.<br>
<br>
For example my class Foo, if I have a rule:<br>
<br>
rule "Identify Foos with values"<br>
<br>
when<br>
Foo(stringProp=="blah", intProp==5)<br>
then<br>
System.err.println("A Foo was found!");<br>
end<br>
<br>
<br>
So how do I check for lack of existence of an object with
certain<br>
characteristics<br>
<br>
I tried:<br>
rule "Flag missing Foos with values"<br>
<br>
when<br>
not(Foo(stringProp=="blah", intProp==5))<br>
then<br>
System.err.println("A proper foo does not exist");<br>
end<br>
</blockquote>
<div><br>
That's the way to do it.<br>
</div>
<blockquote class="gmail_quote" style="border-left: 1px solid
rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;">
<br>
I also tried:<br>
rule "Flag missing Foos with values"<br>
<br>
when<br>
not(exists(Foo(stringProp=="blah", intProp==5)))<br>
then<br>
System.err.println("A proper foo does not exist");<br>
end<br>
</blockquote>
<div><br>
Since not( Foo(...)) means "if no Foo(...) exists", the
addition of "exists" is superfluous and generally considered
bad style (even though some systems accept it to mean just
"not".<br>
<br>
-W<br>
</div>
<blockquote class="gmail_quote" style="border-left: 1px solid
rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;">
_______________________________________________<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>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
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>