Apama 10.3.1 | Apama Documentation | 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 | Choosing which action to execute
 
Choosing which action to execute
Another situation in which and not logic can help terminate event listeners is when you want to specify a choice of one or more actions and terminate the event listeners after one is chosen. An example of this appears below. This is the CEP equivalent of a case statement.
on Pattern_1() and not PatternMatched() processCase1();
on Pattern_2() and not PatternMatched() processCase2();
on Pattern_3() and not PatternMatched() processCase3();
on Pattern_1() or Pattern_2() or Pattern_3()
{   
route PatternMatched();
}
When you inject a monitor that contains this type of code the correlator immediately sets up multiple event listeners. For the example in Pausing event listeners, the event listeners would be watching for these events:
*Pattern_1
*PatternMatched
*Pattern_2
*Pattern_3
Initially, all and not event templates evaluate to true. Suppose Pattern_2 arrives. This causes these two event listeners to trigger:
on Pattern_2() and not PatternMatched() processCase2();
on Pattern_1() or Pattern_2() or Pattern_3()
It is unknown which event listener action the correlator executes first, but the order does not matter. The correlator does all of the following:
*The correlator executes the processCase2() action.
*The correlator terminates the event listener that specifies processCase2() because it has found its match and it does not specify all.
*The correlator routes a PatternMatched event to the front of the context's input queue.
When the correlator processes the PatternMatched() event, the two event templates that are still watching for and not PatternMatched become false. Consequently, those event listeners will never trigger and the correlator terminates them.
Following is another example of specifying and not to make a choice:
on Ack() and not Nack()
{
   processAck();
}
on Nack() and not Ack()
{
   processNack();
}

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.