Search code examples
espercumulocity

How to manage statement execution order in esper


There is an issue with following code. before A gets incremented or decremented....finalstatement gets executed. Why does this happen.. how can we manage the execution order of statements.

create variable Integer A=0;



on pattern[every a=EventCreated(a.type ='C')]
  set A=  A+1;


on pattern[every a=EventCreated(a.type ='EOD')]
  set A=  A-1;



select
  "R" as type,
  "R" as text,
  e.time as time,
  e.source as source
from EventCreated e where A=0 ;

Solution

  • Technically the input for the first statement also fits into the last statement that is why it can happen that esper is first triggering the last one.

    You can force esper to prioritise your first statement higher with an annotation @Priority

    @Priority(1)
    @Name("ReplaceCarCounterAdd")
    on pattern[every a=EventCreated(a.type ='Charging')]
      set ReplaceCar =  ReplaceCar+1;
    

    The highest priority is executed first and by default it is zero for all statements. With that change it should work because then when the last statement is triggered the variable is no longer 0.

    Documentation in esper: http://esper.espertech.com/release-7.1.0/esper-reference/html/epl_clauses.html#epl-syntax-annotation