Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Defining Event Listeners | Defining event expressions with one event template | Listening for events of different types
Listening for events of different types
A monitor is not limited to listening for events of only one type. A single monitor can listen for any number of event types. The following sample monitor uses the StockTick event type and the StockChoice event type, which specifies a stock name. When the event listener finds a StockChoice event, a second event listener then looks for only stocks that match the name in the StockChoice event.
// Definition of a type of event that the correlator will receive.
// These events represent stock ticks from a market data feed.
event StockTick {
   string name;
   float price;
// Definition of a type of event that describes the stock to process.
// These events come from a second live data feed.
event StockChoice {
   string name;
// The following simple monitor listens for two different event types.
monitor SimpleShareSearch {
   // A global variable to store the matching StockTick event:
   StockTick newTick;
   // A global variable to store the StockChoice event:
   StockChoice currentStock;
   // Wait for a StockChoice event and use its name field to
   // filter for StockTick events.
   action onload() {
     on StockChoice(*):currentStock {
       on all StockTick(currentStock.name, *):newTick processTick();
   action processTick() {
     log "StockTick event received" +
       " name = " + newTick.name +
       " Price = " + newTick.price.toString() at INFO;
The differences between the sample in Example of a simple monitor and this monitor are the following:
*Definition of an additional event type (StockChoice)
*Definition of a new global variable (currentStock)
*A more complex onload() action
While the first two changes are straightforward, the new onload() action introduces new behavior. The first line in the onload() action is similar to that in the earlier example. In the new example, the monitor creates an event listener for a StockChoice event. The content of the StockChoice event is not relevant when matching. When the event listener finds an event of this type, it stores the value of the StockChoicename field in the currentStock variable and triggers the creation of a second event listener.
In this example, the first event listener defines the action of creating the second event listener in-line. The first event listener looks for a StockChoice event. The second event listener looks for all StockTick events whose name field corresponds to the value of currentStock.name.

Copyright © 2013-2018 | 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.