Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining Event Listeners | Specifying completion event listeners | Example using unmatched and completed
 
Example using unmatched and completed
The following example shows the use of both the unmatched and completed keywords. After the example, there is a discussion of the processing order.
on all A("foo", < 10) as a {
   print "Match: " + a.toString();
   a.count := a.count+1; // count is second field of A
   route A;
}
 
on all completed A("foo", < 10) as a {
   print "Completed: " + a.toString();
}
 
on all unmatched A(*,*)as a {
   print "Unmatched: " + a.toString();
}
The incoming events are as follows:
A("foo", 8);
A("bar", 7);
The output is as follows:
Match: A("foo", 8)
Match: A("foo", 9)
Unmatched: A("foo", 10)
Completed: A("foo", 9)
Completed: A("foo", 8)
Unmatched: A("bar", 7)
A("foo", 8) is the first item on the queue. The correlator processes all matches for this event except for any matching on completed expressions. The correlator processes those after it has processed all routed events originating from A("foo", 8), which includes the processing of all routed events produced from all routed events produced from A("foo", 8), and so on.
Correlator processing goes like this:
1. Processing of A("foo", 8) routes A("foo", 9) to the front of the queue.
2. Processing of A("foo", 9) routes A("foo", 10) to the front of the queue.
3. Processing of A("foo", 10) finds a match with the unmatched event expression.
4. All routed events that resulted from A("foo", 9) have now been processed. The completed A("foo", 9) event template now matches so the correlator executes its listener action.
5. All routed events that resulted from A("foo", 8) have now been processed. The completed A("foo", 8) event template now matches so the correlator executes its listener action.
6. Processing of A("bar", 7) matches the unmatched A(*,*) event template and the correlator executes its listener action.
For another example of the use of unmatched and completed, see Writing echo monitors for debugging.