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
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 relevent 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
Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.