0

I am new in Drools-fusion. I want to write rules with following condition.

  1. Event data comes regularly to drools engine with two attribute named "eventId" and "state". Ex:- "data":{"eventId":"evet123","state":1}
  2. When first time event come it stores in working memory.
  3. After first event whatever event come that event's state check with previous event and if previous event's state is 1 and current event state is 2. so in that condition execute some function. and current event replace by previous event in working memory.

Ex:- if(Previous event state is 1 ---> Current event state is 2) then call function

Note:- eventId is not unique. Its may be same as previous event or different.

(May be length based sliding window use in this scenerio but i did not kknow how to convert this req. in rules.)

Please any drools expert guide me in this problem.

Raj
  • 252
  • 1
  • 5
  • 20
  • And the data with state==2 remains in working memory, infinitely? Do you want this to happen for every pair state==1/2, no matter what the eventId? - Do you have any rule code yet - what have you tried so far? – laune Feb 26 '14 at 09:57
  • Ah, yes, and you can't replace one fact with another one, but you can retract a fact. – laune Feb 26 '14 at 09:58
  • 1. Suppose first event has state 1 and second event has state 2 then rule condition satisfied. This rule is applicable only for same eventID. when this rules satisfied first event discarded and second event becomes first now so now new event with same id will compare to this new first eventId. – Raj Feb 26 '14 at 11:01

1 Answers1

0

Whatever you say, but what you describe is a strange sequence of events: The first event has state 1, and all following events have state 2.

rule match12
when
  $e1: Event( $id: id, state == 1 )
  $e2: Event( id == $id, state == 2 )
then
  retract( $e1 );
  modify( $e2 ){ setState( 1 ) }
end
laune
  • 31,114
  • 3
  • 29
  • 42
  • Thanks @laune. This is help to me. I have other one difficulty also just look on that one. http://stackoverflow.com/questions/22063409/how-to-access-drools-window-value – Raj Feb 27 '14 at 08:56