Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining Event Listeners | Specifying and/or/xor/not logic in event listeners | Specifying the 'or' or 'xor' operator in event expressions
 
Specifying the 'or' or 'xor' operator in event expressions
The or and xor operators let you specify event expressions where a variety of event patterns could lead to a successful match. They effectively evaluate two event templates (or entire nested event expressions) simultaneously and return true when either of them becomes true (or) or when either of them becomes true and the other is false (xor).
Example for the or operator:
on A() or B() executeAction();
This means that either A or B need to be detected to match. That is, the occurrence of one of the operand expressions (an A or a B) is enough for the event listener to trigger.
Note: 
The examples in this section show how to use the or operator, but they similarly apply to the xor operator.
A coassigned variable can only be used if the variable is initialized in all circumstances that could cause the listener to fire. The following are both valid and invalid examples for coassignment.
Important: 
When using the all operator with operators that combine multiple event templates (such as or, xor, ->), it is likely that you want the all to apply to the whole pattern, rather than the individual event templates. To do this, you need to use brackets around the whole event expression, for example, on all (A() or B()). Using on all A() or B() or on all A() or all B() has different and potentially unwanted behavior, particularly if you use the same event type in more than one event template and the templates are not mutually exclusive.
Example 1 - valid
Only one of these A events will have been matched when triggered, but both are coassigned to variable a, so you can use a in the action.
on A(property = value1) as a or A(property = value2) as a {
executeAction(a);
}
Example 2 - valid
Only one of a or b will be coassigned to. However, they are global variables, so if a is coassigned to, you will have the default initialized value of b or the old value of b from a previous triggering.
monitor Monitor {
A a;
B b;
action foo() {
on all (A(): a or B(): b) {
executeAction(a, b);
}
}
}
Example 3 - valid
Only one of a or b will be coassigned to when triggered. However, they already have values assigned, so if a is coassigned to, you will have a new B in b.
monitor Monitor {
action foo() {
A a := new A;
B b := new B;
on all (A(): a or B(): b) {
executeAction(a, b);
}
}
}
Example 4 - invalid
Only one of a or b will be coassigned to when triggered. Neither of them already have values, so you cannot assume that either a or b can be used.
monitor Monitor {
action foo() {
A a;
B b;
on all (A(): a or B(): b) {
executeAction(a, b);
}
}
}
Example 5 - invalid
This is basically the same as example 4.
on all (A() as a or B() as b) {
executeAction(a, b);
}