be
related to this?
I am inserting a single object via JSON and it fires twice.
Regards,
Prem
On Wed, Jul 1, 2009 at 9:54 AM, Jaroslaw Kijanowski <kijanowski(a)gmail.com>wrote:
https://jira.jboss.org/jira/browse/JBRULES-2154
Thanks.
Edson Tirelli wrote:
>
> Jarowslaw,
>
> Could you please open a JIRA for this. I need to investigate.
> Thanks,
>
> Edson
>
> 2009/7/1 Jaroslaw Kijanowski <kijanowski(a)gmail.com <mailto:
> kijanowski(a)gmail.com>>
>
>
> Hi,
> I've configured my knowledge base to use the EQUALITY assertion
> behaviour.
> When I insert two equal facts into the session, only one gets
> processed (objects and their fact handles are equal).
> However when I insert two equal facts via streams, my rule fires
> twice (objects are equal, but their fact handles are not). Isn't
> equality assertion behaviour supported when using streams?
>
> Here's my rule and test class:
>
> package com.sample
> import com.sample.Message;
> declare Message
> @role( event )
> @timestamp( time )
> end
>
> rule "r"
> when
> Message( $i:i) //from entry-point "myStream"
> then
> System.out.println( $i );
> end
>
> +++++++++++++++++++++++++++++++++++++++++
>
> public class Message {
>
> private int i;
> private Date time;
> //getters, setters, hashcode, equals, constructor
> }
>
> +++++++++++++++++++++++++++++++++++++++++
>
> public class DroolsTest {
> public static final void main(String[] args) {
> try {
> KnowledgeBase kbase = readKnowledgeBase();
> StatefulKnowledgeSession ksession =
> kbase.newStatefulKnowledgeSession();
>
> //WorkingMemoryEntryPoint stream =
> ksession.getWorkingMemoryEntryPoint("myStream");
>
> Date d = new Date();
> Message message1 = new Message(1,d);
> FactHandle fh1 = ksession.insert(message1);
> //FactHandle fh1 = stream.insert(message1);
> Message message2 = new Message(1,d);
> FactHandle fh2 = ksession.insert(message2);
> //FactHandle fh2 = stream.insert(message2);
>
> if (message1.equals(message2) && fh1.equals(fh2)){
> System.out.println("equal");
> }
> ksession.fireAllRules();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
>
> private static KnowledgeBase readKnowledgeBase() throws Exception {
> KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
> kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
> ResourceType.DRL);
> if (kbuilder.getErrors().size() > 0) {
> throw new IllegalArgumentException("Could not parse knowledge.");
> }
> KnowledgeBaseConfiguration kbaseConfig =
> KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
> kbaseConfig.setOption(AssertBehaviorOption.EQUALITY);
> kbaseConfig.setOption(EventProcessingOption.STREAM);
> kbaseConfig.setOption(RemoveIdentitiesOption.YES);
>
> KnowledgeBase kbase =
> KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
> kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
> return kbase;
> }
> }
>
> +++++++++++++++++++++++++++++++++++++++++
>
> Thanks,
> Jarek
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org <mailto:rules-users@lists.jboss.org>
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
> Edson Tirelli
> JBoss Drools Core Development
> JBoss by Red Hat @
www.jboss.com <
http://www.jboss.com>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users