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 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 expressions that specify 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 irrelevent.
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.
Operators used 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.
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.
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.
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.
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.
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).
Temporal operators
at
The event listener triggers at specific times or repeatedly at a specified interval.
wait
Limits the amount of time that an event listener can detect a match.
within
The event listener can find a match only within the specified timeframe.
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.
Copyright © 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.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.