Raj
Raj

Reputation: 262

How to write drools rules in sliding window for following condition?

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.

Upvotes: 0

Views: 490

Answers (1)

laune
laune

Reputation: 31300

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

Upvotes: 0

Related Questions