Developing Apama Applications > Developing Apama Applications in Java > Overview of Apama JMon Applications > About event listeners and match listeners > Defining multiple listeners
Defining multiple listeners
A monitor can define any number of event expressions, and create any number of listeners. The following code,
public void onLoad() {
   EventExpression eventExpr1 = new EventExpression("Tick(*, >10.0)");
   EventExpression eventExpr2 =
     new EventExpression("NewsItem(\"ACME\", *)");
 
   eventExpr1.addMatchListener(this);
   eventExpr2.addMatchListener(this);
}
is creating two event expressions, eventExpr1 and eventExpr2. Then each is assigned a match listener, thus activating two distinct listeners. The fact that both are being assigned the same match listener object, i.e. this same object this, is inconsequential. It just means that the same method, the match method of this object, will be called when the correlator detects either of the event expressions.
As already described, creating a listener is an asynchronous operation that returns immediately. In the above code, in practice both listeners are created concurrently. It is not possible for the eventExpr1 listener to trigger before the eventExpr2 listener is created. However, once the enclosing method’s code has completed execution, the listeners can trigger at any time, and independently of each other.
Copyright © 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.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.