Developing Apama Applications > Developing Apama Applications in EPL > Defining Event Listeners > Specifying and/or/not logic in event listeners > Specifying and not logic to terminate event listeners
Specifying and not logic to terminate event listeners
A typical situation is that you want to listen for a pattern only until a particular condition occurs. When the condition occurs you want to terminate the event listener. In pseudocode, you want to specify something like this:
on all event_expression until stop_condition
To define an event listener that behaves this way, you specify and not:
on all event_expression and not stop_condition
The following example listens for a price increase for aparticular stock while the market is open.
event Price {
   string stock;
   float price;
}
Price p;
on all Price("IBM",>targetPrice):p and not MarketClosed() {
...do something}
When you inject a monitor that contains this code, the correlator sets up an event template to listen for Price events and another event template to listen for MarketClosed events. As long as the correlator does not receive a MarketClosed event, not MarketClosed() evaluates to true. While not MarketClosed() evaluates to true, each time the correlator receives a Price event for IBM stock at a price that is greater than targetPrice, this event expression evaluates to true and triggers its listener action. When the correlator receives a MarketClosed event, MarketClosed() evaluates to true and so not MarketClosed() evaluates to false. At that point, the event expression can no longer evaluate to true. When the correlator recognizes an event listener that can never trigger, it terminates it. In other words, after the market is closed the event listener terminates.
Typically, the stop condition is a condition that applies to multiple entities. In the previous example, the condition applies to only IBM stock, but it could easily be rewritten to apply to all stocks.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.