Apama Documentation : Developing Apama Applications : Developing Apama Applications in EPL : Defining Event Listeners : Specifying the on statement
Specifying the on statement
You specify an on statement to define an event listener. The format of an on statement is as follows:
[listener identifier := ] on event_expr [ coassignment ] listener_action;
Syntax description
Syntax Element
Description
identifier
Optionally, you can specify a variable of type listener and assign the new event listener to that variable. This gives you a handle to the event listener — if you want to terminate it you can call the quit() method on the listener.
event_expr
The event expression identifies the event or pattern of events that you want to match. An event expression is made up of one or more event templates and zero or more event operators.
coassignment
Optionally, you can coassign the matching event to a variable of the same event type. Coassignments are part of event templates. Each event template can have a coassignment, so there can be multiple coassignments in a listener.
listener_action
The statement or block that you want the correlator to perform when the event listener triggers.
Examples
For example:
on StockTick(*,*) processTick();
In this example, the event expression contains one event template: StockTick(*,*). The asterisks indicate that the values of the StockTick event's two fields are not relevant when matching. When this event listener detects a StockTick event, the listener triggers and causes the correlator to execute the processTick() listener action.
Following is an example that coassigns the matching event to the newTick variable. The newTick variable must be a StockTick event type variable. Coassignment simply assigns the event to the variable.
on StockTick(*,*):newTick processTick();
The next example begins with the declaration of a listener variable. The statement assigns the event listener to the l variable.
listener l := on StockTick(*,*):newTick processTick();
Suppose that after finding a matching event, the listener action includes specification of an on statement. For example:
listener l := on StockTick(*,*):newTick {
on StockTick(newTick.symbol, > newTick.value):risingTick {
processRisingTick();
}
}
The correlator creates an entirely new event listener to handle the nested on statement. This new event listener is completely independent of the enclosing event listener. For example, the enclosing event listener does not wait for the nested event listener to find a matching event.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback