Jaffarz
Jaffarz

Reputation: 21

Drools for ECA/Reaction Rules having AND, SEQ, OR in Condition

It seems, Drools is quite prominent around here, so I thought I'd ask:

Can Drools rules be used for event pattern detection?
Patterns are of the from: "Event_x" SEQ/AND/OR "Event_z". The example below indicates the desired usage. The Events are identified using a previously known ID.

rule "Rule x"
when 
      Event1 SEQ/AND/OR Event2
then
    System.out.println("Event1 SEQ/AND/OR Event2");

Upvotes: 1

Views: 1309

Answers (1)

Edson Tirelli
Edson Tirelli

Reputation: 3901

Yes. "and" and "or" are used directly as conditional elements:

rule X when
    Event1() and Event2()
...

rule Y when
    Event3() or Event4()

They can obviously be combined, nested, etc... check Drools documentation for details.

Up to Drools 5.4, sequencies are defined using temporal operators like "before","after", etc. For instance:

rule Z when
    $e1 : Event1() and $e2 : Event2( this after $e1 )
...

For Drools 5.5, the several flavors of sequence conditional elements are planned:

rule W when
    Event1() -> Event2()
...

Where -> is the followed by operator, => is strictly followed by, etc.

Details:

https://community.jboss.org/wiki/EventSequencing#4_Definition_Sequence_Conditional_Elements

Upvotes: 1

Related Questions