Search code examples
javarulesrule-enginecomplex-event-processingesper

Esper rule language: return datafield of class from pattern


I have the following rule that fires when the heart rate remains above 160 for 5 minutes.

EPStatement cepStatementRule3 = cepRule.createEPL("context PartitionByMacHeartRate "
                + "select * from pattern[every(HeartRate(heartrate > 160) "
                + "-> (timer:interval(5 min) "
                + "and not HeartRate(heartrate<=160)))]");
        cepStatementRule3.addListener(new rule3Listener());

My HeartRate class has the following fields:

int heartrate;
String heartratesTimestamp;
String macAddress;

What I want is to be able to get the macAddress in my ruleListener. This however returns an empty hashmap. So my question is how can I return the macAddress of the HeartRate?


Solution

  • Patterns retain and return the tagged events, i.e. this would do:

    // we assign the 'h' tag to the first event and the engine now retains that
    // the select clause could use "h.macAddress as macAddress", for example
    ...every(h=HeartRate(...