Apama 10.3.1 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Defining Event Listeners | Defining event listeners with temporal constraints | Listening for event patterns within a set time
 
Listening for event patterns within a set time
Consider this earlier example:
event StockTick {
   string name;
   float price;
}
 
event NewsItem {
   string subject;
   string newsHeading;
}
 
monitor NewsSharePriceSequence_ACME {
   // Look for a NewsItem followed by a StockTick
   //
   action onload() {
     on NewsItem("ACME",*) -> StockTick("ACME",*)
       notifyUser();
   }
 
   // Print a message, event sequence detected
   //
   action notifyUser() {
     log "Event sequence detected.";
  }
}
This will look for the event pattern of a news item about a company followed by a stock price tick about that company. Once improved this could be used to detect the beginning of a rise (or fall) in the value of shares of a company following the release of a relevant news headline.
However, unless a temporal constraint is put in place, the monitor is not going to be that pertinent, as it might trigger on an event pattern where the price change occurs weeks after the news item. That would clearly not be so useful to a trader, as the two events were most likely unrelated and hence not indicative of a possible trend.
If the event listener above is rewritten as follows,
on NewsItem("ACME",*) -> StockTick("ACME",*) within(30.0)
   notifyUser();
the StockTick event would now need to occur within 30 seconds of NewsItem for the event listener to trigger.
The within(float) operator is a postfix unary operator that can be applied to an event template (the StockTick event template in the above example). Think of it like a stopwatch. The clock starts ticking as soon as the event listener starts looking for the event template that the within operator is attached to. If the stopwatch reaches the specified figure before the event template evaluates to true, then the event template becomes permanently false.
In the above code, the timer is only activated once a suitable NewsItem is encountered. Unless an adequate StockTick then occurs within 30 seconds and makes the expression evaluate to true, the timer will fire and fail the whole event listener.
You can apply the within operator to any event template. For example:
on A() within(10.0) listenerAction();
After the correlator sets up this event listener, the event listener must detect an A event within 10 seconds. If no A event is detected within 10 seconds, the event expression becomes permanently false and the correlator subsequently terminates the event listener.

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.