Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining Event Listeners | About event expressions and event templates
 
About event expressions and event templates
To create an event listener, you must specify an event expression. An event expression
*Identifies an event or event pattern that you want to match
*Contains zero or more event templates
*Contains zero or more event operators
An event template specifies an event or any type and encloses in parentheses the set of, or set of ranges of, event field values to match. An event template can specify wildcards for event fields or can specify that certain event fields must have particular values or ranges of values.
An event expression can specify a temporal operator and zero event templates.
Following are event expressions that are each made up of one event template:
Event Expression
Description
StockTick(*,*)
The event listener that uses this event expression is interested in all StockTick events regardless of the event's field values.
NewsItem("ACME",*)
The event listener that uses this event expression is interested in NewsItem events that have a value of ACME in their first field. Any value can be in the second field.
ChainedResponse(reqId="req1")
The event listener that uses this event expression is interested in ChainedResponse events whose reqId field has a value of req1. If a ChainedResponse event has any other fields, their values are irrelevant.
any()
The event listener that uses this event expression is interested in all events, regardless of their type.
You can specify more than one event template in an event expression by adding event operators. The following table describes the operators that you can use in an event expression.
Category
Operator
Operation
Followed by
->
The event listener detects a match when it finds an event that matches the event template specified before the followed-by operator and later finds an event that matches the event template that comes after the followed-by operator. See also Defining event listeners for patterns of events.
Repeat matching
all
The event listener detects a match for each event that matches the specified event template. The event listener does not terminate after the first match. See also Listening for all events of a particular type.
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.
Logical operators
and
Logical intersection. The event listener detects a match after it finds events that match the event templates on both sides of the and operator. The order in which the listener detects the matching events does not matter. See also Specifying the 'and' operator in event expressions.
not
Logical negation. The event listener detects a match only if an event that matches the event template that follows the not operator has not occurred. See also Specifying the 'not' operator in event expressions.
or
Logical union. The event listener detects a match as soon as it finds an event that matches one of the event templates on either side of the or operator. See also Specifying the 'or' or 'xor' operator in event expressions.
xor
Logical exclusive or. The event listener detects a match if it finds an event that matches exactly one of the event templates on either side of the xor operator. For example, consider this event: A(1,1). This event does not trigger the following listener because it matches the event templates on both sides of the xor operator: on A(1,*) xor A(*,1). See also Specifying the 'or' or 'xor' operator in event expressions.
Temporal operators
at
The event listener triggers at specific times or repeatedly at a specified interval. See also Triggering event listeners at specific times.
wait
Limits the amount of time that an event listener can detect a match. See also Waiting within an event listener.
within
The event listener can find a match only within the specified timeframe. See also Listening for event patterns within a set time.
Consider the following example:
event Test
{   
float f;
}
 
monitor RangeExample
{   
action onload()
   {
      on Test (f >= 9.0 ) and Test (f <= 10.0) processTest();
   }
 
   action processTest();
   {
      do something
   }
}
The event expression is:
Test (f >= 9.0 ) and Test (f <= 10.0)
This event expression specifies the and operator so the event listener must detect an event that matches both of the event expression's event templates or two events, where one matched the first template and another matched the second. It does not have to be a single event that matches both event templates. The order in which the templates are matched does not matter.
Consider this event expression:
A(a = "foo") xor A(b > 9)
An event listener that defines this event expression triggers for A("foo", 9) but not A("foo", 10). On A("foo", 10), the A templates would trigger simultaneously, so the xor would remain false.
The correlator can match on up to 32 fields per event. If you specify an event template for an event that has more than 32 fields, you must ensure that the correlator maintains indexes for the particular fields for which you specify values that you want to match.
In other words, when the event definition was loaded into the correlator, the fields that did not have the wildcard keyword formed the set of fields that you can match on. An event template can try to match on only those fields. If an event template specifies any of the wildcard fields, it must be with an asterisk.
If you try to load a monitor that defines an event template that specifies more than 32 fields without an asterisk or a wildcard field without an asterisk, the correlator rejects the monitor. You must correct the template in order to load the monitor.