Event listener lifecycle
When you inject a monitor into the correlator, the correlator instantiates the monitor in the main context and executes the monitor’s onload() action. The onload() action typically specifies at least one on statement. An on statement includes an event expression that identifies the event or sequence of events that you are interested in. This is what you want to listen for. An onload() statement is not required to specify an on statement. If there is no on statement, the correlator immediately unloads the monitor.
When the correlator executes an on statement, it sets up an event listener for the specified event or sequence of events. After the correlator sets up the event listener, the event listener watches for an event that matches its event expression. When the event listener detects a matching event, the event listener triggers and the correlator executes the action specified in the on statement.
For an event listener that is looking for a single instance of an event, this is straightforward. However, the event expression that defines what you are looking for can specify all instances of an event, all instances of a sequence of events, and it can have temporal and logical constraints. This makes the lifecycle of an event listener less straightforward.
For example, consider the following event listener:
on all A() success;
When the correlator sets up this event listener, it sets up an event template to look for an A event. When an A event arrives, the correlator does the following:
Executes the
success() event listener action.
Sets up a new event template to look for the next
A event.
Now consider this event listener:
on all A() -> all B() success;
Again, suppose that the correlator sets up this event listener and an A event arrives. This time the correlator does the following:
1. Sets up an event template to listen for the next B event.
2. Sets up an event template to listen for the next A event.
This event listener will be active until it is explicitly killed because there will always be an event listener that is looking for the next A event.
Additional information about event listener lifecycles is in
Developing Apama Applications in EPL,
How the correlator executes event listeners.