Re: [rules-users] About fusion and collections
Kewl !.. sounds good. Thanks for your help folks. I will try the options out. 2010/3/15 Edson Tirelli > >Amit, > >Check fireUntilHalt() docs in order to set the engine to reactive > mode... although, for most cases I've seen, you still have more control by > defining the fireAllRules() cycle explicitly. > >Regarding your rule, the problem is that the first type is matched for > multiple events. The simplest way to fix that is by pre-populating the > working memory with all possible event types. In this case you would use a > rule like: > > when > EventType( $type : type ) > > $events: ArrayList (size > 10) > from collect (Event(eventType == $type)) > then > // do something > end > >You can also find the distinct event types using accumulate, but that is > heavier and more complex than the previous example. Lets say event type is a > String: > > when > $types : Set() > from accumulate( Event($type : eventType), >collectSet( $type ) ) > $type : String() from $types > > $events: ArrayList (size > 10) > from collect (Event(eventType == $type)) > then > // do something > end > >I don't really recommend the second approach though. An intermediate > approach is to have a separate rule logically insert all event types, and > then use the same approach of the first example above: > > declare EventType > type : String @key > end > > when > Event( $type : eventType ) > then > EventType et = new EventType(); > et.setType( $type ); > logicalInsert( et ); > end > >[]s >Edson > > > 2010/3/15 Amit Kumar > >> Hello All, >> >> >> Was doing some rule writing and am seeing some issues which I want to >> overcome. >> >> In Fusion when we send the facts into working memory.. there seems to be >> no way that rules are automatically getting triggered. >> We have to call fireAllRules after each fact insertion. Is this the way it >> was designed. Its like this in the stocktick example also >> >> This one should be simple for somebody with little more experience than me >> In the following rule >> >> rule "raise alarm" >> when >> Event($type : eventType) >> $events: ArrayList (size > 10) >> from collect (Event(eventType == $type)) >> then >> raise alarm >> >> In the above rule the raise alarm is getting called 10 times. .. How can I >> make it to be called only once. >> >> Thanks >> Amit >> >> ___ >> rules-users mailing list >> 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 > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] About fusion and collections
Amit, Check fireUntilHalt() docs in order to set the engine to reactive mode... although, for most cases I've seen, you still have more control by defining the fireAllRules() cycle explicitly. Regarding your rule, the problem is that the first type is matched for multiple events. The simplest way to fix that is by pre-populating the working memory with all possible event types. In this case you would use a rule like: when EventType( $type : type ) $events: ArrayList (size > 10) from collect (Event(eventType == $type)) then // do something end You can also find the distinct event types using accumulate, but that is heavier and more complex than the previous example. Lets say event type is a String: when $types : Set() from accumulate( Event($type : eventType), collectSet( $type ) ) $type : String() from $types $events: ArrayList (size > 10) from collect (Event(eventType == $type)) then // do something end I don't really recommend the second approach though. An intermediate approach is to have a separate rule logically insert all event types, and then use the same approach of the first example above: declare EventType type : String @key end when Event( $type : eventType ) then EventType et = new EventType(); et.setType( $type ); logicalInsert( et ); end []s Edson 2010/3/15 Amit Kumar > Hello All, > > Was doing some rule writing and am seeing some issues which I want to > overcome. > > In Fusion when we send the facts into working memory.. there seems to be no > way that rules are automatically getting triggered. > We have to call fireAllRules after each fact insertion. Is this the way it > was designed. Its like this in the stocktick example also > > This one should be simple for somebody with little more experience than me > In the following rule > > rule "raise alarm" > when > Event($type : eventType) > $events: ArrayList (size > 10) > from collect (Event(eventType == $type)) > then > raise alarm > > In the above rule the raise alarm is getting called 10 times. .. How can I > make it to be called only once. > > Thanks > Amit > > ___ > rules-users mailing list > 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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] About fusion and collections
I think something like this should work: rule "raise alarm" when Event($type : eventType) exists (ArrayList (size > 10) from collect (Event(eventType == $type))) then raise alarm Of course that you can't use the $events anymore. You can use a flag too: rule "raise alarm" when not TheAlarmWasAlreadyTriggered() Event($type : eventType) $events: ArrayList (size > 10) from collect (Event(eventType == $type)) then raise alarm insert(new TheAlarmWasAlreadyTriggered()); best, 2010/3/15 Amit Kumar > Hello All, > > Was doing some rule writing and am seeing some issues which I want to > overcome. > > In Fusion when we send the facts into working memory.. there seems to be no > way that rules are automatically getting triggered. > We have to call fireAllRules after each fact insertion. Is this the way it > was designed. Its like this in the stocktick example also > > This one should be simple for somebody with little more experience than me > In the following rule > > rule "raise alarm" > when > Event($type : eventType) > $events: ArrayList (size > 10) > from collect (Event(eventType == $type)) > then > raise alarm > > In the above rule the raise alarm is getting called 10 times. .. How can I > make it to be called only once. > > Thanks > Amit > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > > -- Esteban Aliverti ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] About fusion and collections
Hello All, Was doing some rule writing and am seeing some issues which I want to overcome. In Fusion when we send the facts into working memory.. there seems to be no way that rules are automatically getting triggered. We have to call fireAllRules after each fact insertion. Is this the way it was designed. Its like this in the stocktick example also This one should be simple for somebody with little more experience than me In the following rule rule "raise alarm" when Event($type : eventType) $events: ArrayList (size > 10) from collect (Event(eventType == $type)) then raise alarm In the above rule the raise alarm is getting called 10 times. .. How can I make it to be called only once. Thanks Amit ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users