Apama 10.3.1 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Defining Event Listeners | Specifying multiple event listeners
 
Specifying multiple event listeners
When the correlator encounters an on statement, it creates an event listener to watch for events that match the event expression specified in the on statement. When the event listener finds a matching event, the event listener triggers and the correlator executes the listener action. Ordinarily the event listener then dies. That is, the event listener processes only a single matching event.
When you require multiple matching events specify the all operator before the template for the event for which you want multiple matches. This prevents termination of the event listener upon an event match.
Another way to match multiple events is to define two (or more) event listeners for the same event type. If you specify two on statements that require the same event, they both trigger when they find that event. The order in which they trigger is not defined. For example:
on all StockTick(*,*) as newTick1 { print newTick1.name; }
on all StockTick(*,*) as newTick2 { print newTick2.name; }
When the correlator receives a single StockTick event, the correlator populates both the newTick1 variable and the newTick2 variable with the event value. The correlator then prints the value of the name field in each variable. This means that an event of the format StockTick("ACME", 50.10) causes this output:
ACME
ACME
Adding further on statements to those above would increase the number of times the string ACME is printed. This is true regardless of where (that is, in which action) the on statements are defined. For example:
action action1() {
   on all StockChoice("ACME") as currentStock processTick();
}
action action2() {
   on all StockChoice("ACME") as currentStock processTick();
}
If both the action1() and action2() actions have been invoked, both will invoke the processTick() action when an "ACME" StockChoice event is received.
Now consider the following example:
on all StockTick("ACME", *) action1();
on all StockTick(*,50.0) action1();
The event StockTick("ACME", 50.0) will trigger both event listeners. It is not possible to determine which one will execute the action first but the actions will be executed atomically. That is, the correlator will start executing action1(), finish it, and only then will the correlator execute action1() again. The correlator processes only one listener action at a time.
See Spawning monitor instances for another way to have multiple event listeners.

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.